python,人工智能,水果识别.pdf
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
python,⼈⼯智能,⽔果识别 1) 需求分析 1.⽔果数据处理:对⽔果(苹果,⾹蕉)进⾏处理转化为标签和图像,并转化为one-hot码。 2.卷积模型搭建:采⽤搭建模型,卷积层、池化层、Dropout层、全连接层、输出层 3.模型训练把数据集在建⽴的模型上进⾏训练,并把最好的模型保存到h5⽂件中,便于直接对模型进⾏测试。 4.模型测试:打开摄像头,使⽤通⽤物体进⾏测试。测试结果将录制成视频展⽰。 2) 概要设计 1. 测试前代码: from keras.applications.resnet50 import ResNet50 #//导⼊AI软件平台keras ⾥的AI模型 ResNet50 from keras.preprocessing import image#//导⼊图像处理库 image from keras.applications.resnet50 import preprocess_input, decode_predictions import numpy as np #//载⼊模型 model = ResNet50(weights='imagenet') #//使model指向ResNet50模型 img_path = '鸟.jpg' #//等待识别的图像(可⽤车,⽔果等),注:需把图⽚放该代码的同⽬录下 img = image.load_img(img_path, target_size=(224, 224)) #//载⼊图像 #//-图像的预处理 x = image.img_to_array(img) #//把图像转换为数组 x = np.expand_dims(x, axis=0) #//沿轴0(⾏)扩展 -> 多维数组 x = preprocess_input(x) #//做输⼊预处理 #//预测 preds = model.predict(x) #//运⾏模型进⾏预测 print('Predicted:', decode_predictions(preds, top=3)[0]) #//解码预测,输出结果 2. 主程序: import cv2 from keras.applications.resnet50 import ResNet50 from keras.preprocessing import image from keras.applications.resnet50 import preprocess_input, decode_predictions import numpy as np img_path = 'capyure.jpg' def capture_camera_pic(): cv2.namedWindow('capture_pic') cp = cv2.VideoCapture(0) # //指定摄像头,默认0指向第⼀个 while cp.isOpened(): # //检测摄像头是否打开,如果摄像头能成功打开,则进⾏循环的视频拍照显⽰ ok, frame = cp.read() # 读取⼀帧数据 if not ok: # 如果拍照失败,退出 break cv2.imwrite(img_path, frame) # 保存图像 # 翻译 # translator = Translator(to_lang='chinese') # translation = translator.translate(jieguo()) cv2.putText(frame, jieguo(), (30, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 4) cv2.imshow('capture_pic', frame) # 显⽰图像 c = cv2.waitKey(10) if c & 0xff == ord('q'): break cp.release() cv2.destroyAllWindows() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 def jieguo(): model = ResNet50(weights='imagenet') img_path = 'capyure.jpg' img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) x = np.expa
- 粉丝: 168
- 资源: 3万+
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助