mystic123 / tensorflow-yolo-v3

Implementation of YOLO v3 object detector in Tensorflow (TF-Slim)
https://medium.com/@pawekapica_31302/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe
Apache License 2.0
890 stars 353 forks source link

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

Open iBralic opened 5 years ago

iBralic commented 5 years ago

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

tomafischer commented 5 years ago

I have the exact same issue. Same configuration.

iBralic commented 5 years ago

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.

dkashkin commented 5 years ago

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?

Mi-zo-re commented 5 years ago

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.

skynomadism commented 5 years ago

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])
Ajaz-Ahmad commented 5 years ago

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

lmcltj commented 4 years ago

it works for me ,thks

LucasMahieu commented 3 years ago

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

PrashantDixit0 commented 2 years ago

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..