Loading... ## 神经网络已经为您训练完成! <button class=" btn m-b-xs btn-warning btn-addon" onclick="window.open('http://blog.a152.top/usr/uploads/2021/08/118235401.h5','_blank')"><i class="glyphicon glyphicon-cloud-download"></i>下载已经完成的cnn</button> 使用代码如下: ```python import keras from keras.models import load_model model = load_model('简单的猫狗cnn.h5') model.summary() ``` 如何进行识别? ```python from matplotlib import pyplot as plt import numpy as np path = 'testimg/QQ图片20210802200354.jpg' #图片路径 img_height, img_width = 150,150 #大小改为固定格式 img_keras = keras.preprocessing.image.load_img(path=path, target_size=(img_height, img_width)) plt.imshow(img_keras) img_keras = np.array(img_keras) img_keras = img_keras/255 img_keras = np.expand_dims(img_keras, axis=0) img_keras.reshape(150,150,3) print('狗狗的相似度是',model.predict(img_keras)[0][0]) print('猫猫的相似度是',1-model.predict(img_keras)[0][0]) ``` Last modification:August 3, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的内容对你有用,请随意赞赏