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

ValueError: cannot reshape array of size 1091 into shape (85)

Open iBralic opened this issue 5 years ago • 9 comments

I cloned your repository and tried running the demo. I got the following error:

Traceback (most recent call last):
  File "./demo.py", line 101, in <module>
    tf.app.run()
  File "/home/ivan/virtual_environments/tensorflow-cpu/lib/python3.5/site- packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "./demo.py", line 92, in main
    iou_threshold=FLAGS.iou_threshold)
  File "/home/ivan/tensorflow-yolo-v3/utils.py", line 191, in non_max_suppression
    image_pred = image_pred.reshape(-1, shape[-1])
ValueError: cannot reshape array of size 1091 into shape (85)

I ran the demo on Tensorflow cpu version. I dowloaded the coco.names and yolov3.weights files. Then I ran the following commands:
python ./convert_weights.py --data_format NHWC
python ./convert_weights_pb.py --data_format NHWC
python ./demo.py --input_img ./dog.jpg --output_img ./pred_dog.jpg --frozen_model ./frozen_darknet_yolov3_model.pb --data_format NHWC
the dog image in 3rd command was the same one that was used in yolov3 tutorial on darknet yolo website found here The weights conversion went fine, and frozen model was generated fine but demo.py gave the error. I suspect this has something to do with data format and me using NHWC instead of NCHW but I'm not sure. I'd like to hear your opinion and hopefully you can run some tests to see if there is bug in implementation or did I do something wrong.
I used Tensorflow 1.13 (cpu version)
Ubuntu 16.04 (on virtual machine)
Python 3.5

iBralic avatar Apr 05 '19 07:04 iBralic

I have the exact same issue. Same configuration.

tomafischer avatar Apr 10 '19 00:04 tomafischer

Hi tomafischer,
when I tried running this model on Intel Neural Compute Stick 2 I had issues with Tensorflow 1.13 incorrectly turning the model into the frozen representation. When I downgraded to Tensorflow 1.12 I managed to get it working. I'm not sure if this is guaranteed to help, but I would definitely try to downgrade Tensorflow and give it a try, you have nothing to lose. Good luck.

iBralic avatar Apr 10 '19 06:04 iBralic

I bumped into the same problem in several different configurations:

  1. Tensorflow 1.13.1 and 1.14.1
  2. data_format: NCHW and NHWC
  3. Model size: tiny and full
  4. demo execution with Frozen graph and Checkpoint @mystic123 can you please help us out?

dkashkin avatar May 06 '19 16:05 dkashkin

The owner may try to find out all lines that only contains 0, so he use np.nonzero, which makes error and causes this this value error. My classmate and i try in this way: do the sum to each line and find out the indexes of those which results are not equal to 0, and make them to a new array. Here's the code temp = image_pred sum_t = np.sum(temp, axis=1) non_zero_idx = sum_t != 0 image_pred = image_pred[non_zero_idx, :] then we can use the demo.

Mi-zo-re avatar May 10 '19 09:05 Mi-zo-re

Modify utils.py:

for i, image_pred in enumerate(predictions):

    shape = image_pred.shape
    #non_zero_idxs = np.nonzero(image_pred)
    #image_pred = image_pred[non_zero_idxs]
    temp = image_pred
    sum_t = np.sum(temp, axis=1)
    non_zero_idx = sum_t != 0
    image_pred = image_pred[non_zero_idx, :]
    image_pred = image_pred.reshape(-1, shape[-1])

skynomadism avatar Jul 30 '19 15:07 skynomadism

Hello everyone,

Did you guys solved the issue? I am facing a challenge in deploying my model to movidius stick and getting following error: 4056=13x13x3x8 (yolo network) ValueError: cannot reshape array of size 4056 into shape (1,1,1)

any help is appreciated. thanks

Ajaz-Ahmad avatar Aug 07 '19 03:08 Ajaz-Ahmad

it works for me ,thks

lmcltj avatar Apr 28 '20 14:04 lmcltj

Seems related to pull request here : https://github.com/mystic123/tensorflow-yolo-v3/pull/105

LucasMahieu avatar Apr 16 '21 12:04 LucasMahieu

Modify utils.py:

for i, image_pred in enumerate(predictions):

    shape = image_pred.shape
    #non_zero_idxs = np.nonzero(image_pred)
    #image_pred = image_pred[non_zero_idxs]
    temp = image_pred
    sum_t = np.sum(temp, axis=1)
    non_zero_idx = sum_t != 0
    image_pred = image_pred[non_zero_idx, :]
    image_pred = image_pred.reshape(-1, shape[-1])

This worked for me..

PrashantDixit0 avatar Nov 16 '21 13:11 PrashantDixit0