PINTO0309 / OpenVINO-YoloV3

YoloV3/tiny-YoloV3+RaspberryPi3/Ubuntu LaptopPC+NCS/NCS2+USB Camera+Python+OpenVINO
https://qiita.com/PINTO
Apache License 2.0
537 stars 165 forks source link

Unable to run yolov3_tiny with different input_size #42

Open cfdcfc opened 5 years ago

cfdcfc commented 5 years ago

Hi,

First of all, I have successfully implement openvino_tiny-yolov3_test.py. Then, I would like to trade the accuracy for speed by reducing the input_size (416 -> 320), I have successfully achieve this in yolov3. However, I am not able to achieve this in yolov3_tiny, please see the below details:

get model wget https://pjreddie.com/media/files/yolov3-tiny.weights

convert yolo to tensorflow python3 /opt/OpenVINO-YoloV3/convert_weights_pb.py --class_names /opt/darknet/data/coco.names --weights_file /opt/darknet/yolov3-tiny.weights --data_format NHWC --output_graph /data/train/frozen_darknet_yolov3_tiny_model.pb --size 320 --tiny

convert tensorflow to IR python3 /opt/intel/openvino/deployment_tools/model_optimizer/mo_tf.py --input_model /data/train/frozen_darknet_yolov3_tiny_model.pb --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/yolo_v3_tiny.json --data_type FP16 --batch 1 --output_dir /data/train/

try to test with python(On Raspberry Pi Stretch with NCS2)

import os

try:
    from armv7l.openvino.inference_engine import IENetwork, IEPlugin
except:
    from openvino.inference_engine import IENetwork, IEPlugin

model_xml = "/home/pi/models/frozen_darknet_yolov3_tiny_model.xml"
model_bin = os.path.splitext(model_xml)[0] + ".bin"

plugin = IEPlugin(device="MYRIAD")
net = IENetwork(model=model_xml, weights=model_bin)
input_blob = next(iter(net.inputs))
exec_net = plugin.load(network=net)

Then error occurs:

Traceback (most recent call last): File "yolov3_tiny_test.py", line 14, in exec_net = plugin.load(network=net) File "ie_api.pyx", line 395, in openvino.inference_engine.ie_api.IEPlugin.load File "ie_api.pyx", line 406, in openvino.inference_engine.ie_api.IEPlugin.load RuntimeError: [VPU] Internal error: Output in detector/yolo-v3-tiny/pool2_5/MaxPool has incorrect width dimension. Expected: 9 or 9 Actual: 10

PINTO0309 commented 5 years ago
  1. Install Tensorflow v1.12.0
    $ sudo -H pip3 install tensorflow==1.12.0 --upgrade
  2. Execute below.
    $ python3 /opt/intel/openvino/deployment_tools/model_optimizer/mo_tf.py \
    --input_model /data/train/frozen_darknet_yolov3_tiny_model.pb \
    --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/yolo_v3_tiny.json \
    --data_type FP16 \
    --batch 1 \
    --output_dir /data/train/ \
    --input_shape [1,320,320,3]
cfdcfc commented 5 years ago

Hi PINTO0309,

Thanks for the response, I followed your instruction but got this error:

[ ERROR ] Both --input_shape and --batch were provided. Please provide only one of them. For more information please refer to Model Optimizer FAQ (/deployment_tools/documentation/docs/MO_FAQ.html), question #56.

I removed the --batch 1 and successfully convert the tensorflow to IR, but eventually I end up with the same error like before

Traceback (most recent call last): File "yolov3_tiny_test.py", line 14, in exec_net = plugin.load(network=net) File "ie_api.pyx", line 395, in openvino.inference_engine.ie_api.IEPlugin.load File "ie_api.pyx", line 406, in openvino.inference_engine.ie_api.IEPlugin.load RuntimeError: [VPU] Internal error: Output in detector/yolo-v3-tiny/pool2_5/MaxPool has incorrect width dimension. Expected: 9 or 9 Actual: 10

PINTO0309 commented 5 years ago

Did you do it at 320 when training? I think it needs to be adjusted when training on Darknet.

cfdcfc commented 5 years ago

I did not train at 320. However, I was able to apply the same trick on normal yolo v3.