[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的更多相关文章

  1. Tensorflow中的padding操作

    转载请注明出处:http://www.cnblogs.com/willnote/p/6746668.html 图示说明 用一个3x3的网格在一个28x28的图像上做切片并移动 移动到边缘上的时候,如果 ...

  2. CNN中的卷积核及TensorFlow中卷积的各种实现

    声明: 1. 我和每一个应该看这篇博文的人一样,都是初学者,都是小菜鸟,我发布博文只是希望加深学习印象并与大家讨论. 2. 我不确定的地方用了"应该"二字 首先,通俗说一下,CNN ...

  3. python/numpy/tensorflow中,对矩阵行列操作,下标是怎么回事儿?

    Python中的list/tuple,numpy中的ndarrray与tensorflow中的tensor. 用python中list/tuple理解,仅仅是从内存角度理解一个序列数据,而非数学中标量 ...

  4. [翻译] Tensorflow中name scope和variable scope的区别是什么

    翻译自:https://stackoverflow.com/questions/35919020/whats-the-difference-of-name-scope-and-a-variable-s ...

  5. SSD:TensorFlow中的单次多重检测器

    SSD:TensorFlow中的单次多重检测器 SSD Notebook 包含 SSD TensorFlow 的最小示例. 很快,就检测出了两个主要步骤:在图像上运行SSD网络,并使用通用算法(top ...

  6. 在 TensorFlow 中实现文本分类的卷积神经网络

    在TensorFlow中实现文本分类的卷积神经网络 Github提供了完整的代码: https://github.com/dennybritz/cnn-text-classification-tf 在 ...

  7. [开发技巧]·TensorFlow中numpy与tensor数据相互转化

    [开发技巧]·TensorFlow中numpy与tensor数据相互转化 个人主页–> https://xiaosongshine.github.io/ - 问题描述 在我们使用TensorFl ...

  8. TensorFlow中的变量和常量

    1.TensorFlow中的变量和常量介绍 TensorFlow中的变量: import tensorflow as tf state = tf.Variable(0,name='counter') ...

  9. TensorFlow中的通信机制——Rendezvous(二)gRPC传输

    背景 [作者:DeepLearningStack,阿里巴巴算法工程师,开源TensorFlow Contributor] 本篇是TensorFlow通信机制系列的第二篇文章,主要梳理使用gRPC网络传 ...

随机推荐

  1. Java并发编程的艺术笔记(一)——volatile和syncronized关键字

    一.线程间的通信 volatile和syncronized关键字 volatile 修饰变量,告知任何对该变量的访问必须从共享内存获取,对它的改变必须同步刷新至共享内存,由此保证可见性. syncro ...

  2. 读写锁StampedLock的思想

    该类是一个读写锁的改进,它的思想是读写锁中读不仅不阻塞读,同时也不应该阻塞写. 读不阻塞写的实现思路: 在读的时候如果发生了写,则应当重读而不是在读的时候直接阻塞写! 因为在读线程非常多而写线程比较少 ...

  3. 文件的权利和sudoers中规定的权限哪个更大?

    文件的权利和sudoers中规定的权限哪个更大? 当然是文件的权限更大!!! 这也是linux的 更安全的根本所在! 就是它的每一个文件都有严格的 rwxr--r-- 权限规定. 只有文件权限规定了的 ...

  4. EMQ插件通过HTTP连接认证服务器实现认证

    需求 在EMQ中添加认证插件,将到来的MQTT连接的ClientID.UserName.Password通过HTTP协议发送到认证服务器,用返回的数据决定是否允许该连接: 在连接时和断开时向服务器发送 ...

  5. C# App.config 自定义 配置节

    1)App.config <?xml version="1.0" encoding="utf-8" ?><configuration>  ...

  6. ActionList及Action使用

    ActionList及Action使用 https://blog.csdn.net/adamrao/article/details/7450889 2012年04月11日 19:09:27 阅读数:1 ...

  7. 【AOP】操作相关术语---【Spring】的【AOP】操作(基于aspectj的xml方式)

    [AOP]操作相关术语 Joinpoint(连接点):类里面哪些方法可以被增强,这些方法称为连接点. Pointcut(切入点):在类里面可以有很多的方法被增强,比如实际操作中,只是增强了类里面add ...

  8. Java多线程学习——例子:模拟电影院抢座位

    Cinema——List<Integer>数据结构存储电影院座位 public class Cinema{ private List<Integer> seats; //剩余座 ...

  9. ssh远程连接linux服务器并执行命令

    详细方法: SSHClient中的方法 参数和参数说明 connect(实现ssh连接和校验) hostname:目标主机地址 port:主机端口 username:校验的用户名 password:登 ...

  10. 浅谈html5在vr中的应用

    使用过HTML5制作动画过程的开发者都知道,HTML5页面给人一种逼真的感觉,同时HTML也是可以制作VR页面,但是需要你熟练HTML5与JavaScript开发过程,所以在有必要的情况下,我们可以用 ...