alexnet图像分类预测脚本报错

ALEXNET做图像分类,训练完train脚本后,下载一张图像放置在下图位置,

img


运行predict.py运行时报错出现:
assert os.path.exists(img_path), "file: '{}' dose not exist.".format(img_path)
AssertionError: file: '../tulip.jpg' dose not exist.

img

img

这个错误表示指定的文件路径('../tulip.jpg')不存在。可能是文件名拼写错误或文件路径不正确。

这个错误提示表明程序无法找到指定路径下的文件。可能的原因包括:

  1. 文件路径错误:检查文件路径是否正确,确保文件存在于指定路径下。

  2. 文件名错误:检查文件名是否正确,确保文件名拼写正确,大小写是否一致。

  3. 文件格式错误:检查文件格式是否正确,确保文件后缀名正确。

您可以尝试使用绝对路径或者相对路径来打开文件,确保文件路径正确,并且文件存在于指定路径下。例如:



img_path = os.path.abspath("./tulip.jpg")
assert os.path.exists(img_path), "file: '{}' dose not exist.".format(img_path)
img = Image.open(img_path)

或者:

img_path = "../tulip.jpg"
assert os.path.exists(img_path), "file: '{}' dose not exist.".format(img_path)
img = Image.open(img_path)

如果问题仍然存在,请检查文件是否存在,或者尝试使用其他图片进行测试。

楼主,我也遇到了同样的问题,请问有解决办法了吗?