To train a Single Shot Detector, jump to
training_toolbox/ssd_detector directory. You'll see the ssd_detector
folder with sample code
demonstrating how to train a MobileNetV2-based SSD object detector.
We provide 2 predefined configurations:
-
Vehicles and license plates detector.
- Configuration file: training_toolbox/ssd_detector/vlp/config.py.
- Trained model: MobileNet v2 0.35 256x256.
-
Object detector trained on the COCO dataset.
- Configuration file: training_toolbox/ssd_detector/coco/config.py.
- Trained model: MobileNet v2 1.0 256x256.
The sample model will learn how to detect vehicles and license plates on BitVehicle dataset. The resulting model can further be used to build a sample application, similar to "security barrier" from OpenVINO™.
To train a model, go through the following steps:
-
Download training data and put it in the
data/bitvehicle
directory according to data/bitvehicle/README.md file. Annotation files in the COCO format (refer to cocodataset for details) are already located indata/bitvehicle
. -
If necessary, you can modify training settings by editing training_toolbox/ssd_detector/vlp/config.py or leave them by default. For more details please read comments in config.py. Notable parameters in
train
class are:batch_size
- number of images in training batch, by default it's set to32
, but could be increased or decreased depending on the amount of available memory.annotation_path
- path to json file with annotation in the COCO format, by default it's set to relative path to bitvehicle annotation, but you could use your own annotation.steps
- number of training iterationsexecution.CUDA_VISIBLE_DEVICES
- Environment variable to control cuda device used for training. By default, it's set to0
. In case you have multiple GPUs, you can change it to the respective number, or leave this string empty, if you want to train on CPU.cache_type
- type of input data to save in cache to speed-up data loading and preprocessing. By default it's set toENCODED
. Remember that caching might cause system slowdown, so if you don't have enough RAM memory better to disable it, passNONE
to this parameter.
-
To start training go to
training_toolbox/ssd_detector
directory and type in command line:python3 train.py vlp/config.py
-
To start evaluation process go to
training_toolbox/ssd_detector
directory and type in command line:python3 eval.py vlp/config.py
Do step 4 in another terminal, so training and evaluation are performed simultaneously.
-
Training and evaluation artifacts will be stored by default in
training_toolbox/ssd_detector/vlp/model
. To visualize training and evaluation, go totraining_toolbox/ssd_detector/vlp
and run tensorboard with:tensorboard --logdir=./model
And view results in a browser: http://localhost:6006.
-
When training is complete, model from the checkpoint could be infered on input data by running
training_toolbox/ssd_detector/infer.py
:python3 infer.py vlp/config.py --video --input=<path_to_input_video> --show
-
Finally, trained model could be converted to Inference Engine format for optimized inference. To export, go to
training_toolbox/ssd_detector
and runexport.py
:python3 export.py vlp/config.py <path_to_mo.py>
If OpenVINO™ was installed in a home directory, then
<path_to_mo.py>
is~/intel/computer_vision_sdk/deployment_tools/model_optimizer/mo.py
.As a result, you'll find three new artifacts in
training_toolbox/ssd_detector/vlp/model/ie_model
:graph.pb
- TensorFlow frozen graph,graph.xml
andgrapn.bin
- Inference Engine representation of the model.
-
Model in IR format could be infered using python sample from OpenVINO™ which could be found here:
<path_to_computer_vision_sdk>/inference_engine/samples/python_samples/object_detection_demo_ssd_async.py
python3 object_detection_demo_ssd_async.py -m <path_to_converted_model>/graph.xml -l <path_to_computer_vision_sdk>/deployment_tools/inference_engine/lib/ubuntu_16.04/intel64/libcpu_extension_avx2.so -i <path_to_input_video>