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

Single Class Conversion : ValueError: cannot reshape array of size 4607 into shape (18,256,1,1) #15

Open ashuezy opened 5 years ago

ashuezy commented 5 years ago

python3 convert_weights_pb.py --class_names /opt/person_detection_yolov3_tiny/obj.names --weights_file weights/yolov3-tiny_obj_80000.weights --data_format NHWC --tiny --output_graph pbmodels/frozen_tiny_yolov3_person_detection.pb Traceback (most recent call last): File "convert_weights_pb.py", line 60, in tf.app.run() File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "convert_weights_pb.py", line 42, in main load_ops = load_weights(tf.global_variables(scope='detector'), FLAGS.weights_file) File "/opt/github2/OpenVINO-YoloV3/utils.py", line 122, in load_weights (shape[3], shape[2], shape[0], shape[1])) ValueError: cannot reshape array of size 4607 into shape (18,256,1,1)

PINTO0309 commented 5 years ago

18x256x1x1 = 4608

NightFury10497 commented 5 years ago

@PINTO0309 how should i use only 1 class of detection using YOLO, I am not able to convert it through Openvino. ./convert_weights_pb.py --class_name coco.names --data_format NHWC --weight_file yolov3.weights Traceback (most recent call last): File "./convert_weights_pb.py", line 52, in tf.app.run() File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "./convert_weights_pb.py", line 42, in main load_ops = load_weights(tf.global_variables(scope='detector'), FLAGS.weights_file) File "/home/night/Desktop/github/tensorflow-yolo-v3/utils.py", line 115, in load_weights (shape[3], shape[2], shape[0], shape[1])) ValueError: cannot reshape array of size 4607 into shape (18,256,1,1) I have trained my own Yolo on just one class, help us find a way out to that.

PINTO0309 commented 5 years ago

@ashuezy @NightFury10497

Have you performed the following link work?

Implementing YOLO v3 in Tensorflow (TF-Slim) https://itnext.io/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe

and, https://github.com/mystic123/tensorflow-yolo-v3/issues/17 https://github.com/mystic123/tensorflow-yolo-v3/issues/15 https://github.com/mystic123/tensorflow-yolo-v3/issues/64

NightFury10497 commented 5 years ago

@PINTO0309 Comand python3 mo_tf.py --input_model /opt/github/tensorflow-yolo-v3/frozen_darknet_yolov3_model.pb --tensorflow_use_custom_operations_config /home/night/Downloads/OpenVINO-YoloV3-master/yolo_v3_changed.json --batch 1 ERROR Model Optimizer version: 1.5.12.49d067a0 [ ERROR ] Cannot infer shapes or values for node "detector/yolo-v3/meshgrid_1/mul_1/YoloRegion". [ ERROR ] index 2 is out of bounds for axis 0 with size 2 [ ERROR ]
[ ERROR ] It can happen due to bug in custom shape infer function <function RegionYoloOp.regionyolo_infer at 0x7fa52ed07268>. [ ERROR ] Or because the node inputs have incorrect values/shapes. [ ERROR ] Or because input shapes are incorrect (embedded to the model or passed via --input_shape). [ ERROR ] Run Model Optimizer with --log_level=DEBUG for more information. [ ERROR ] Stopped shape/value propagation at "detector/yolo-v3/meshgrid_1/mul_1/YoloRegion" node. For more information please refer to Model Optimizer FAQ (/deployment_tools/documentation/docs/MO_FAQ.html), question #38. After I have converted the weights to .PB now while throwing it through optimizer i got this ERROR

PINTO0309 commented 5 years ago

https://qiita.com/PINTO/items/7dd7135085a7249bf17a

ohUMR commented 5 years ago

I got the same reason, and here's how I solve it.

First,check is your environment right.

I trained my weights file on Win 10 at first, after debug, I find the weight size is not equal to the network actually needed, in my case, the size of my one-class weights is 8676243 while the network needs 8676244.

After changing into Ubuntu, I use Ubuntu 18.04(Ubuntu 16.04 should be the same), and retrained my one-class yolov3-tinny model, I use this weights to convert into pb format, it finally works

So check your environment, I advice you train your model on Ubuntu and use tensorflow-gpu V1.12.

Finally, I'd like anyone to tell me why it's different in Windows and Ubuntu, in my guess, it's probably the reason of the value's precision is different in Ubuntu and Windows.

abuzahid commented 4 years ago

This happens for problem in (.names) file. You should check tow things to solve this.

  1. If you are training on all classes please check if there is extra new line at the last of class names.
  2. If you are training on specific some classes please remove the extra class from (.names) file either you used all class names during training.