tensorflow 中 inter_op 和 intra_op
[root@localhost custom-resnet-v2]# cat runme.sh
#python demo_slim.py -h
#python demo_slim.py --cpu_num 8 --inter_op_threads 1 --intra_op_threads 8 --dump_timeline True
# export KMP_AFFINITY=verbose,granularity=fine,proclist=[0,1,2,3],explicit
# numactl -C 0-3 python demo_slim.py --cpu_num 4 --inter_op_threads 1 --intra_op_threads 4 >& run1.log &
export OMP_NUM_THREADS=8
python demo_slim.py --cpu_num 8 --inter_op_threads 1 --intra_op_threads 8
[root@localhost custom-resnet-v2]# cat demo_slim.py
# coding: utf8
import os
import sys
import numpy as np
import tensorflow as tf
from tensorflow.python.client import timeline
import argparse
import time
def make_fake_input(batch_size, input_height, input_width, input_channel):
im = np.zeros((input_height,input_width,input_channel), np.uint8)
im[:,:,:] = 1
images = np.zeros((batch_size, input_height, input_width, input_channel), dtype=np.float32)
for i in xrange(batch_size):
images[i, 0:im.shape[0], 0:im.shape[1], :] = im
#channel_swap = (0, 3, 1, 2) # caffe
#images = np.transpose(images, channel_swap)
#cv2.imwrite("test.jpg", im)
return images
def get_parser():
"""
create a parser to parse argument "--cpu_num --inter_op_threads --intra_op_threads"
"""
parser = argparse.ArgumentParser(description="Specify tensorflow parallelism")
parser.add_argument("--cpu_num", dest="cpu_num", default=1, help="specify how many cpus to use.(default: 1)")
parser.add_argument("--inter_op_threads", dest="inter_op_threads", default=1, help="specify max inter op parallelism.(default: 1)")
parser.add_argument("--intra_op_threads", dest="intra_op_threads", default=1, help="specify max intra op parallelism.(default: 1)")
parser.add_argument("--dump_timeline", dest="dump_timeline", default=False, help="specify to dump timeline.(default: False)")
return parser
def main():
parser = get_parser()
args = parser.parse_args()
#parser.print_help()
cpu_num = int(args.cpu_num)
inter_op_threads = int(args.inter_op_threads)
intra_op_threads = int(args.intra_op_threads)
dump_timeline = bool(args.dump_timeline)
print("cpu_num: ", cpu_num)
print("inter_op_threads: ", inter_op_threads)
print("intra_op_threads: ", intra_op_threads)
print("dump_timeline: ", dump_timeline)
config = tf.ConfigProto(device_count={"CPU": cpu_num}, # limit to num_cpu_core CPU usage
inter_op_parallelism_threads = inter_op_threads,
intra_op_parallelism_threads = intra_op_threads,
log_device_placement=False)
with tf.Session(config = config) as sess:
imgs = make_fake_input(1, 224, 224, 3)
#init_start = time.time()
saver = tf.train.import_meta_graph("slim_model/slim_model.ckpt.meta")
saver.restore(sess, tf.train.latest_checkpoint("slim_model/"))
## Operations
#for op in tf.get_default_graph().get_operations():
# print(op.name)
# print(op.values())
graph = tf.get_default_graph()
input_data = graph.get_tensor_by_name("Placeholder:0")
fc6 = graph.get_tensor_by_name("resnet_v2/avg_fc_fc6_Conv2D/BiasAdd:0")
#init_end = time.time()
#print("initialization time: ", init_end-init_start, "s")
time_start = time.time()
for step in range(200):
if dump_timeline:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
result = sess.run(fc6, feed_dict={input_data:imgs}, options=run_options, run_metadata=run_metadata)
tm = timeline.Timeline(run_metadata.step_stats)
ctf = tm.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(ctf)
else:
result = sess.run(fc6, feed_dict={input_data:imgs})
print(result[0][0][0])
time_end = time.time()
avg_time = (time_end-time_start) * 1000 / 200;
print("AVG Time: ", avg_time, " ms")
return 0
if __name__ == "__main__":
sys.exit(main())
tensorflow 中 inter_op 和 intra_op的更多相关文章
- Tensorflow中的padding操作
转载请注明出处:http://www.cnblogs.com/willnote/p/6746668.html 图示说明 用一个3x3的网格在一个28x28的图像上做切片并移动 移动到边缘上的时候,如果 ...
- CNN中的卷积核及TensorFlow中卷积的各种实现
声明: 1. 我和每一个应该看这篇博文的人一样,都是初学者,都是小菜鸟,我发布博文只是希望加深学习印象并与大家讨论. 2. 我不确定的地方用了"应该"二字 首先,通俗说一下,CNN ...
- python/numpy/tensorflow中,对矩阵行列操作,下标是怎么回事儿?
Python中的list/tuple,numpy中的ndarrray与tensorflow中的tensor. 用python中list/tuple理解,仅仅是从内存角度理解一个序列数据,而非数学中标量 ...
- [翻译] Tensorflow中name scope和variable scope的区别是什么
翻译自:https://stackoverflow.com/questions/35919020/whats-the-difference-of-name-scope-and-a-variable-s ...
- SSD:TensorFlow中的单次多重检测器
SSD:TensorFlow中的单次多重检测器 SSD Notebook 包含 SSD TensorFlow 的最小示例. 很快,就检测出了两个主要步骤:在图像上运行SSD网络,并使用通用算法(top ...
- 在 TensorFlow 中实现文本分类的卷积神经网络
在TensorFlow中实现文本分类的卷积神经网络 Github提供了完整的代码: https://github.com/dennybritz/cnn-text-classification-tf 在 ...
- [开发技巧]·TensorFlow中numpy与tensor数据相互转化
[开发技巧]·TensorFlow中numpy与tensor数据相互转化 个人主页–> https://xiaosongshine.github.io/ - 问题描述 在我们使用TensorFl ...
- TensorFlow中的变量和常量
1.TensorFlow中的变量和常量介绍 TensorFlow中的变量: import tensorflow as tf state = tf.Variable(0,name='counter') ...
- TensorFlow中的通信机制——Rendezvous(二)gRPC传输
背景 [作者:DeepLearningStack,阿里巴巴算法工程师,开源TensorFlow Contributor] 本篇是TensorFlow通信机制系列的第二篇文章,主要梳理使用gRPC网络传 ...
随机推荐
- [LeetCode]-algorithms-Reverse Integer
Reverse digits of an integer. If the integer's last digit is 0, what should the output be? ie, cases ...
- Spring4配置文件模板
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- JPagination分页插件的使用(ASP.NET中使用)
前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.asp ...
- curl下载文件时自动创建目录
有时候需要自动创建多级目录 按照如下格式即可 curl -o d:/lei/demo/test.jpg --create-dirs http://img.7160.com/uploads/allimg ...
- tensorflow源码分析——CTC
CTC是2006年的论文Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurren ...
- AAAI 2019 分析
AAAI 2019 分析 Google Scholar 订阅 CoKE : Word Sense Induction Using Contextualized Knowledge Embeddings ...
- 2018 icpc 沈阳
https://codeforces.com/gym/101955 J 签到 #include<iostream> #include<cstring> #include< ...
- 20191128 Spring Boot官方文档学习(9.11-9.17)
9.11.消息传递 Spring Boot提供了许多包含消息传递的启动器.本部分回答了将消息与Spring Boot一起使用所引起的问题. 9.11.1.禁用事务JMS会话 如果您的JMS代理不支持事 ...
- C语言第十一周作业
这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/ ...
- [转帖]CBO和RBO
http://www.itpub.net/thread-263395-1-1.html 参数不能随便改啊.. optimizer_features_enable('8.1.7') ORACLE 提供了 ...