tensorflow-yolo-v3 icon indicating copy to clipboard operation
tensorflow-yolo-v3 copied to clipboard

cannot reshape array of size 4607 into shape (18,256,1,1)

Open firstxx opened this issue 6 years ago • 18 comments

I convert yolov3.weights to a pb file. It is OK. When I tried to convert a pre-training model, the following errors occurred. The structure of pre-training model is the same as that of yolov3.weight. The only difference is that it has only one class.

Traceback (most recent call last): File "convert_weights_pb.py", line 53, in tf.app.run() File "C:\ProgramData\Anaconda3\envs\fr\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run _sys.exit(main(argv)) File "convert_weights_pb.py", line 43, in main load_ops = load_weights(tf.global_variables(scope='detector'), FLAGS.weights_file) File "D:\codes\converter\tensorflow-yolo-v3\utils.py", line 120, in load_weights (shape[3], shape[2], shape[0], shape[1])) ValueError: cannot reshape array of size 4607 into shape (18,256,1,1)

firstxx avatar Jan 15 '19 10:01 firstxx

Got the Same ISSUE! ./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) @mystic123 I have trained my own Yolo on just one class, help us find a way out to that.

NightFury10497 avatar Feb 01 '19 05:02 NightFury10497

Well I got this issue as well Traceback (most recent call last): File "convert_weights_pb.py", line 52, in tf.app.run() File "C:\Users\bhati\AppData\Local\Programs\Python\Python36\lib\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 "C:\yogita-2\tensorflow-yolo-v3\utils.py", line 115, in load_weights (shape[3], shape[2], shape[0], shape[1])) ValueError: cannot reshape array of size 264248 into shape (256,128,3,3)

Yogita98 avatar Feb 05 '19 20:02 Yogita98

Is there anybody who have solved the problem?

xiayq1 avatar Feb 11 '19 07:02 xiayq1

Change your labels.txt to appropriate length.

karandeepdps avatar Mar 18 '19 12:03 karandeepdps

--class_names

Change your labels.txt to appropriate length.

what's that mean? the process when run convert_weights_pb.py does not require any txt file

karandeepdps avatar Mar 19 '19 11:03 karandeepdps

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.

ohUMR avatar Mar 24 '19 11:03 ohUMR

So some of us have the weights missing 1 float32. Is this related? https://github.com/pjreddie/darknet/issues/497#issuecomment-369269855 The seen may be 32bit or 64bit long.

Could you try reading 32 bits fewer by changing count to 4 in _ = np.fromfile(fp, dtype=np.int32, count=5) in utils? ~I am still having some problem with the set of weights I have, so I would love to see a confirmation that this is a valid fix.~ Just checked, this works for me.

phiSgr avatar Mar 27 '19 19:03 phiSgr

I find the error is because the class_names file, the last line is blank line, delete the blank line , the problom solving

wangluolaowu avatar Apr 12 '19 07:04 wangluolaowu

Could you try reading 32 bits fewer by changing count to 4 in _ = np.fromfile(fp, dtype=np.int32, count=5) in utils?

It didn't work for me..

violet17 avatar Jun 03 '19 09:06 violet17

Changing the count to 4 may fix the issue only if the number is off by one. E.g. 4067 = 18 * 256 - 1 in the title.

phiSgr avatar Jun 03 '19 11:06 phiSgr

I am not sure why the comment of @wangluolaowu has been down voted. It's actually the solution that worked for me.

aditya-vora avatar Jun 06 '19 04:06 aditya-vora

Has anyone that had a correct .names file solved this problem yet? @firstxx @NightFury10497 @Yogita98 I am having the same problem.

stangier avatar Jul 01 '19 15:07 stangier

I have the correct .names and still have the problem. Any idea?

OctaM avatar Oct 07 '19 14:10 OctaM

ValueError: cannot reshape array of size 3072 into shape (18,256,1,1) anyone can help me?

ceciliaAI avatar Dec 09 '19 13:12 ceciliaAI

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.

abuzahid avatar Mar 03 '20 02:03 abuzahid

I had the same issue, turned out I was giving .data file as --names_path - instead of .names file. Giving correct arguments fixed it for me, so make sure that you're giving the right ones.

aleksandreK avatar Mar 13 '20 15:03 aleksandreK

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.

I've tried both. no extra line, all classes present ( 36 ) and still have exception :(

ionutvacariu avatar Apr 13 '20 17:04 ionutvacariu

Convert

_ = np.fromfile(fp, dtype=np.int32, count=5)

to

_ = np.fromfile(fp, dtype=np.int32, count=4)

in utils.py (line 70). It works to me.

7wdeepin avatar Aug 18 '20 12:08 7wdeepin