ModelDepot / tfjs-yolo-tiny

In-Browser Object Detection using Tiny YOLO on Tensorflow.js
https://modeldepot.io/mikeshi/tiny-yolo-in-javascript
MIT License
530 stars 92 forks source link

Custom Object detection not working #19

Closed nirmalaagash closed 6 years ago

nirmalaagash commented 6 years ago

Hi,

I had trained my yolo-tiny-v2 with my dataset of 2 classes(width and height being 416). Also, converted the final .weights file to keras using YAD2K converter. And then used tensorflowjs converter to convert it to web model which resulted in model.json file along with shard files.

Coming to the code in tfjs-yolo-tiny-demo repo I have successfully passed the uploaded json file url in model = await downloadModel(url); Also the options in yolo function - const boxes = await yolo(inputImage, model,{numClasses:2, classNames :['X1','X2']});

Output is empty array.

What changes do I have to make.Please guide me in making my custom detection compatible to yours.

MikeShi42 commented 6 years ago

Have you tested the model in darknet/keras to see if it detects in those environments?

It's pretty hard to debug errors in the processing code in this lib for a model, but one thing you can do is look at the intermediate tensors and see if they're funny values like NaN or 0's

nirmalaagash commented 6 years ago

I checked it. it is working fine. It predicted those two classes with >90% prediction.

I'll check through what you mentioned. But have I missed any steps in between?

MikeShi42 commented 6 years ago

I guess it's possible that the inputImage isn't in the right format, how are you feeding in the input?

nirmalaagash commented 6 years ago

const inputImage = webcam.capture();

passing the image taken directly from the webcam

MikeShi42 commented 6 years ago

Have you tried feeding in an image directly? You can do so by instead of targeting a video element, to use an image element when constructing the webcam object. I imagine it's possible that the model is overfitting to images that you're passing in but not recognizing webcam quality images. Alternatively, you can try testing webcam images on your model in darknet/keras.

Otherwise you'll probably have to dig into inspecting the tensors in this lib itself for the culprit, but it can be tricky unless there is obvious 0s/NaNs. Another sanity check might be if the default pretrained model work in your setup or not, there could be some weird tfjs dependency error going on that's happened in the past (but hopefully have fixed by now).

nirmalaagash commented 6 years ago

Alternatively, you can try testing webcam images on your model in darknet/keras.

Approached the above said. Model seems to work fine with the webcam images. Maybe I'll try doing the conversion again.

Last time while converting to keras, parameter "buffer" buffer=weights_file.read(filters * 4)) in the convolution function in yad2k.py was giving out the error

TypeError: buffer is too small for requested array when reading file

  Hence I removed that parameter and converted it without any error. Could this be the issue?

MikeShi42 commented 6 years ago

It's been a while since I had to deal with it, but have you seen this comment? https://github.com/allanzelener/YAD2K/issues/83#issuecomment-364649222

That could definitely be a problem.

nirmalaagash commented 6 years ago

It is working now. Thanks @MikeShi42

MikeShi42 commented 6 years ago

That's great, could you share the problem/solution for future reference?

nirmalaagash commented 6 years ago

I changed weights_file.read(16)) to weights_file.read(20)) in yad2k.py. Previously it was weights_file.read(16)). Then it worked fine.