Tensorflow 一个用于不同训练数据的读取和解码功能
我是TensorFlow的新手,下面是我要做的:保存不同场景中的训练数据,然后读回。对于不同的场景,功能和输出的大小可能不同 问题是,当我试图读回数据时,出现了如下异常:Tensorflow 一个用于不同训练数据的读取和解码功能,tensorflow,Tensorflow,我是TensorFlow的新手,下面是我要做的:保存不同场景中的训练数据,然后读回。对于不同的场景,功能和输出的大小可能不同 问题是,当我试图读回数据时,出现了如下异常: InvalidArgumentError (see above for traceback): Name: <unknown>, Key: observation, Index: 0. Number of float values != expected. Values size: 17 but output sh
InvalidArgumentError (see above for traceback): Name: <unknown>, Key: observation, Index: 0. Number of float values != expected. Values size: 17 but output shape: []
读回数据的功能如下:
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, example = reader.read(filename_queue)
features = tf.parse_single_example(
example,
features = {
'obs' : tf.FixedLenFeature([], tf.float32),
'action' : tf.FixedLenFeature([], tf.float32),
'obs_size': tf.FixedLenFeature([], tf.int64),
'action_size' : tf.FixedLenFeature([], tf.int64)
}
)
obs_size = tf.cast(features['observation_size'], tf.int32)
action_size = tf.cast(features['action_size'], tf.int32)
obs_shape = tf.pack([1, obs_size])
action_shape = tf.pack([1, action_size])
obs = tf.reshape(obs, obs_shape)
action = tf.reshape(action, action_shape)
您似乎在编写更长的列表(本例中为长度17),但在读取时指定了
tf.FixedLenFeature([],dtype)
,这意味着它需要符合标量张量的内容(即,具有单个值;[]
,因为形状意味着标量)。既然您已经包含了大小,也许您可以使用VarLenFeature
来代替?@AllenLavoie实际上我不太明白tf.FixedLenFeature的第一个参数是如何工作的。那么tf.FixedLenFeature([17],dtype)会起作用吗?在这种情况下,这意味着我期望一个有17个元素的一维张量?另外,如果你能提供一些链接,说明如何使用VarLenFeature,那就太好了。谢谢,如果所有序列的长度都是17,那么[17]作为FixedLenFeature
的shape参数将起作用。有几个很好的例子说明VarLenFeatures
如何映射到SparseTensors
。
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, example = reader.read(filename_queue)
features = tf.parse_single_example(
example,
features = {
'obs' : tf.FixedLenFeature([], tf.float32),
'action' : tf.FixedLenFeature([], tf.float32),
'obs_size': tf.FixedLenFeature([], tf.int64),
'action_size' : tf.FixedLenFeature([], tf.int64)
}
)
obs_size = tf.cast(features['observation_size'], tf.int32)
action_size = tf.cast(features['action_size'], tf.int32)
obs_shape = tf.pack([1, obs_size])
action_shape = tf.pack([1, action_size])
obs = tf.reshape(obs, obs_shape)
action = tf.reshape(action, action_shape)