- Ubuntu* 16.04
- Python* 3.6
- TensorFlow* 1.10.0
- OpenVINO™ 2019 R1 with Python API
-
Create virtual environment:
virtualenv venv -p python3 --prompt="(ssd)"
-
Activate virtual environment and setup OpenVINO™ variables:
. venv/bin/activate . /opt/intel/openvino/bin/setupvars.sh
TIP Good practice is adding
. /opt/intel/openvino/bin/setupvars.sh
to the end of thevenv/bin/activate
.echo ". /opt/intel/openvino/bin/setupvars.sh" >> venv/bin/activate
-
Install the modules:
pip3 install -e . pip3 install -e ../utils
For the case without GPU, use the
CPU_ONLY=true
environment variable:CPU_ONLY=true pip3 install -e . pip3 install -e ../utils
-
Download and prepare required submodules:
bash ../prepare_modules.sh
To train a Single Shot Detector, go to the
training_toolbox/ssd_detector
directory. The ssd_detector
folder with sample code
demonstrates 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 learns to detect vehicles and license plates on the BitVehicle dataset.
To train a model, go through the following steps:
-
Download training data and put it in the
data/bitvehicle
directory according to the data/bitvehicle/README.md file. Annotation files in the COCO format (refer to cocodataset for details) are already located indata/bitvehicle
.The resulting structure of the folder:
./data/bitvehicle/ ├── images/ │ ├── vehicle_0000001.jpg | ... ├── bitvehicle_test.json ├── bitvehicle_train.json └── README.md
-
Change
annotation_path
invlp/config.py
todata/bitvehicle
instead of test datasetdata/vlp_test/
. -
If necessary, modify training settings by editing training_toolbox/ssd_detector/vlp/config.py or leave them by default. For details, read comments in config.py. Notable parameters in the
train
class are:batch_size
- number of images in training batch. The default value is32
, but can be increased or decreased depending on the amount of available memory.annotation_path
- path to a JSON file with an annotation in the COCO format The default value is the relative path to the bitvehicle annotation, but you can use your own annotation.steps
- number of training iterationsexecution.CUDA_VISIBLE_DEVICES
- Environment variable to control the CUDA device used for training. The default value is0
. In case you have multiple GPUs, 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. The default value isENCODED
.NOTE: Caching might cause system slowdown, so if you do not have enough RAM memory, disable cashing by passing
NONE
to this parameter.
-
To start training, go to the
training_toolbox/ssd_detector
directory and run the command below:python3 tools/train.py vlp/config.py
TIP: To start from a pretrained checkpoint, use
initial_weights_path
inconfig.py
. -
To start the evaluation process, go to the
training_toolbox/ssd_detector
directory and run the command below:python3 tools/eval.py vlp/config.py
NOTE: Take the step 4 in another terminal, so training and evaluation are performed simultaneously.
-
Training and evaluation artifacts are 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 the command below:tensorboard --logdir=./model
Then view results in a browser: http://localhost:6006.
To run the model via OpenVINO™, freeze the TensorFlow graph and convert it to the OpenVINO™ Internal Representation (IR) using the Model Optimizer:
python3 tools/export.py --data_type FP32 --output_dir vlp/model/export vlp/config.py
The script results in three new artifacts:
Default export path
vlp/model/export_<step>/frozen_graph/
- path to the frozen graphvlp/model/export_<step>/IR/<data_type>/
- path to the converted model in the IR format
When the training is complete, you can infer the model from the checkpoint on
input data by running training_toolbox/ssd_detector/infer.py
:
python3 infer_checkpoint.py vlp/config.py --video --input=<path_to_input_video> --show
python3 infer_checkpoint.py vlp/config.py --json --input=<path_to_annotation_json> --show
python3 tools/infer.py --model vlp/model/export/frozen_graph/graph.pb.frozen \
<image_path>
python3 tools/infer_ie.py --model vlp/model/export/frozen_graph/graph.pb.frozen \
--device=CPU \
--cpu_extension="${INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/libcpu_extension_avx2.so" \
--input_type json \
--input ../../data/vlp_test/annotations_test.json \
--dump_predictions_to_json True \
--output_json_path test.json
A model in the IR format could be inferred using the Python sample from OpenVINO™ located at <path_to_computer_vision_sdk>/inference_engine/samples/python_samples/object_detection_demo_ssd_async/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>