引言
由于需要对最近看到的一篇论文中的提到的SiameseLSTM模型进行代码实现,于是便选择了Tensorflow框架。这是除了看视频学习之外,我第一次自己对Tensorflow框架进行实践,确实也遇到了一些比较让人难受的问题,特此记录。
问题
操作系统:Windows 10 64位
问题描述:使用tf.placeholder()读入数据时,与原始数据不一致。
实验代码:
import tensorflow as tf
step = 4
x = tf.placeholder(dtype=tf.float32, shape=[step])
y = tf.placeholder(dtype=tf.float64, shape=[step])
inx = [0.5, 1.5, 2.6, 3.7]
with tf.Session() as sess:
testx, testy = sess.run([x, y], feed_dict={x: inx, y: inx})
print("inx(tf.float32):", testx)
print("iny(tf.float64):", testy)
输出:
inx(tf.float32): [ 0.5 1.5 2.5999999 3.70000005]
iny(tf.float64): [ 0.5 1.5 2.6 3.7]
猜想:应该是由于我的机器是64位操作系统,所以在dtype= tf.float32时,会出现这个问题,虽然不知道这样的精度对实验的效果影响如何,但是多多少少存在影响,还好发现了是数据类型问题。
欢迎一起学习,探讨~