用Resnet 模型进行验证
Step 1 导入resnet 50模型
import numpy as np
import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
for device in physical_devices: # 使用GPU
tf.config.experimental.set_memory_growth(device, True)
model = tf.keras.applications.resnet50.ResNet50(weights='imagenet') # 导入resnet 模型
img = tf.keras.utils.load_img('123.jpg', target_size=[224, 224,3]) # 载入图片并给出size
x = tf.keras.preprocessing.image.img_to_array(img) # 处理输入图片尺寸
x = np.expand_dims(x, axis=0)
x = tf.keras.applications.resnet50.preprocess_input(x)
preds = model.predict(x) # 预测结果
# 将结果解码为元组列表 (class, description, probability)
# (一个列表代表批次中的一个样本)
print('Predicted:', tf.keras.applications.resnet50.decode_predictions(preds, top=3)[0])

最低0.47元/天 解锁文章
1661

被折叠的 条评论
为什么被折叠?



