这个问题在某种程度上是一个扩展我如何使用从TFRecords读取的值作为tf.reshape的参数?
我使用以下代码将图像转换为特定形状:
height = tf.cast(features['height'],tf.int32)
width = tf.cast(features['width'],tf.int32)
image = tf.reshape(image,tf.pack([height, width, 3]))
Run Code Online (Sandbox Code Playgroud)
在cifar10_input代码中,图像随后被扭曲,其中IMAGE_SIZE = 32:
height = IMAGE_SIZE
width = IMAGE_SIZE
distorted_image = tf.random_crop(image, [height, width, 3])
Run Code Online (Sandbox Code Playgroud)
但是,就我的目的而言,我现在不需要随机播种.因此,我用以下内容替换了该行:
distorted_image = image
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它会抛出以下错误:
Traceback (most recent call last):
File "cnn_train.py", line 128, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 30, in run
sys.exit(main(sys.argv))
File "cnn_train.py", line 124, in main
train()
File "cnn_train.py", line 56, in train
images, labels = cnn.distorted_inputs()
File "/home/samuelchin/tensorflow/my_code/CNN/cnn.py", line 123, in distorted_inputs
batch_size=BATCH_SIZE)
File "/home/samuelchin/tensorflow/my_code/CNN/cnn_input.py", line 128, in distorted_inputs
min_queue_examples, batch_size)
File "/home/samuelchin/tensorflow/my_code/CNN/cnn_input.py", line 70, in _generate_image_and_label_batch
min_after_dequeue=min_queue_examples)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py", line 494, in shuffle_batch
dtypes=types, shapes=shapes)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 404, in __init__
shapes = _as_shape_list(shapes, dtypes)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 70, in _as_shape_list
raise ValueError("All shapes must be fully defined: %s" % shapes)
ValueError: All shapes must be fully defined: [TensorShape([Dimension(None), Dimension(None), Dimension(None)]), TensorShape([])]
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
因为您动态生成图像,包括从tf记录文件中动态拉出高度和宽度,TensorFlow不知道生成图像的形状.管道中的许多后来的操作需要能够在Python执行时确定形状.
该tf.random_crop具有图像大小设置为已知的固定大小,和离开它的形状暴露以用于后续处理的附带效果.
你可以将图像切割成你想要的大小,而不是做一个random_crop,但是你需要执行一些操作来将图像变成固定大小的东西.如果你想要它是32x32 并且你知道你的输入高度和宽度是32x32,那么你可以在它上面做set_shape(但你最好是对的).否则,您可以裁剪和/或调整大小到您想要的大小.
| 归档时间: |
|
| 查看次数: |
5738 次 |
| 最近记录: |