2017-05-14 13 views
-1

を持っていますが、私はInvalidArgumentError(トレースバックについては上記参照):私はtfrecordsを書いて、それを読んで、私はすでに「train.tfrecords」ファイルを取得しているしようと再形成への入力は154587個の値を持つテンソルであるが、要求された形状は150528

image_size=224 
def read_and_decode(filename,batch_size): 
    filename_queue=tf.train.string_input_producer([filename]) 
    reader=tf.TFRecordReader() 
    _,serialized_example=reader.read(filename_queue)#返回文件名和文件 
    features=tf.parse_single_example(serialized_example,features={ 
    "label": tf.FixedLenFeature([],tf.int64), 
    "img_raw":tf.FixedLenFeature([],tf.string), 
    }) 
    img=tf.decode_raw(features['img_raw'],tf.uint8) 
    img=tf.cast(img,tf.float32) 
    img=tf.reshape(img,[image_size,image_size,3]) 
    img = tf.random_crop(img, [image_size, image_size, 3]) 
    img = tf.image.random_flip_left_right(img) 
    img=tf.image.per_image_standardization(img) 
    label=tf.cast(features['label'],tf.int32) 
    img_batch, label_batch = tf.train.shuffle_batch([img, label], 
               batch_size=batch_size, num_threads=10, capacity=16 * batch_size, 
               min_after_dequeue=8*batch_size) 
    label_batch= tf.reshape(label_batch, [batch_size, 1]) 
    indices = tf.reshape(tf.range(0, batch_size, 1), [batch_size, 1]) 
    label_batch = tf.sparse_to_dense(
    tf.concat(values=[indices, label_batch], axis=1), 
    [batch_size, 3], 1.0, 0.0) 
    assert len(img_batch.get_shape()) == 4 
    assert img_batch.get_shape()[0] == batch_size 
    assert img_batch.get_shape()[-1] == 3 
    assert len(label_batch.get_shape()) == 2 
    assert label_batch.get_shape()[0] == batch_size 
    assert label_batch.get_shape()[1] == 3 

    # Display the training images in the visualizer. 
    tf.summary.image('images', img_batch) 
    return img_batch, label_batch 

それを読むためにこの関数を使用する際にエラーがある:

Caused by op 'Reshape', defined at: 
File "C:/Users/Administrator/Desktop/tensorflow/ResNet/main.py", line 176, in <module>tf.app.run() 
File"C:\ProgramFiles\Python35\lib\sitepackages\tensorflow\python\platform\app.py", line 48, in run 
_sys.exit(main(_sys.argv[:1] + flags_passthrough)) 
File "C:/Users/Administrator/Desktop/tensorflow/ResNet/main.py", line 169, in main 
train(hps) 
File "C:/Users/Administrator/Desktop/tensorflow/ResNet/main.py", line 31, in train 
images, labels = read_and_decode('train.tfrecords', hps.batch_size) 
File "C:\Users\Administrator\Desktop\tensorflow\ResNet\input.py", line 15, in read_and_decode 
img=tf.reshape(img,[image_size,image_size,3]) 
File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2510, in reshape 
name=name) 
    File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op 
op_def=op_def) 
File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op 
original_op=self._default_original_op, op_def=op_def) 
File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__ 
self._traceback = _extract_stack() 
InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 154587 values, but the requested shape has 150528 
[[Node: Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](Cast, Reshape/shape)]] 

私はしばらくの間、インターネット上で検索し、私はこの問題は、これらのコードで起こると思うが、私は知りませんどのようにそれを修正するには、私を助けてください、ありがとう

img=tf.decode_raw(features['img_raw'],tf.uint8) 
img=tf.cast(img,tf.float32) 
img=tf.reshape(img,[image_size,image_size,3]) 
+1

あなたはレコードが224×224×3の画像ではなく227×227×3の画像であることを確認していますか?画像サイズを227に変更してみてください。 –

+0

ああ...私はそれを気付かず、TFRコードをもう一度準備しています。 –

答えて

0

コメントで@Mathias RAVで説明したようにあなたははっきりログでこれを見ることができます。 TFrecordsの

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 154587 values, but the requested shape has 150528 

サイズは154587です:最初のモデルの必要な入力サイズを確認し、それに応じて画像を調整224x224x3

:227x227x3

しかし、あなたが提供テンソル形状のサイズは150528です。 いずれか

  1. tf.image.resize_images()または
  2. サイズで再度TFRecordsの準備を使用して224x224x3画像をリサイズ224x224x3または
  3. モデル入力サイズは227x227x3、次にちょうど227にimage_sizeではを変更する場合。

私はこのことができます願っています。

+0

@Geこれはあなたの問題を解決しましたか? – hars

+0

はい、私はTFRecordsを書き換え、それは動作します、ありがとう! –

+0

それを知っておいてよかった! – hars

関連する問題

 関連する問題