Skip to content

Add lite version of the license plate reader example #994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update documentation for license plate reader proj
  • Loading branch information
RobertLucian committed May 1, 2020
commit e1bcdeb33a1ef5bf98ede120ed521fb0d9ca079f
71 changes: 64 additions & 7 deletions examples/tensorflow/license-plate-reader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,30 @@ The other two models, *CRAFT* and *CRNN*, can be found in [keras-ocr](https://gi

## Deploying

The recommended number of instances to run this smoothly on a video stream is about 12 GPU instances (2 GPU instances for *YOLOv3* and 10 for *CRNN* + *CRAFT*). `cortex.yaml` is already set up to use these 12 instances. Note: this is the optimal number of instances when using the `g4dn.xlarge` instance type. For the client to work smoothly, the number of workers per replica can be adjusted, especially for `p3` or `g4` instances, where the GPU has a lot of compute capacity.
### Lite Version

A non-real-time version of this project can be deployed with `cortex_lite.yaml`. For this kind of deployment, only x1 GPU is required. This only works for frames served as URL links. This way, cost-effective experimentation is made possible for those who want to get the example up and running quickly.

Once the cortex cluster is created, run
```bash
cortex deploy cortex_lite.yaml
```

And monitor the API with
```bash
cortex get --watch
```

### Full Version

The recommended number of instances to run this smoothly on a video stream is about 12 GPU instances (2 GPU instances for *YOLOv3* and 10 for *CRNN* + *CRAFT*). `cortex_full.yaml` is already set up to use these 12 instances. Note: this is the optimal number of instances when using the `g4dn.xlarge` instance type. For the client to work smoothly, the number of workers per replica can be adjusted, especially for `p3` or `g4` instances, where the GPU has a lot of compute capacity.

If you don't have access to this many GPU-equipped instances, you could just lower the number and expect dropped frames. It will still prove the point, albeit at a much lower framerate and with higher latency. More on that [here](https://github.com/RobertLucian/cortex-license-plate-reader-client).

Then after the cortex cluster is created, run

```bash
cortex deploy
cortex deploy cortex_full.yamll
```

And monitor the APIs with
Expand All @@ -42,7 +58,32 @@ And monitor the APIs with
cortex get --watch
```

## Launching the Client
## Launching the Client - Lite Version

To run an inference on the lite version, the only 3 tools you need are `curl`, `sed` and `base64`. This API expects an URL pointing to an image onto which the inferencing is done. This includes the detection of license plates with *YOLOv3* and the recognition part with *CRAFT* + *CRNN* models.

Export the endpoint & the image's URL by running
```bash
export ENDPOINT=your-api-endpoint
export IMAGE_URL=https://i.imgur.com/r8xdI7P.png
```

Then run the following piped commands
```
curl "${ENDPOINT}" -X POST -H "Content-Type: application/json" -d '{"url":"'${IMAGE_URL}'"}' |
sed 's/"//g' |
base64 -d > prediction.jpg
```

The resulting image is the same as the one in [Verifying the Deployed APIs](#verifying-the-deployed-apis).

For another prediction, let's use a generic image from the web. Export [this image's URL link](https://i.imgur.com/mYuvMOs.jpg) and re-run the prediction. This is what we get.

![annotated sample image](https://i.imgur.com/tg1PE1E.jpg)

*The above prediction has the bounding boxes colored differently to distinguish them from the cars' red bodies*

## Launching the Client - Full Version

### Verifying the Deployed APIs

Expand Down Expand Up @@ -83,11 +124,27 @@ Once the APIs are up and running, launch the streaming client by following the i

### Uploading the SavedModel to S3

The only model that has to be uploaded to an S3 bucket (for Cortex to deploy) is the *YOLOv3* model. The other two models are downloaded automatically upon deploying the service.
The only model that is uploaded to an S3 bucket (for Cortex to deploy) is the *YOLOv3* model. The other two models are downloaded automatically upon deploying the service.

If you would like to host the model from your own bucket, or if you want to fine tune the model for your needs, here's what you can do.

#### Lite Version

Download the *Keras* model:

*Note: The Keras model from [here](https://github.com/experiencor/keras-yolo3) has been converted to SavedModel model instead.*
```bash
wget -O license_plate.h5 "https://www.dropbox.com/s/vsvgoyricooksyv/license_plate.h5?dl=0"
```

And then upload it to your bucket (also make sure [cortex_lite.yaml](cortex_lite.yaml) points to this bucket):

```bash
BUCKET=my-bucket
YOLO3_PATH=examples/tensorflow/license-plate-reader/yolov3
aws s3 cp license_plate.h5 "s3://$BUCKET/$YOLO3_PATH/model.h5"
```

If you would like to host the model from your own bucket, or if you want to fine tune the model for your needs, you can:
#### Full Version

Download the *SavedModel*:

Expand All @@ -101,7 +158,7 @@ Unzip it:
unzip yolov3.zip -d yolov3
```

And then upload it to your bucket (also make sure [cortex.yaml](cortex.yaml) points to this bucket):
And then upload it to your bucket (also make sure [cortex_full.yaml](cortex_full.yaml) points to this bucket):

```bash
BUCKET=my-bucket
Expand Down