【发布时间】:2021-06-07 11:46:24
【问题描述】:
您好,我是 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'>
谁能解释一下我真的不明白问题出在哪里 谢谢你的回答
【问题讨论】:
-
嗨。你的型号是什么?如果是 Keras 模型,你的输入 roi 必须是 InputKeras 类型
-
嗨,“模型”的模型是network = models.Sequential() network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,))) network.add(layers.Dense(10, activation='softmax'))
-
你试过这个吗(不确定但可能是一个解决方案)? model.predict(np.array(roi))
-
我刚试过,我的答案是:IndexError: list index out of range
-
显示回溯 - 即完整的错误。到目前为止,我们只是猜测错误发生在哪里(显然你也在猜测)。更具体地了解进口。
model不是numpy创建的。这是keras中的东西(我猜!)。