首先网上找了7张图
打算对这7张图片进行识别,直接上代码:
from tensorflow.keras import applications
#decode_predictions 对预测结果进行处理,解码
from tensorflow.keras.applications.vgg16 import decode_predictions
#preprocess_input处理输入图片
from tensorflow.keras.applications.vgg16 import preprocess_input
from tensorflow import keras
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.preprocessing.image import load_img
#VGG 图片输入大小要求 224*224*3
#VGG 有1.4亿个参数
#获取已训练好的模型
def predict(my_model,images):
y_lables = []
for image in images:
y_predictions = my_model.predict(image)
# print(y_predictions)
y_lable = decode_predictions(y_predictions)
y_lables.append(y_lable)
return y_lables
#图片读取处理
def load_img1(files_path):
images=[]
#加载图片