Darknet: class number issue when converting to Tensorflow model

Created on 27 Feb 2019  路  4Comments  路  Source: AlexeyAB/darknet

Hi alex,
I tried to convert a 5-class weight file trained in this fork to tensorflow model with following repo:
https://github.com/mystic123/tensorflow-yolo-v3/
(It takes weight file and name file, read number of classes from the name file)
However, I got an reshape array size error indicating that it only has 4 classes. (it does compile when i delete one class, but the detection result is not correct in TF)

I tried the same process using weight file trained in PJ's fork, and I do not face to same error.

Would you be able to shed some light on this please ? (it could be issue with their conversion code?). Thanks for your response.

question

Most helpful comment

@arkjiang @cayman1021 Hi,

  • Try to use the latest version of this repository for training. Before Mar 2, 2019 there was an issue with ADAM. More about this issue: https://github.com/AlexeyAB/darknet/issues/2688

  • Check that you set classes= in all [yolo]-layers in cfg-files

  • Check that you obj.names file contains as many lines as classes.


Dunno if I've used Adam optimizer. Probably not.

Yes, there could be a problem with ADAM before. But if you trained your model after Mar 2, 2019 there shouldn't be a problem, this issue is fixed now.

All 4 comments

I tried the same process using weight file trained in PJ's fork, and I do not face to same error.

  • Did you convert successfully your own trained model on PJ's repo or default model yolov3.weights ?

  • Do you use Linux or Windows?

  • Can you rename your cfg-file to txt-file and drag-n-drop it to your message?

  • Did you use Adam optimizer during training?

I tried the same process using weight file trained in PJ's fork, and I do not face to same error.

  • Did you convert successfully your own trained model on PJ's repo or default model yolov3.weights ?

My own trained model in PJ's repo. The conversion reads 5 classes, and didnt complain about dimension.

  • Do you use Linux or Windows?

Linux

  • Can you rename your cfg-file to txt-file and drag-n-drop it to your message?

yolov3_c5.txt

  • Did you use Adam optimizer during training?

No. i didn't.

Greetings Alex,

I got the same problem here. The messages are shown below:

D:\MyProjects\tensorflow-yolo-v3>python convert_weights_pb.py --class_names my_model.names --data_format NHWC --weights_file my_model.weights --tiny

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

WARNING:tensorflow:From C:\Users\User\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Traceback (most recent call last):
  File "convert_weights_pb.py", line 52, in <module>
    tf.app.run()
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-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 "D:\MyProjects\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)
  1. Using the same Python code to run on PJ's coco.names and yolov3-tiny.weights works without any problem, too.
  2. Only modify the number of the classes (only 1) and the filter (which is 18 according to your guide) in the *.cfg file. Didn't change any CNN structure settings inside.
    yolov3_tiny.txt
  3. Tried on both Windows and Ubuntu.
  4. I'm not sure whether if the problem is on the weight file because my version is much earlier (synced more than 6 months ago from your GitHub).
  5. Dunno if I've used Adam optimizer. Probably not.

@arkjiang @cayman1021 Hi,

  • Try to use the latest version of this repository for training. Before Mar 2, 2019 there was an issue with ADAM. More about this issue: https://github.com/AlexeyAB/darknet/issues/2688

  • Check that you set classes= in all [yolo]-layers in cfg-files

  • Check that you obj.names file contains as many lines as classes.


Dunno if I've used Adam optimizer. Probably not.

Yes, there could be a problem with ADAM before. But if you trained your model after Mar 2, 2019 there shouldn't be a problem, this issue is fixed now.

Was this page helpful?
0 / 5 - 0 ratings