placeholder和assign速度对比
在CPU上,使用variable和placeholder效果差不多
在GPU上,使用variable要比每次都传placeholder快得多3:2
使用GPU的瓶颈主要在于GPU和内存之间的复制操作
"""
place_holder和variable速度对比
"""
import timeimport numpy as np
import tensorflow as tfM = 4096
N = 4096
K = 4096
A = np.random.random((N, M))
B = np.random.random((M, K))
a = tf.placeholder(dtype=tf.float32, shape=(None, M))
b = tf.placeholder(dtype=tf.float32, shape=(None, N))
c = tf.Variable(initial_value=A, dtype=tf.float32)
pro = a @ b
use_assign = c @ b
with tf.Session() as sess:sess.run(tf.global_variables_initializer())beg_time = time.time()for i in range(5):sess.run(use_assign, feed_dict={b: B})print("use variable", time.time() - beg_time)beg_time = time.time()for i in range(5):sess.run(pro, feed_dict={a: A,b: B})print("use placeholder", time.time() - beg_time)
转载于:https://www.cnblogs.com/weiyinfu/p/11264639.html
placeholder和assign速度对比相关推荐
- 附录5:TensorFlow基础(一)
目录 TensorFlow简介 什么是tensorflow tensorflow的核心 Numpy与TensorFlow Tensorflow基本操作 初步认识tensorflow与tensorboa ...
- SpringBoot启动报错Could not resolve placeholder ‘XXX.XXX‘ in value
SpringBoot启动项目时报错: Exception encountered during context initialization - cancelling refresh attempt: ...
- TensorFlow 复制placeholder
用这种方式复制placeholder: input_placeholder = tf.placeholder(tf.int32, [batch_size, sequence_len], name=&q ...
- tf.placeholder函数说明
函数形式: tf.placeholder( dtype, shape=None, name=None ) 参数: dtype:数据类型.常用的是tf.float32,tf.fl ...
- 小程序中点击input控件键盘弹出时placeholder文字上移
最近做的一个小程序项目中,出现了点击input控件键盘弹出时placeholder文字上移,刚开始以为是软键盘弹出布局上移问题是传说中典型的fixed 软键盘顶起问题,因此采纳了网上搜到的" ...
- 【一语点醒梦中人】如何优雅地合并两个JSON对象 → Object.assign(a, b)和Object.assign({}, a, b)的区别
var a = {a: 1}; var b = {b: 2}; var c = Object.assign(a, b);/* a对象也会改变,b不变,返回被被修改对象 */ var d = Objec ...
- placeholder
打开一个那边发过来的页面,里面全是placeholder.没见过,一时气愤全部ko,用传统的方法都能搞定的东西,为啥要标新立异! 后来发现如果想在input password里显示个把汉字,还真是不容 ...
- lambda在python中的用法_在python中对lambda使用.assign()方法
我在Python中运行以下代码:#Declaring these now for later use in the plots TOP_CAP_TITLE = 'Top 10 market capit ...
- 支持placeholder和自适配高度的TextView控件
一.应用于项目的效果如下: 二.使用方法: 1.导入JXTextView.h头文件 2.初始化,并添加到view中: JXTextView *textView = [[JXTextView alloc ...
最新文章
- 南大庄建军计算机学院讲座,教师成果 - 南京大学 - 电子信息专业国家级实验教学示范中心...
- Mac OS 下安装 MacVim
- 主键、唯一键与唯一索引的区别
- CDI中的事务异常处理
- homelede软路由设置方法_斐讯无线路由器怎么设置 斐讯无线路由器设置方法【详解】...
- 0x800f0845 更新1803报错
- kylin: NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
- ncurses窗口机制:newwin(),wprintw(),delwin(),box(),wborder(),
- 水晶报表如何查看sql_amazon自动广告如何查看报表?怎么知道亚马逊的自然流量和广告流量分别是多少?...
- 动态规划法实现最优二叉搜索树
- VB.NET/C# Free Grid Control 免费开源表格控件 - ReoGrid 介绍(1)
- 世界各国与中国时差查询
- DiscuzQ_V3二次开发版本部署文档
- 深入理解LayoutInflater.inflate()
- 解决 Navigating to current location (/userslist) is not allowed问题。
- css3上箭头怎么写,纯css作箭头
- 小生云服务器,HobitLab#2--云服务器的有效利用之搭建tiny tiny RSS
- CVPR 2018视频行为识别挑战赛概览
- 金立生命倒计时:破产清算官网无法打开,创始人被曝赌博输十亿不知所踪
- 微信小程序如何引用iconfont图标