【发布时间】:2021-04-16 04:45:56
【问题描述】:
我使用 CNN 制作了一个模型来预测给定的 X 射线是否属于 Covid 患者。
我面临的问题
- 有些图像可以正常工作,而有些则引发错误,我无法确定问题所在
这是错误
ValueError: in user code:
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1478 predict_function *
return step_function(self, iterator)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1468 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
return fn(*args, **kwargs)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1461 run_step **
outputs = model.predict_step(data)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1434 predict_step
return self(x, training=False)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__
input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
/home/khushwant/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/input_spec.py:255 assert_input_compatibility
raise ValueError(
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 64, 64, 1)
如何重新创建问题?
- 克隆回购Repo link
- 进入文件夹并安装requirements.txt
- 运行 cdclass.py
- 尝试上传我放在试用文件夹中的图片
您会看到 corona 文件夹中的图像可以正常工作,但是一旦我从普通文件夹上传内容,它就会引发错误,如上所述。
PS:-我尝试了模型中的预测(在我创建它时在 google colab 中)相同的图像工作得很好,但在部署中,它会抛出错误)你会发现一个 . Repo 中的 ipynb 文件,如果您愿意,可以随意查看。
【问题讨论】:
-
你能添加一个指向 repo 的链接吗?
-
哦,对不起,我忘了这样做
-
@RaJa 抱歉,我刚刚添加了链接
标签: python tensorflow keras python-imaging-library