numpy model.predict() 不起作用



你好,我是一个新手与Numpy, Keras和stackoverflow,我有一个问题,我在一个循环

roi = roi.reshape(28,28)
roi = (np.linalg.norm(roi))
probas = model.predict(roi)[0]
#number = np.argmax(probas[i])
#i+=1

我确信我的重塑是有效的结果是

ValueError                                Traceback (most recent call last)
<ipython-input-385-3ee67baef91d> in <module>()
----> 1 detect_digits("/content/drive/MyDrive/Colab Notebooks/photo1.jpg", network)
3 frames
<ipython-input-384-79a58876db55> in detect_digits(image_name, model)
49         # 2. Use 'model' to make a prediction
50 
---> 51         probas = model.predict(roi)[0]
52 
53         # 3. Based on the prediction, determine the class (a number between 0 and 9)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1606           use_multiprocessing=use_multiprocessing,
1607           model=self,
-> 1608           steps_per_execution=self._steps_per_execution)
1609 
1610       # Container that configures and calls `tf.keras.Callback`s.
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model, steps_per_execution)
1097       self._steps_per_execution_value = steps_per_execution.numpy().item()
1098 
-> 1099     adapter_cls = select_data_adapter(x, y)
1100     self._adapter = adapter_cls(
1101         x,
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in select_data_adapter(x, y)
962         "Failed to find data adapter that can handle "
963         "input: {}, {}".format(
--> 964             _type_name(x), _type_name(y)))
965   elif len(adapter_cls) > 1:
966     raise RuntimeError(
ValueError: Failed to find data adapter that can handle input: <class 'numpy.float32'>, <class 'NoneType'>
谁能给我解释一下,我真的不明白是什么问题,在哪里谢谢你的回答

我解决了我的问题,解决方案是:

roi = roi.reshape((1,28*28))
min = np.min(roi)
max = np.max(roi)
roi = (roi - min) * (1.0/(max - min))
probas = model.predict(roi)[0]
number = np.argmax(probas)

我正在重塑我的矩阵成一个矢量,这就是为什么我的代码不工作,非常感谢你的帮助!

最新更新