简体   繁体   English

卷积神经网络新手

[英]Convolutional neural network Newbie

I am new to CNN so I am trying to learn to code it with python by following tutorials online, and I came up to this tutorial: https://medium.com/nybles/create-your-first-image-recognition-classifier-using-cnn-keras-and-tensorflow-backend-6eaab98d14dd I followed the code and all but I get this small error that I can't seem to know the solution:我是 CNN 的新手,所以我正在尝试通过以下在线教程学习使用 python 进行编码,我想到了本教程: https://medium.com/nybles/create-your-first-image-recognition-classifier -using-cnn-keras-and-tensorflow-backend-6eaab98d14dd我遵循了代码,但我得到了这个我似乎不知道解决方案的小错误:

FileNotFoundError: [Errno 2] No such file or directory: 'random.jpg' FileNotFoundError:[Errno 2] 没有这样的文件或目录:'random.jpg'

This is the code where the error points out to:这是错误指出的代码:

import numpy as np
from keras.preprocessing import image
test_image = image.load_img('random.jpg',target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] >= 0.5:
    prediction = 'dog'
else:
    prediction = 'cat'
    print(prediction)

I'm going to include the whole code just in case people want to see: https://drive.google.com/open?id=1ew22sJOvl5Ea9VTM_PXqVKNZJm1OuXTG我将包含整个代码以防万一人们想看到: https://drive.google.com/open?id=1ew22sJOvl5Ea9VTM_PXqVKNZJm1OuXTG

Any help is appreciated.任何帮助表示赞赏。 :) :)

You need to give full path to the image or put code file and the image to the same file.您需要提供图像的完整路径或将代码文件和图像放在同一个文件中。

Based on what I read on the blog post, he used just a random dog image (downloaded from any web), name it as "random.jpg", and use it as a test image.根据我在博客文章中看到的内容,他只使用了一张随机的狗图片(从任何网络下载),将其命名为“random.jpg”,并将其用作测试图片。 You can just seek for any dog/cat image around the web, download and rename it as "random.jpg".您可以在 web 周围寻找任何狗/猫图像,下载并将其重命名为“random.jpg”。

The point is, you know the image is a dog or cat, then test your model to predict what image it is.关键是,您知道图像是狗还是猫,然后测试您的 model 以预测它是什么图像。

You need to put 'random.jpg' into your working directory.您需要将“random.jpg”放入您的工作目录。 That is put any file( a dog, cat, or any) with that name inside your folder:)就是将具有该名称的任何文件(狗、猫或任何文件)放入您的文件夹中:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM