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

权重文件请点赞关注收藏后私信博主要

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

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

原图片如下

 

识别源码如下


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')]










权重文件请点赞关注收藏后私信博主要

  • 14
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

showswoller

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值