tensorflow中的placeholder

2018-03-04  本文已影响0人  大梦一场三十一

本文主要是介绍tensorflow中的placeholder及用法。placeholder,中文意思是占位符,在tensorflow中类似于函数参数,运行时必须传入值。

import tensorflow as tf
import numpy as np

# 定义placeholder
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

# 定义乘法运算
output = tf.multiply(input1, input2)
# module 'tensorflow' has no attribute 'mul'

# 通过session执行乘法运行
with tf.Session() as sess:
    # 执行时要传入placeholder的值
    print (sess.run(output, feed_dict = {input1:[7.], input2: [2.]}))

上一篇 下一篇

猜你喜欢

热点阅读