python使用卷积神经网络(CNN,VGGNET)识别猫狗

简介: python使用卷积神经网络(CNN,VGGNET)识别猫狗

卷积神经网络的知识此处不再赘述 如不有疑问可以参考这篇文章CNN卷积神经网络


接下来的代码使用VGGNET模型去识别不同图片的特征,我们将使用ImageNet数据集上训练完成的RexNet-50模型去识别现实生活的实物  如动物等...


原图片如下

image.png

image.png

image.png

识别源码如下

from tensorflow import  keras
from keras.applications.resnet import ResNet50
from keras.preprocessing import  image
from  keras.applications.resnet import preprocess_input,decode_predictions
import  numpy as np
import  cv2
from PIL import  ImageFont,ImageDraw,Image
img1=r'C:dog.jpg'
img2=r'C:cat.jpg'
img3=r'C:deer.jpg'
weight_path=r'C:\Users\Admin\Desktop\resnet50_weights_tf_dim_ordering_tf_kernels.h5'
img=image.loda_img(img1,target_size=(224,224))
x=image.img_to_array(img)
x=np.expand_dims(x,axis=0)
x=preprocess_input(x)
def get_model():
    model=ResNet50(weights=weight_path)
    print(model.summary())
    return model
model=get_model()
#预测图片
preds=model.predict(x)
#打印出top-5的结果
print('predicted',decode_predictions(preds,top=5)[0])
#使用dog照片预测的结果
Predicted:[('n02108422','bull_mastiff','0.366562'),('n02110958','pug','0.3122419'),('n02093754','Border_terrier','0.16009717'),
           ('n02108915','French_bulldog','0.049768772'),('n02099712','Labrador_retriever','0.04569989')]
#使用猫照片预测的结果
Predicted:[('n02123045','tabby','0.92873186'),('n021204075','Eqyptian_cat','0.02793644'),('n02123159','tiger_cat','0.021263707'),
           ('n04493381','tub','0.0037994932'),('n04040759','radiator','0.0017052109')]
#使用🦌照片预测的结果
Predicted:[('n02422699','impala','0.30113414'),('n02417914','ibex','0.28613034'),('n02423022','gazelle','0.26537818'),
           ('n02422106','hartebeest','0.031009475'),('n02412080','ram','0.030351655')]


相关文章
|
3天前
|
机器学习/深度学习 自然语言处理 PyTorch
使用Python实现循环神经网络(RNN)的博客教程
使用Python实现循环神经网络(RNN)的博客教程
23 1
|
1天前
|
数据采集 文字识别 测试技术
神器!使用Python 轻松识别验证码
本文介绍了使用Python进行验证码识别,主要包括安装Tesseract OCR和相关Python库,如`pytesseract`和`opencv-python`。通过Pillow加载验证码图片,使用`pytesseract`进行简单数字验证码识别。对于数字字母混合的验证码,先进行二值化和降噪处理,然后使用`cv2.findContours`分割字符并分别识别。这种方法适用于自动化测试和爬虫中的验证码处理。
10 2
|
2天前
|
机器学习/深度学习 Python
【Python实战】——神经网络识别手写数字(三)
【Python实战】——神经网络识别手写数字
|
2天前
|
机器学习/深度学习 数据可视化 Python
【Python实战】——神经网络识别手写数字(二)
【Python实战】——神经网络识别手写数字(三)
|
2天前
|
机器学习/深度学习 数据可视化 Python
【Python实战】——神经网络识别手写数字(一)
【Python实战】——神经网络识别手写数字
|
3天前
|
机器学习/深度学习 算法 TensorFlow
Python深度学习基于Tensorflow(6)神经网络基础
Python深度学习基于Tensorflow(6)神经网络基础
16 2
Python深度学习基于Tensorflow(6)神经网络基础
|
3天前
|
存储 Shell 网络安全
|
5天前
|
机器学习/深度学习 PyTorch 算法框架/工具
使用Python实现卷积神经网络(CNN)
使用Python实现卷积神经网络(CNN)的博客教程
30 1
|
6天前
|
存储 JavaScript 前端开发
Python网络数据抓取(5):Pandas
Python网络数据抓取(5):Pandas
28 8
|
10天前
|
机器学习/深度学习 人工智能 算法
【AI 初识】什么是卷积神经网络 (CNN)?
【5月更文挑战第2天】【AI 初识】什么是卷积神经网络 (CNN)?