0

AlexNetでTensorFlowを使用して自分のデータをフィードしようとしています。私はトレーニング中に(227 x 227)rgb画像を使用しており、BATCH_SIZEは50です。以下はコードの一部です。私は常に行でエラーを取得していtrain_accuracy = accuracy.eval(...)TensofFlowを使用して実装されたAlexNetでデータを入力する際のディメンションエラー

x = tf.placeholder(tf.float32, shape=[None, 227, 227, 3]) 
x_image = tf.reshape(x, [1, 227, 227, 3]) 
y_ = tf.placeholder(tf.float32, shape=[None, 5]) 


train_image_batch, train_label_batch = tf.train.batch([train_image, train_label], batch_size=BATCH_SIZE)            
test_image_batch, test_label_batch = tf.train.batch([test_image, test_label], batch_size=BATCH_SIZE) 


print train_label_batch.get_shape() 
print y_.get_shape() 
print "input pipeline ready" 




cross_entropy = tf.reduce_mean(-tf.reduce_sum(train_y * tf.log(y_conv), reduction_indices=[1])) 
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) 
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(train_y,1)) 
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 




init = tf.initialize_all_variables() 

with tf.Session() as sess: 

    sess.run(init) 

    # initialize the queue threads to start to shovel data 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(sess=sess, coord=coord) 


    for i in range(2): 
     train_batch_image = sess.run(train_image_batch) 
     train_batch_label = sess.run(train_label_batch) 

    #if i%100 == 0: 
    train_accuracy = accuracy.eval(feed_dict={x: train_batch_image, y_: train_batch_label, keep_prob: 1.0}) 
    print("step %d, training accuracy %g"%(i, train_accuracy)) 
    train_step.run(feed_dict={x: train_batch_image, y_: train_batch_label, keep_prob: 0.5}) 

    test_batch_image = sess.run(train_image_batch) 
    test_batch_label = sess.run(train_label_batch) 

    print("test accuracy %g"%accuracy.eval(feed_dict={x: test_batch_image, y_: test_batch_label, keep_prob: 1.0})) 



    coord.request_stop() 
    coord.join(threads) 
    sess.close() 

現在のエラーは次のとおりです。

Traceback (most recent call last): 
    File "tf_alexnet.py", line 294, in <module> 
    train_accuracy = accuracy.eval(feed_dict={x: train_batch_image, y_: train_batch_label, keep_prob: 1.0}) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 556, in eval 
    return _eval_using_default_session(self, feed_dict, self.graph, session) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3649, in _eval_using_default_session 
    return session.run(tensors, feed_dict) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 382, in run 
    run_metadata_ptr) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 655, in _run 
    feed_dict_string, options, run_metadata) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 723, in _do_run 
    target_list, options, run_metadata) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 743, in _do_call 
    raise type(e)(node_def, op, message) 
tensorflow.python.framework.errors.InvalidArgumentError: Input to reshape is a tensor with 7729350 values, but the requested shape has 154587 
    [[Node: Reshape = Reshape[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_Placeholder_0, Reshape/shape)]] 
Caused by op u'Reshape', defined at: 
    File "tf_alexnet.py", line 79, in <module> 
    x_image = tf.reshape(x, [1, 227, 227, 3]) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1750, in reshape 
    name=name) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op 
    op_def=op_def) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2310, in create_op 
    original_op=self._default_original_op, op_def=op_def) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1232, in __init__ 
    self._traceback = _extract_stack() 

答えて

1

問題は、あなたが50にBATCH_SIZEを設定しているが、フォームにXを再構築しようとしているかのようにしますバッチサイズは1に等しい。その問題を解決するには、形状の1を-1に変更すると、入力の合計サイズが保持されます。

+0

return tf.reshape(tf.nn.bias_add(conv、biases)、conv.get_shape()。as_list()) ファイル "/usr/local/lib/python2.7/dist-packages/tensorflow/python /ops/gen_array_ops.py "、改行1750行 このエラーが発生しました。 –

+0

私は畳み込みレイヤーにいくつかの他の問題がありました。私はそれを整理しました。ありがとう。 –

関連する問題