10、TensorFlow中feed与fetch讲解_笔记
- # -*- coding: utf-8 -*-
- __author__ = 'dongfangyao'
- __date__ = '2018/9/17 下午5:53'
- __product__ = 'PyCharm'
- __filename__ = 'tf05'
- import tensorflow as tf
- import os
- # 只显示 warning 和 Error
- os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
- # 构建一个矩阵的乘法 但是矩阵数据在运行的时候给定(相当于定义一个方法一样)
- m1 = tf.placeholder(dtype=tf.float32, shape=[2, 3], name='placeholder_m1')
- print(type(m1))
- m2 = tf.placeholder(dtype=tf.float32, shape=[3, 2], name='placeholder_m2')
- m3 = tf.matmul(m1, m2)
- with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess:
- print('result:\n{}'.format(sess.run(fetches=[m3],
- feed_dict={m1: [[1, 2, 3], [4, 5, 6]], m2: [[1, 2], [3, 4], [5, 6]]})))
- print('result-eval:\n{}'.format(m3.eval(feed_dict={m1: [[1, 2, 3], [4, 5, 6]], m2: [[1, 2], [3, 4], [5, 6]]})))
- pass
复制代码
|