赞
踩
实际的图片——Dog:
预测的结果有误。但是没关系,自己可以找一些数据集,在此模型的基础上进行微调达到更好的效果。
关于InceptionV3(159层),Xception(126层),Inception_ResNet_V2(572层):
https://mydreamambitious.blog.csdn.net/article/details/123907490
关于ResNet50和ResNet101:
https://mydreamambitious.blog.csdn.net/article/details/123906833
关于MobileNet(88层)和MobileNetV2(88层):
https://mydreamambitious.blog.csdn.net/article/details/123907955
关于DenseNet121(121层),DenseNet169(169层),DenseNet201(201层):
https://mydreamambitious.blog.csdn.net/article/details/123908742
EfficientNetBX
https://mydreamambitious.blog.csdn.net/article/details/123929264
import os import cv2 import numpy as np import tensorflow.keras.applications.vgg16 from PIL import Image from tensorflow import keras from tensorflow.keras.preprocessing import image from tensorflow.keras.preprocessing.image import img_to_array from keras.applications.vgg16 import preprocess_input,decode_predictions def load_VGG_16(): #加载VGG16模型,并且保留顶层 model_VGG16=tensorflow.keras.applications.vgg16.VGG16(weights='imagenet') img_path='images/train/dog/1.jpg' # 将图像转换为网络需要的大小,因为我们这里加载的模型都是固定输入大小224*224 img=image.load_img(img_path,target_size=(224,224)) ##首先需要转换为向量的形式 img=image.img_to_array(img) # 扩充维度 img=np.expand_dims(img,axis=0) # 对输入的图像进行处理 img_out=preprocess_input(img) ## decode the results into a list of tuples (class, description, probability) # (one such list for each sample in the batch) #上面这段话的意思是输出包括(类别,图像描述,输出概率) preds=model_VGG16.predict(img_out) # 输出前三个结果的可能性 print('Predicted: ', decode_predictions(preds, top=3)[0]) print('Predicted: ', decode_predictions(preds, top=3)) def load_VGG_19(): #加载VGG16模型,并且保留顶层 model_VGG19=tensorflow.keras.applications.vgg19.VGG19(weights='imagenet') img_path='images/train/dog/1.jpg' # 将图像转换为网络需要的大小,因为我们这里加载的模型都是固定输入大小224*224 img=image.load_img(img_path,target_size=(224,224)) ##首先需要转换为向量的形式 img=image.img_to_array(img) # 扩充维度 img=np.expand_dims(img,axis=0) # 对输入的图像进行处理 img_out=preprocess_input(img) ## decode the results into a list of tuples (class, description, probability) # (one such list for each sample in the batch) #上面这段话的意思是输出包括(类别,图像描述,输出概率) preds=model_VGG19.predict(img_out) # 输出前三个结果的可能性 print('Predicted: ', decode_predictions(preds, top=3)[0]) print('Predicted: ', decode_predictions(preds, top=3)) if __name__ == '__main__': print('Pycharm') print('VGG16: Predict:\\n') load_VGG_16() print('VGG19: Predict:\\n') load_VGG_19()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。