{"id":25010069,"url":"https://github.com/kyopark2014/image-classification-api-server","last_synced_at":"2026-03-08T02:04:39.814Z","repository":{"id":111876182,"uuid":"584025541","full_name":"kyopark2014/image-classification-api-server","owner":"kyopark2014","description":"It shows API server for image classification based on RESNET-50.","archived":false,"fork":false,"pushed_at":"2023-07-14T05:53:25.000Z","size":77429,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T19:39:49.367Z","etag":null,"topics":["api-gateway","dlr","docker-image","image-classification","inference","lambda-functions","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyopark2014.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-01T01:00:59.000Z","updated_at":"2025-04-01T12:26:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"be9d2c12-1959-4144-ba0d-b1a9196404b6","html_url":"https://github.com/kyopark2014/image-classification-api-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kyopark2014/image-classification-api-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyopark2014%2Fimage-classification-api-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyopark2014%2Fimage-classification-api-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyopark2014%2Fimage-classification-api-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyopark2014%2Fimage-classification-api-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyopark2014","download_url":"https://codeload.github.com/kyopark2014/image-classification-api-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyopark2014%2Fimage-classification-api-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30242404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-gateway","dlr","docker-image","image-classification","inference","lambda-functions","machine-learning"],"created_at":"2025-02-05T04:52:33.957Z","updated_at":"2026-03-08T02:04:39.808Z","avatar_url":"https://github.com/kyopark2014.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 머신러닝(ML) 기반의 이미지 분류를 위한 API 서버 만들기 \n\nRESNET-50를 사용하는 AWS의 [DLR(Deep Learning Runtime)](https://docs.aws.amazon.com/greengrass/v2/developerguide/dlr-component.html) 이미지 분류 모델을 이용하여 추론을 수행하고자 합니다. \n\n전체적인 Architecture는 아래와 같습니다. 이미지 분류를 사용하는 Client는 RESTful API로 syncronous하게 이미지를 분류할 수 있습니다. API요청시 API Gateway의 address를 Endpoint로 이용합니다. 이때 API 이름으로 \"/classifier\"를 이용하면 API Gateway와 연결된 Lambda로 요청이 event의 형태로 인입되어서, 이미지 분류를 위한 추론이 수행됩니다. Lambda는 Container로 배포되는데 이미지 추론에는 DLR Model을 사용합니다. Lambda Function URL이 아닌 API Gateway를 사용하는것은 외부에서 public하게 open되는 케이스를 고려하기 위함입니다. Lambda 및 API Gateway의 배포시에 AWS CDK와 ECR을 이용합니다. \n\n![image](https://user-images.githubusercontent.com/52392004/221357663-c4e1ba1d-b45f-411f-81a4-9b688feac83b.png)\n\n\n## Image Classification\n\nevent의 \"body-json\"으로 들어온 upload된 이미지를 base64로 encoding후 UTF8로 decoding하여 이미지 데이터를 추출 합니다. \n```java\ndata = base64.b64decode(event['body-json'])\n\n# convert string of image data to uint8\nencoded_img = np.fromstring(data, dtype = np.uint8)\n\nimage_data = cv2.imdecode(encoded_img, cv2.IMREAD_COLOR)\n```\n\n이미지 데이터를 json 포맷으로 바꾸어 추론(inference)를 수행하는 inference.py에 아래와 같이 요청합니다. 추론결과의 가장 높은 확율을 가지는 object의 label을 리턴합니다. \n```java\nevent = {\n 'body': image_data\n}\n\ntry:\n result = inference.handler(event,\"\")          \n return result['body'][0]['Label']\nexcept:\ntraceback.print_exc()\n```\n\nContainer 생성시 필요한 Dockerfile은 아래와 같습니다.\n\n```java\nFROM amazon/aws-lambda-python:3.8\n\nRUN pip3 install --upgrade pip\nRUN pip3 install scikit-build wheel \nRUN pip3 install opencv-python==4.6.0.66 \n\nRUN python -m pip install joblib awsiotsdk pandas\nRUN yum install libglvnd-glx -y\nRUN python -m pip install dlr\nRUN pip3 install dlr==1.6.0\n\nWORKDIR /var/task/image-classifier\n\nCOPY inference.py /var/task\nCOPY classifier.py /var/task\n\nCOPY . .\n\nCMD [\"classifier.run\"]\n```\n\n## 배포\n\n인프라 설치는 아래와 같이 수행합니다.\n\n```java\ngit clone https://github.com/kyopark2014/image-classification-api-server\ncd cdk-lambda-api \u0026\u0026 npm install aws-cdk-lib@2.64.0 path \ncdk deploy\n```\n\n배포후 아래와 같은 값을 얻습니다.\n\n![image](https://user-images.githubusercontent.com/52392004/221360112-bdb0e611-9971-4443-ac41-33ceefe8bee6.png)\n\n여기서 ApiGatewayUrl의 주소는 \"https://f8wr4q0nlj.execute-api.ap-northeast-2.amazonaws.com/dev/classifier\" 와 같고 Web으로 접속할 주소는 \"https://d1twzjcpb87z2n.cloudfront.net/classifier.html\"임을 알 수 있습니다.\n\n### Web에서 시험하기\n\n아래와 같이 Web으로 접속해서 [Choose File]을 선택하여 이미지를 지정하고 [Send]를 선택하여 Classification을 요청합니다. \n\n![image](https://user-images.githubusercontent.com/52392004/221360058-4f57732e-8b51-4ae1-aa35-0c04dddb2ac7.png)\n\n\n### Postman으로 시험하기 \n\nPostman을 이용해 테스트시에 아래와 같이 수행합니다.\n\n- Content-Type으로 \"image/jpeg\"을 입력합니다. \n\n![image](https://user-images.githubusercontent.com/52392004/211182527-c86878bb-a7be-47a9-93c2-4613924912bc.png)\n\n- body에서 파일을 선택합니다. \n\n![image](https://user-images.githubusercontent.com/52392004/211182507-0cf39f97-40c7-41e7-9c76-0b0f3d5baabd.png)\n\n\n아래와 같은 이미지를 업로드합니다. \n\n![dog](https://user-images.githubusercontent.com/52392004/211182490-fa9f59ff-4435-407d-b877-d1399132a0ce.jpg)\n\n\n이때의 결과는 아래와 같습니다. \n\n```java\n{\n    \"statusCode\": 200,\n    \"label\": \"Weimaraner\"\n}\n```\n\n## 결과 예제\n\n- \"label\": \"cup\"\n\n\u003cimg src=\"https://user-images.githubusercontent.com/52392004/211224277-40571e68-aad7-4923-b18b-99745b3733c5.jpeg\" width=\"400\"\u003e\n\n\n- \"label\": \"coffee mug\"\n\n\u003cimg src=\"https://user-images.githubusercontent.com/52392004/211223986-2650ab6f-2b9f-4d02-b278-3ad149b6c5bf.jpeg\" width=\"800\"\u003e\n\n\n\n- \"label\": \"ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin\"\n\n\u003cimg src=\"https://user-images.githubusercontent.com/52392004/211224017-39facb8e-24f2-42c6-8bbb-88fa160031dd.jpeg\" width=\"400\"\u003e\n\n\n\n- \"label\": \"sports car, sport car\"\n\n\u003cimg src=\"https://user-images.githubusercontent.com/52392004/211224064-7fa64af5-1924-4b73-b312-fdc1ba972c42.jpeg\" width=\"800\"\u003e\n\n\n\n- \"label\": \"crash helmet\"\n\n\u003cimg src=\"https://user-images.githubusercontent.com/52392004/211224133-bdaf1a6c-af2a-4db9-a461-3c73f13ec62f.jpeg\" width=\"800\"\u003e\n\n## RESNET-50\n\n\n### Demos\n\n- [GluonCV ResNet50 Classifier Demo](https://aws.amazon.com/marketplace/ai/model-evaluation?productId=587dc453-b6d6-487e-abc4-133b4bd3a0ed)\n\n- [RESNET-50 Demo](https://aws.amazon.com/marketplace/ai/model-evaluation?productId=cc879d3b-e759-4270-9afb-ceb50d2f7fe6)\n\n \n ## Reference \n\n[Github: neo-ai-dlr](https://github.com/neo-ai/neo-ai-dlr)\n\n[DLR image classification model store](https://docs.aws.amazon.com/greengrass/v2/developerguide/dlr-image-classification-model-store-component.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyopark2014%2Fimage-classification-api-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyopark2014%2Fimage-classification-api-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyopark2014%2Fimage-classification-api-server/lists"}