Getting error while running YOLO on my PC

Hello !

I completed CNN course several month ago and now would like to run it on my own. I saved the workspace earlier, but the .h5 model file was broken so I had to download weight and convert it to .h5 manually.

I have a problem while trying to run a predict function on a test image and getting the following error:

InvalidArgumentError: Shapes of all inputs must match: values[0].shape = [1,19,19,255] != values[1].shape = [1,38,38,255] [Op:Pack] name: packed

which partly point to this part of code:

InvalidArgumentError Traceback (most recent call last)
/tmp/ipykernel_4667/1640018199.py in
----> 1 out_scores, out_boxes, out_classes = predict(“test.jpg”)

/tmp/ipykernel_4667/1712354711.py in predict(image_file)
18
19 yolo_model_outputs = yolo_model(image_data)
—> 20 yolo_outputs = yolo_head(yolo_model_outputs, anchors, len(class_names))
21 print(image.size)
22

I had a look on functions that can be related to that issue, but I don’t see where could be the problem.

Could you please help me with that?

P.S.: maybe it is related to the fact that I used yolo v3 weight not v2 ?

i haven’t read v3 code, but I know it does image sampling at multiple resolutions, and 38 is 2x 19, which is suspicious. I would be shocked if you could directly load weights trained on a v3 network into a v2 model. The network is an entirely different entity: different shapes, different use of anchor boxes, etc.

1 Like

Hello @ai_curious , thanks for your thought !

Here is a piece of model summary. Shapes look quite weird…

Some clues about viability of v3->v2 transfer learning I found here from the author of the YOLO papers:

2.3. Predictions Across Scales
YOLOv3 predicts boxes at 3 different scales. Our system extracts features from those scales using a similar concept to feature pyramid networks [8]. From our base feature extractor we add several convolutional layers…In our experiments with COCO [10] we predict 3 boxes at each scale so the tensor is N ×N ×[3∗(4+1+80)], for the 4 bounding box offsets, 1 objectness prediction, and 80 class predictions.


2.4. Feature Extractor
We use a new network for performing feature extraction. Our new network is a hybrid approach between the network used in YOLOv2, Darknet-19, and that newfangled residual network stuff. Our network uses successive 3 × 3 and 1 × 1 convolutional layers but now has some shortcut connections as well and is significantly larger. It has 53 convolutional layers …

2 Likes

V2 had 19 Convolutional layers plus some skip connection voodoo, so I think v3 weights will never work with a v2 model. I am trying to train a v2 at home right now but it is not going flawlessly. Or quickly. Two steps forward, then a big one back…

1 Like

I see… so this particular notebook (assignment) was done for yolo v3 ?

Woow, why it suddenly goes up at 25th epoch ?

here’s the associated coordinate loss graph…

not pretty.

yes it is v2 indeed, then no wonder why code does not work…

I am trying to convert now weight for v2 into .h5.

Thank you very much for your help!

1 Like

I just tried with yolo v2, I have a following error now:

ValueError: bad marshal data (unknown type code)

any ideas ? :slight_smile:

Haven’t seen it myself since i am training my own rather than loading pre-trained. But looks like others have…

yep I saw this link already. it looks like there is a problem with the compatibility between keras and tf.
Could you please tell which versions do you have ?

  1. that thread was hijacked with a few different scenarios, but my takeaway was the problem was related to differences in python version, not Keras or tf. Though maybe all three.

  2. regardless, it doesn’t matter what i am running since i am building everything myself. I think instead what matters is that you replicate the environment from which the model/weights file was created. For the record, i am developing in python 3.7.10, tensorflow 2.0.0, and Keras 2.2.4

1 Like