diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/main.py" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/main.py" new file mode 100644 index 00000000..47593659 --- /dev/null +++ "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/main.py" @@ -0,0 +1,22 @@ +import cv2 +import os +import boto3 +import json + +def check_frame(frame): + payload = json.dumps(frame.tolist()) + response = client.invoke_endpoint(EndpointName=ENDPOINT_NAME, ContentType='application/json',Body=payload) + res = json.load(response['Body'])['predictions'] + return res[0] > res[1] + +cap = cv2.VideoCapture('动画师如何用蔬菜水果拍摄一段定格动画,看饿了.flv') #打开摄像头 +while True: + ret, frame = cap.read() #读取摄像头画面 + cv2.imshow('v', frame) + cv2.waitKey(30) + # if not check_frame(frame): #判断是否有腐烂的水果 + # print('有腐烂的水果') +#初始化调用endpoint +ENDPOINT_NAME = 'sagemaker-tensorflow-serving-2020-09-14-21-13-59-342' +client = boto3.client('runtime.sagemaker', region_name='cn-northwest-1', aws_access_key_id='', aws_secret_access_key='') + diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/readme.md" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/readme.md" new file mode 100644 index 00000000..45c3bcce --- /dev/null +++ "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/readme.md" @@ -0,0 +1,32 @@ +# 果识 - 乌兹到底行不行 + +## 作品介绍 + +通过AWS SagerMaker训练图片分类模型并部署。使用opencv调用摄像头获取图片,使用boto3调用endpoint部署的算法。 + +## 使用的AWS服务和技术 + +* 将训练数据上传到 AWS S3 +* 使用SageMaker 训练任务 训练图片分类模型 +* 使用SageMaker Endpoint 部署模型 +* 使用开发工具包 boto3 调用模型 + +## 实现过程 + +### 数据来源 +[水果图片数据集](https://www.kaggle.com/sriramr/fruits-fresh-and-rotten-for-classification) + +共包括3种新鲜水果和3种腐烂水果 + +### 训练图片分类模型 +![](截图/s3数据.png) +![](截图/训练超参数.jpg) +![](截图/数据配置.jpg) +![](截图/训练指标.jpg) +![](截图/部署终端节点.jpg) + +### 调用摄像头获取图片并分类 +![](截图/摄像头拍摄视频.png) + +## 贡献者名单及联系方式 +孙东牛 1254750354@qq.com diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/s3\346\225\260\346\215\256.png" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/s3\346\225\260\346\215\256.png" new file mode 100644 index 00000000..30e231c7 Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/s3\346\225\260\346\215\256.png" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\221\204\345\203\217\345\244\264\346\213\215\346\221\204\350\247\206\351\242\221.png" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\221\204\345\203\217\345\244\264\346\213\215\346\221\204\350\247\206\351\242\221.png" new file mode 100644 index 00000000..45506e24 Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\221\204\345\203\217\345\244\264\346\213\215\346\221\204\350\247\206\351\242\221.png" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\225\260\346\215\256\351\205\215\347\275\256.jpg" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\225\260\346\215\256\351\205\215\347\275\256.jpg" new file mode 100644 index 00000000..127dfbcb Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\346\225\260\346\215\256\351\205\215\347\275\256.jpg" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\346\214\207\346\240\207.jpg" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\346\214\207\346\240\207.jpg" new file mode 100644 index 00000000..f6f131c7 Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\346\214\207\346\240\207.jpg" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\350\266\205\345\217\202\346\225\260.jpg" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\350\266\205\345\217\202\346\225\260.jpg" new file mode 100644 index 00000000..f33eacb0 Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\350\256\255\347\273\203\350\266\205\345\217\202\346\225\260.jpg" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\351\203\250\347\275\262\347\273\210\347\253\257\350\212\202\347\202\271.jpg" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\351\203\250\347\275\262\347\273\210\347\253\257\350\212\202\347\202\271.jpg" new file mode 100644 index 00000000..3f6539ed Binary files /dev/null and "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\346\210\252\345\233\276/\351\203\250\347\275\262\347\273\210\347\253\257\350\212\202\347\202\271.jpg" differ diff --git "a/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\347\224\237\346\210\220lst\346\226\207\344\273\266.py" "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\347\224\237\346\210\220lst\346\226\207\344\273\266.py" new file mode 100644 index 00000000..526818e1 --- /dev/null +++ "b/4 \351\244\220\345\216\205\345\217\212\345\220\216\345\216\250\345\215\253\347\224\237\345\256\211\345\205\250\347\232\204\350\207\252\345\212\250\347\233\221\346\265\213/\346\236\234\350\257\206 - \344\271\214\345\205\271\345\210\260\345\272\225\350\241\214\344\270\215\350\241\214/\347\224\237\346\210\220lst\346\226\207\344\273\266.py" @@ -0,0 +1,20 @@ +import os +from sklearn import preprocessing +le = preprocessing.LabelEncoder() +labels = ['freshapples', 'rottenapples'] +le.fit(labels) +idx = 0 + +def lst(channel): + global idx + dirs = os.listdir(channel) + with open(channel + '.lst' , 'w', encoding='utf-8') as fp: + for label in dirs: + class_num = str(le.transform([label])[0]) + files = os.listdir(os.path.join(channel, label)) + for file in files: + fp.write(str(idx) + '\t' + class_num + '\t' + label + '/' + file + '\n') + idx += 1 + +lst('train') +lst('validation') \ No newline at end of file