我是坦索弗洛的新手。我打算用tf.reshape把形状(28,28,1)张量压平成一维张量,但没有得到预期的结果。这是我使用的代码的一部分。
def input_pipeline(self, batch_size, num_epochs=None):
images_tensor = tf.convert_to_tensor(self.image_names, dtype=tf.string)
labels_tensor = tf.convert_to_tensor(self.labels, dtype=tf.int64)
input_queue = tf.train.slice_input_producer([images_tensor, labels_tensor], num_epochs=num_epochs)
labels = input_queue[1]
images_content = tf.read_file(input_queue[0])
images = tf.image.convert_image_dtype(tf.image.decode_png(images_content, channels=N_CHANNELS), tf.float32)
new_size = tf.constant([IMAGE_SIZE_CHN, IMAGE_SIZE_CHN], dtype=tf.int32)
images = tf.image.resize_images(images, new_size)
reshape_vec = tf.constant([-1], dtype=tf.int32)
print(images.get_shape())
tf.reshape(images, reshape_vec)
print(images.get_shape())
image_batch, label_batch = tf.train.shuffle_batch([images, labels], batch_size=batch_size, capacity=50000,
min_after_dequeue=10000)
return image_batch, label_batch两个打印函数的结果都是(28,28,1)。有人能帮我吗?谢谢!
发布于 2018-04-05 23:43:51
reshape返回一个新的张量,这是重塑旧张量的结果。它不会改变原来的张量。若要修复,只需将整形行更改为
images = tf.reshape(images, reshape_vec)注意,仅仅使用它可能会更好/更干净
images = tf.reshape(images, (-1,))而不是用一个单独的常数张量来定义新的形状,尽管这更多的是个人偏好的事情。
https://stackoverflow.com/questions/49682839
复制相似问题