tflite 学习——生成.tflite 模型与验证

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








结果: Predicted: [('n03887697', 'paper_towel', 0.71528304), ('n15075141', 'toilet_tissue', 0.16052581), ('n02948072', 'candle', 0.03291733)]

Step 2 存储

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值