-
헬스기구 분류 AI API로 만들기Project/ML-헬스 기구 분류 및 운동법 추천 2023. 6. 20. 20:40반응형
import io from PIL import Image from flask_ngrok import run_with_ngrok from flask import Flask, jsonify, request def get_predict(image_bytes) : image = Image.open(io.BytesIo(image_bytes)) image = transforms_test(image).unsqueeze(0).to(device) with torch.no_grad() : outputs = model(image) _, preds = torch.max(outputs, 1) imshow(image.cup().data[0], title='예측결과' + class_names[preds[0]]) return class_names[preds[0]] app = Flask(__name__) @app.route('/post', methods=['POST']) def predict() : res = request.get if request.method == 'POST' : file = request.files['file'] image_bytes = file.read() class_name = get_predict(image_bytes=image_bytes) print("결과 : ", {'class_name' : class_name}) return jsonify({'class_name' : class_name})
파이썬 이미지 라이브러리로 전달받은 이미지를 byte화 하여 torch가 읽을 수 있는 형식으로 전환해준 뒤에
모델이 이를 예측하고 결과인 클래스이름을 리턴하는 함수를 만들었다.
그리고 삼성전자 주가 분석모델과 비슷하게 flask로 post요청을 받을 수 있는 함수를 작성했는데
HTTPConnectionPool(host='localhost', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5d913c5540>: Failed to establish a new connection: [Errno 111] Connection refused')) 위 에러와 함께 호기롭게 막혀버렷다..
구글링을 열심히 해봤는데 요청이 많아지면 그럴 수 있다고 한다..시간이 많이 없는데 테스트해보고 싶었지만
다음으로 미뤄둔다.. 지금 회사에서 진행하는 상담유형분류 모델도 작업해야하고 여행도 있기 때문에
일정을 소화한 뒤에 다시 돌아와 완성하도록 하자.
반응형'Project > ML-헬스 기구 분류 및 운동법 추천' 카테고리의 다른 글
헬스 머신 분류로 사용법까지 조회하기 (3) 2023.06.28 머신 분류 결과를 웹과 연결하기 (0) 2023.06.27 ngrok서버 구동 에러 Errno 111 Connection refused (0) 2023.06.27 헬스장 기구 분류 AI 진행과정 (0) 2023.06.15 헬스 머신 분류 및 운동법을 알려주는 AI (0) 2023.06.12