The following instructions will enable you to build a docker container with a YOLOv3 Keras custom model, built with this repository, using nginx, gunicorn, flask, and runit. The app code is based the Keras YOLOv3 implementation for object detection at https://github.com/qqwweee/keras-yolo3. Keras 2.2.4 and TensorFlow 1.15.2 are used in this project. This model has not take advantage of optimizations, but may be sufficient given the device and resources in which it will run.
Note: References to third-party software in this repo are for informational and convenience purposes only. Microsoft does not endorse nor provide rights for the third-party software. For more information on third-party software please see the links provided above.
- Install Docker on your machine
- Install curl
- Custom anchors file (named
custom_anchors.txt
and placed inapp
folder) - Custom classes file (named
custom_classes.txt
and placed inapp
folder) - YOLO v3 Keras model (named
custom_model.h5
and placed inapp
folder)
- Create a new directory on your machine and copy all the files (including the sub-folders) from this GitHub folder to that directory.
- Build the container image (should take some minutes) by running the following docker command from a command window in that directory.
docker build . -t yolov3-keras:latest
Run the container using the following docker command.
docker run --name my_yolo_container -p 80:80 -d -i yolov3-keras:latest
Test the container using the following commands.
Since the LVA edge module is capable of sending specified size image in specified format, we are not preprocessing the incoming images to resize them. This is mainly because of the performance improvement.
To get a list of detected objects, use the following command.
curl -X POST http://127.0.0.1/score -H "Content-Type: image/jpeg" --data-binary @<image_file_in_jpeg>
If successful, you will see JSON printed on your screen that looks something like this
{
"inferences": [
{
"type": "entity",
"entity": {
"tag": {
"value": "hardhat",
"confidence": "0.9017146"
},
"box": {
"l": "0.5199710921937251",
"t": "0.0000000000000000",
"w": "0.38537373941733066",
"h": "0.8657244792833408"
}
}
}
]
}
Terminate the container using the following docker commands.
docker stop my_yolo_container
docker rm my_yolo_container
Follow instruction in Push and Pull Docker images - Azure Container Registry to save your image for later use on another machine.
Follow instruction in Deploy module from Azure portal to deploy the container image as an IoT Edge module (use the IoT Edge module option).