使用深度学习(tensorflow)识别动物的简单案例(vgg16)包含数据集及代码——0基础版

1.Tensorflow 版本

tensorflow的版本是1.12.0
如何安装tensorflow1.12.0?首先使用conda创建python版本为3.6的虚拟环境,然后再在虚拟环境中使用命令conda install tensorflow==1.12.0安装tensorflow 1.12.0版本。具体过程请百度。

2.VGG16模型权重数据集下载

链接:https://pan.baidu.com/s/1OBQUWafOF8LYY73-sW7SUw
提取码:xcmp

下载后的数据移动至目录:C:\Users\Administrator\.keras\models(不同机器目录可能不同)
在这里插入图片描述

3.实现

from tensorflow.python.keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
from tensorflow.python.keras.preprocessing.image import load_img, img_to_array


def predict():
    model = VGG16()
    # print(model.summary())
    # !!!记得修改图片路径
    image = load_img("./image/i5.jpg", target_size=(224, 224))
    image = img_to_array(image)

    # 输入卷积中需要4维结构
    image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
    print("形状:", image.shape)

    # 预测之前做图片的数据处理,归一化处理等
    image = preprocess_input(image)
    y_predictions = model.predict(image)

    # 对结果进行解码,按照降序排序结果
    label = decode_predictions(y_predictions)
    print("预测的类别是:%s, 其概率为:%f" % (label[0][0][1], label[0][0][2]))

    # 预测一张图的类别


if __name__ == '__main__':
    predict()

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值