This tutorial guides you through the process of capturing images, labeling a dataset, training a custom object detection model and deploying to a Meraki MV camera using Azure Machine Learning and Python.
You can also analyze data from the device and the results of custom object detection model by streaming to the cloud using Azure IoT Hub, Microsoft Fabric Eventstream, Azure KQL Database, and PowerBI visualizations.
- Cisco Meraki MV 2nd Generation Camera (MV2, MV12, MV32, MV22, MV72)
- Software version 4.18 on the camera
- Microsoft Azure Subscription
- A micro computer with Linux distribution. This demo used a Raspberry PI 4 device running the Bullseye Raspberry Pi OS
Step 1. Image Capture. Use the Meraki MV Camera to capture images to use for training a custom object detection model.
Step 2. Labeling. Use the Azure Machine Learning labeling project to prepare the data.
Step 3. Train Custom Object Detection Model. Train an object detection model using Azure Machine Learning Notebooks.
Step 4. Deploy. Use the Cisco Meraki Dashboard to deploy the model to the Meraki MV Camera.
Step 5. Stream to Azure. Setup streaming services to Azure so data from the camera can be analyzed and visualized.
Step 6. Analyze. Leverage the data on the cloud for analytics, visualization and automation such as event alerts.
The first step is to capture a set of images to use for training a custom object detection model.
-
Capture enough images to include a minimum of 50 examples of each class to be detected - but the more the better.
-
Keep the ratio between the most and least frequently captured classes below 2 to 1.
-
The more classes you have, the more individual samples per class you will need. If you have more than 50 classes, you would want a minimum of 200 examples of each class.
-
It's helpful to capture images with different lighting, settings, and combinations that are relevant to the scenario the model would be used in.
-
Place the objects in different orientations, positions, locations, and include some objects that you do NOT want to detect as well. Also, you may want to partially obscure some of the objects as well, by blocking with other objects or not being in completely in the frame.
For more information and suggestion see: Improve your Custom Vision Model.
The cvSnapper.py script uses a Meraki camera to take snapshots of objects within the frame.
First, set the following values In the config.py file:
-
api_keyis your Meraki Dashboard API Key. If you don't know how to generate one, follow the instructions in this article. -
camera_serialis the serial number of the camera you will be working with. -
desired_snapsis the number of snapshots you wish to take to construct your dataset. The more the better, especially if you want to be able to recognize many different classes, but you should see decent accuracy with around 100 images and 4 classes total. -
dataset_nameis how you want to name your dataset. For example,meraki_images. -
train_test_splitis the percentage of images in the dataset that will be used for training, while the remaining ones will be used for testing.
Once you have completed setting up the config.py, the next steps setup the environment and snapshot script.
-
In line
12of thecvSnapper.pyscript, change thewin_or_macvariable tomacorwindepending on your environment. -
Run
pip install -r requirements.txtto install the required Python libraries before proceeding (in the image_capture directory of this repo).
When you're ready and you have positioned the camera and objects you wish to use in the desired location and position, you can run the script with python cvSnapper.py.
The script will do the following:
- It will create a directory structure in the form:
images/
|_train/
|_test/
-
It will prompt you with
Press Enter to capture snapshot:, and after you press Enter (with no other input), it will generate a Snapshot from the camera you chose. It can be useful to have a Meraki Dashboard video stream of the camera open side by side to know what the camera is looking at before you request the snapshot and make any necessary adjustments. -
It will then ask you if you want to
Keep image? (Y/N):. If you answerYit will increase the snap counter, and save the image assnap_{snap_count}.jpgin the images folder. -
If you answer
N, it will discard the image and ask you if you wish to continue or not. If you answerY, it will prompt you again to take a new snapshot, and if you answerNit will exit the program -
The script will continue fetching snapshots until the counter reaches your
desired_snapssetting, and you have the desired number of images. -
After this, the script will randomly split your captured images according to your specified
train_test_splitand will place them in thetrainandtestfolders.
Once you have captured the images, use the Azure Machine Learning Labeling Project to prepare the dataset for training.
For general information about this service please see Image labeling capabilities.
Detailed instructions for this tutorial are here.
With the labeled images and an annotations file available from the previous step, you are ready to train a custom object detection model using transfer learning.
We will be leveraging a pre-trained TensorFlow model, specifically the SSD Mobilenet V2 Object Detection model with FPN-Lite feature extractor. The process we'll follow includes preparing the data, training the model, and evaluating the results. Once our model is trained and evaluated, we'll convert it to TFLite format. This conversion allows the model to be deployed on the Meraki Camera.
Detailed instructions for training the model are here.
After completing the steps to train your custom Object Detection model and exported model file prepared you can deploy the model to a Meraki Camera using the Cisco Meraki Dashboard.
Detailed instructions can be found in the MV Sense Custom Computer Vision documentation.
The next step is to scale from the Meraki Camera to Azure for additional Analytics and Visualization on data collected on the camera, including the output of the custom Object Detection model running on the camera. This is enabled by streaming data from the Meraki Camera to Azure.
-
Follow the instructions to Create an IOT Hub service on Azure.
-
Follow the instructions to Register a new device in the IoT hub representing your mosquitto broker.
Once you have set up those services on Azure, you will create the bridge from the Meraki device to Azure. Step by step instructions can be found here.
Now that we can stream the data to Azure, we can use Azure Data Fabric to do Real-Time Analytics, Visualize our data using Copilot assistance, and orchestrate automation based on events detected in the data. Step by step instructions to set this up are available here.
