我该如何完成此步骤?

时间:2019-12-01 00:58:39

标签: python tensorflow machine-learning keras deep-learning


WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
Train on 10000 samples
Epoch 1/5
10000/10000 [==============================] - 1s 107us/sample - loss: 7.1288 - acc: 0.0090
Epoch 2/5
10000/10000 [==============================] - 1s 69us/sample - loss: 4.9724 - acc: 0.0120
Epoch 3/5
10000/10000 [==============================] - 1s 67us/sample - loss: 4.8243 - acc: 0.0132
Epoch 4/5
10000/10000 [==============================] - 1s 68us/sample - loss: 4.7343 - acc: 0.0113
Epoch 5/5
10000/10000 [==============================] - 1s 69us/sample - loss: 4.6702 - acc: 0.0139
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-4b4fc1f78d7e> in <module>()
     26 model.fit(array(input_randoms), output_randoms, epochs=5)
     27 
---> 28 model.evaluate([[50,32],[16,18]],  [82,34], verbose=2)
     29 

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    570                              ': expected ' + names[i] + ' to have shape ' +
    571                              str(shape) + ' but got array with shape ' +
--> 572                              str(data_shape))
    573   return data
    574 

ValueError: Error when checking input: expected flatten_input to have shape (2,) but got array with shape (1,)

输出为:

{{1}}

我正在尝试完成此操作。

据我了解,model.evaluate([[50,32],[16,18]],[82,34],verbose = 2)我应该放置两个样本输入并对它们进行正确回答。我正在寻找的输出如上文“错误输出前”中所述。

1 个答案:

答案 0 :(得分:1)

我相信您错过了一对方括号,一旦添加了方括号,输入应该正确。我也是初学者,并不了解...

model.evaluate([[50,32],[16,18]],  [82,34], verbose=2)

model.evaluate([[[50,32],[16,18]]],  [82,34], verbose=2)

screenshot of my testing