qqwweee / keras-yolo3

A Keras implementation of YOLOv3 (Tensorflow backend)
MIT License
7.14k stars 3.45k forks source link

Inference using tfjs with a custom trained YOLOv3 model #746

Open tngan opened 3 years ago

tngan commented 3 years ago

Model trained with custom data (using train.py) will introduce two extra inputs. When I use tfjs to do inference, the error Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 3 Tensor(s), but instead got 1 Tensors(s). shows.

image

When I use the pretrained yolov3 model (yolo.h5 generated via convert.py). It only has one input and two outputs, and I can get tfjs working well with it.

image

Is it possible to deploy the model with same architecture as the pretrained yolo.h5 ?

clarkdong commented 3 years ago

I have trained a custom Yolo-V3-tiny model with 2 classes (final filter size is 21). My custom darknet model works well in darknet, but when converted to keras it no longer detects (like reported by others here).

I dug into it more, and found that the final stage of the converted keras model had additional weights....21 extra to be precise. Below is from the model.summary()....

        stage                 output     weights              from

conv2d_9 (Conv2D) (-,-,-, 21) 10773 lky_re_lu_8[0][0] << 26 x 26 x 21...expects 10,752 conv2d_12 (Conv2D) (-,-,-, 21) 5397 lky_re_lu_10[0][0] << 13 x 13 x 21...expects 5,376

NOTE the covd2d_9 layer should have 10,752 weights, because wt = input size1 size2 output => 512 x 1 x 1 x 21. The converted version has 10,773 because I believe it did 513 x 1 x 1 x 21.....Which looks like to be a bug? Similarly the math for the 13 x13 output stage (conv2d_12) is 256 x 1 x 1 x 21 = 5376. And the converted was 257 x 1 x 1 x 21 = 5397. Both are off by 21, which is one EXTRA INPUT*. Why?

I am digging into the code to see what caused the bug and there is quite a bit of learning curve, I suspect a side effect with the vector math somewhere, and I hope somebody smarter can figure this out.

robertokcanale commented 3 years ago

Following this! This seems like a very serious point

ChukkanakalPooja commented 3 years ago

I too have the same problem, yolo weights predicts result but converted keras model does not predict any result. Any solution?