当前位置:网站首页>Tensorflow中placeholder函数的用法
Tensorflow中placeholder函数的用法
2022-08-09 21:35:00 【phac123】
简介
在代码层面上,每一个tensor值在graph上都是一个op,当我们将train数据分成一个个minibatch然后传入网络上进行训练时,每一个minibatch都将是一个op,这样的话,一幅图上的op未免太多,也会产生巨大的开销;于是就有了tf.placeholder(),即,我们每次可以将一个minitatch传入到 x = tf.placeholder(tf.float32, [None, 32])上,下一次传入的x都替换掉上一次传入的x,这样就对于所有传入的minibatch x就只会产生一个op,不会产生其他多余的op,进而减少了graph的开销.
函数的形式:
tf.placeholder(
dtype,
shape = None,
name = None
)
函数参数:
- dtype: 数据类型; 常用的是tf.float32, tf.float64等数值类型
- shape: 数据形状; 默认是None, 就是一维值, 也可以是多维(例如[2,3], [None, 3]表示列是3,行不定)
- name: 名称
返回
- Tensor类型
实现
import tensorflow as tf
import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
import numpy as np
from enum import Enum
from data.create_data import Distribution
from functools import wraps
x = tf.placeholder(tf.float32)
y = tf.constant(5.6)
output = tf.add(x, y)
with tf.Session() as sess:
print(sess.run(output, feed_dict={
x:3, y:5}))
边栏推荐
- 题解:Edu Codeforces 109(div2)
- 字节二面问的MySQL,差点没答好
- 字节一面:TCP 和 UDP 可以使用同一个端口吗?
- SQL语句及索引的优化
- 【高效工具】远程控制软件 ToDesk(收藏夹)
- 单元测试
- Simulation of Water Temperature Control System Based on Fuzzy PID Controller
- Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
- 编程时请选择正确的输入法,严格区分中英文
- Acrel5000web能耗系统在某学院的应用-Susie 周
猜你喜欢
访问控制知识
蓝牙模块有哪些种类?BLE低功耗蓝牙模块有什么特点?
定投的基金
安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
普源精电上半年扭亏为盈,高端产品持续发力!你看好仪器界“华为”吗?
Excel如何打出正负号?Excel打出正负号的方法
Ali Ermi: Without accept, can a TCP connection be established?
MySQL, which is asked on both sides of the byte, almost didn't answer well
小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
随机推荐
2021(ICPC)亚洲区域赛昆明站(CGHIJLM)
【Efficient Tools】Remote Control Software ToDesk (Favorites)
访问控制知识
DSPE-PEG-Azide, DSPE-PEG-N3, phospholipid-polyethylene glycol-azide can react directly with DBCO
必看设计干货|易知微设计师是怎么做标准可视化设计服务的?
Access control knowledge
题解:Edu Codeforces 109(div2)
Next second data: the transformation of the modern data stack brought about by the integration of lake and warehouse has begun
Word第一页空白页怎么删除?删除Word第一页空白页方法教程
cadence中复制一部分PCB到另一个PCB中去
小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
基于光通信的6G水下信道建模综述
Definition and Basic Operations of Linear Tables
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
hdu 3341 Lost's revenge(dp+Ac自动机)
buuctf (Adventure 2)
gmail+mtalk配合打免费网络电话。
Word怎么制作一张标准的答题卡?
Referenced file contains errors 完美解决方法
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节