Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

果识 - 乌兹到底行不行 #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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='')

Original file line number Diff line number Diff line change
@@ -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)

## 贡献者名单及联系方式
孙东牛 [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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')