如何使用Google Colab在Keras上加载单个图像



我建立了一个对猫和狗进行分类的深度学习模型。我已经成功地安装了谷歌驱动器,并根据需要对图像进行了训练。然而,我正试图通过上传一张图像并让Keras进行预测来进行单个预测。

在像Spyder这样的常规IDE中,它是这样的:

test_image = image.load_img('image1.jpg',target_size=(64,64))

但它抛出了一个错误:

Transport endpoint is not connected: 'image1.jpg'

我重新安装驱动器,然后它告诉我:

No such file or directory: 'image1.jpg'

在那之后,我尝试了如何在image.load((方法上编写目录,但目前没有任何想法。

您可以装载驱动器,通过身份验证进行连接,然后导入所需的文件,并使用模型进行预测。请在此处查看GitHub要点。您可以按照以下步骤操作,如果需要任何帮助,请告诉我。谢谢

from google.colab import drive
# This will prompt for authorization.
drive.mount('/content/drive')
# Predicting Roses
img=mpimg.imread('/content/drive/My Drive/5602220566_5cdde8fa6c_n.jpg')
imgplot = plt.imshow(img)
img = tf.expand_dims(img,0) # need this to make batch_shape = 1
img=img/255  # normalizing the image
img=tf.image.resize(img,size=(224, 224)) # resizing image
Prob=loaded_model.predict(img) # prediction
indd=tf.argmax(Prob[0],axis=-1).numpy()
print(tf.argmax(Prob[0],axis=-1).numpy())
print(labels_string[indd])

最新更新