为什么model.fit不起作用,而model.predict不起作用?

时间:2019-06-18 18:45:42

标签: python tensorflow machine-learning

我正在尝试为TensorFLow做HelloWorld等效项。但是,在训练模型后,我面临一个预测问题

到目前为止,我已经克服了一个问题,但是我不完全相信为什么这是一个解决方案。 当我使用fit方法时,我将张量的输入转换为numpy。这使我能够训练模型

我无法解决的另一个问题。是在训练模型后无法使用预测方法,因为它给了我这个错误:

2019-06-18 11:34:21.318083: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
WARNING:tensorflow:From /Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:642: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
(60000, 28, 28)
(28, 28)
(60000, 28, 28)
60000/60000 [==============================] - 3s 52us/sample - loss: 0.2553 - acc: 0.9272
Tensor("flatten_input:0", shape=(?, 28, 28), dtype=float32)
Traceback (most recent call last):
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/HelloWorldTensorFlow.py", line 62, in <module>
    predict = model.predict(tf.reshape(test,[1,28,28]))
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/keras/engine/training.py", line 1113, in predict
    self, x, batch_size=batch_size, verbose=verbose, steps=steps)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/keras/engine/training_arrays.py", line 329, in model_iteration
    batch_outs = f(ins_batch)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/keras/backend.py", line 3166, in __call__
    outputs = self._graph_fn(*converted_inputs)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/eager/function.py", line 368, in __call__
    return self._call_flat(args)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/eager/function.py", line 433, in _call_flat
    outputs = self._inference_function.call(ctx, args)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/eager/function.py", line 269, in call
    executor_type=function_call_options.executor_type)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/ops/functional_ops.py", line 1083, in partitioned_call
    executor_type=executor_type)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/tensorflow/python/ops/gen_functional_ops.py", line 497, in stateful_partitioned_call
    _six.raise_from(_core._status_to_exception(e.code, message), None)
  File "/Users/emadabdelrahman/PycharmProjects/FirstTensorFlow/venv/lib/python2.7/site-packages/six.py", line 737, in raise_from
    raise value
tensorflow.python.framework.errors_impl.InvalidArgumentError: Matrix size-incompatible: In[0]: [28,28], In[1]: [784,128]
     [[{{node MatMul}}]] [Op:StatefulPartitionedCall]

0 个答案:

没有答案