Spaces:
Building
Building
Clement Vachet
commited on
Commit
·
ced969c
1
Parent(s):
0c345cc
docs: add section for deployed model
Browse files
README.md
CHANGED
@@ -16,21 +16,21 @@ short_description: Object detection Lambda
|
|
16 |
- Front-end: user interface via Gradio library
|
17 |
- Back-end: use of AWS Lambda function to run deployed ML models
|
18 |
|
19 |
-
## Local development
|
20 |
|
21 |
|
22 |
-
### 1. Building the docker image
|
23 |
|
24 |
bash
|
25 |
> docker build -t object-detection-lambda .
|
26 |
|
27 |
-
### 2. Running the docker container locally
|
28 |
|
29 |
bash
|
30 |
|
31 |
> docker run --name object-detection-lambda-cont -p 8080:8080 object-detection-lambda
|
32 |
|
33 |
-
### 3. Execution via user interface
|
34 |
Use of Gradio library for web interface
|
35 |
|
36 |
<b>Note:</b> The environment variable ```AWS_API``` should point to the local container
|
@@ -42,7 +42,7 @@ Command line for execution:
|
|
42 |
The Gradio web application should now be accessible at http://localhost:7860
|
43 |
|
44 |
|
45 |
-
### 4. Execution via command line:
|
46 |
|
47 |
Example of a prediction request
|
48 |
|
@@ -60,9 +60,9 @@ python
|
|
60 |
> --model yolos-small
|
61 |
|
62 |
|
63 |
-
## Deployment to AWS
|
64 |
|
65 |
-
### Pushing the docker container to AWS ECR
|
66 |
|
67 |
Steps:
|
68 |
- Create new ECR Repository via aws console
|
@@ -82,9 +82,9 @@ Example: ```object-detection-lambda```
|
|
82 |
- Push docker image to ECR
|
83 |
> docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
|
84 |
|
85 |
-
[Link to AWS Documention](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
|
86 |
|
87 |
-
### Creating and testing a Lambda function
|
88 |
|
89 |
<b>Steps</b>:
|
90 |
- Create function from container image
|
@@ -100,8 +100,7 @@ Advanced notes:
|
|
100 |
> aws lambda update-function-code --function-name object-detection --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
|
101 |
|
102 |
|
103 |
-
### Creating a REST API via API Gateway
|
104 |
-
|
105 |
|
106 |
<b>Steps</b>:
|
107 |
- Create a new ```Rest API``` (e.g. ```object-detection-api```)
|
@@ -114,3 +113,21 @@ Advanced notes:
|
|
114 |
Example AWS API Endpoint:
|
115 |
```https://<api_id>.execute-api.<aws_region>.amazonaws.com/dev/detect```
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
- Front-end: user interface via Gradio library
|
17 |
- Back-end: use of AWS Lambda function to run deployed ML models
|
18 |
|
19 |
+
## 1. Local development
|
20 |
|
21 |
|
22 |
+
### 1.1. Building the docker image
|
23 |
|
24 |
bash
|
25 |
> docker build -t object-detection-lambda .
|
26 |
|
27 |
+
### 1.2. Running the docker container locally
|
28 |
|
29 |
bash
|
30 |
|
31 |
> docker run --name object-detection-lambda-cont -p 8080:8080 object-detection-lambda
|
32 |
|
33 |
+
### 1.3. Execution via user interface
|
34 |
Use of Gradio library for web interface
|
35 |
|
36 |
<b>Note:</b> The environment variable ```AWS_API``` should point to the local container
|
|
|
42 |
The Gradio web application should now be accessible at http://localhost:7860
|
43 |
|
44 |
|
45 |
+
### 1.4. Execution via command line:
|
46 |
|
47 |
Example of a prediction request
|
48 |
|
|
|
60 |
> --model yolos-small
|
61 |
|
62 |
|
63 |
+
## 2. Deployment to AWS
|
64 |
|
65 |
+
### 2.1. Pushing the docker container to AWS ECR
|
66 |
|
67 |
Steps:
|
68 |
- Create new ECR Repository via aws console
|
|
|
82 |
- Push docker image to ECR
|
83 |
> docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
|
84 |
|
85 |
+
[Link to AWS ECR Documention](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
|
86 |
|
87 |
+
### 2.2. Creating and testing a Lambda function
|
88 |
|
89 |
<b>Steps</b>:
|
90 |
- Create function from container image
|
|
|
100 |
> aws lambda update-function-code --function-name object-detection --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
|
101 |
|
102 |
|
103 |
+
### 2.3. Creating a REST API via API Gateway
|
|
|
104 |
|
105 |
<b>Steps</b>:
|
106 |
- Create a new ```Rest API``` (e.g. ```object-detection-api```)
|
|
|
113 |
Example AWS API Endpoint:
|
114 |
```https://<api_id>.execute-api.<aws_region>.amazonaws.com/dev/detect```
|
115 |
|
116 |
+
|
117 |
+
### 2.4. Execution for deployed model
|
118 |
+
|
119 |
+
Example of a prediction request
|
120 |
+
|
121 |
+
bash
|
122 |
+
> encoded_image=$(base64 -i ./tests/data/boats.jpg)
|
123 |
+
|
124 |
+
> curl -X POST "https://<api_id>.execute-api.<aws_region>.amazonaws.com/dev/detect" \
|
125 |
+
> -H "Content-Type: application/json" \
|
126 |
+
> -d '{"body": "'"$encoded_image"'", "isBase64Encoded": true, "model":"yolos-small"}'
|
127 |
+
|
128 |
+
python
|
129 |
+
> python3 inference_api.py \
|
130 |
+
> --api https://<api_id>.execute-api.<aws_region>.amazonaws.com/dev/detect \
|
131 |
+
> --file ./tests/data/boats.jpg \
|
132 |
+
> --model yolos-small
|
133 |
+
|