YAD2K icon indicating copy to clipboard operation
YAD2K copied to clipboard

Not detecting using custom model

Open filipetrocadoferreira opened this issue 6 years ago • 17 comments

I trained my own detector using original darknet code.

It works nice on the original code, when i'm trying to convert to yad2k format using the tutorial in the homepage I get :

None
Saved Keras model to object_yolo.h5
Read 67111984 of 67111985.0 from Darknet weights.
Warning: 1.0 unused weights

The truth is that the code runs ok but no detection is generated. All the outputs come empty

filipetrocadoferreira avatar Aug 25 '17 15:08 filipetrocadoferreira

I'm also checking that box_confidence out of yolo_head comes all zeros.

Can these be related to different number of classes (N=11?)

filipetrocadoferreira avatar Aug 25 '17 16:08 filipetrocadoferreira

Ok. Solved

Just change line 85 in yad2k.py:


weights_header = np.ndarray(
        shape=(4, ), dtype='int32', buffer=weights_file.read(20))

.read(16) - > .read(20)

filipetrocadoferreira avatar Aug 27 '17 08:08 filipetrocadoferreira

However the results are not the same.

https://github.com/pjreddie/darknet/issues/78

filipetrocadoferreira avatar Aug 27 '17 10:08 filipetrocadoferreira

Did you ever get more info on this? How does the number of classes influence the buffer size?

I get the converter to work fine with the standard weights from https://pjreddie.com/darknet/. But after training my own model in darknet and converting it to keras nothing can be found (with test_yolo.py).

Converting my darknet model to a .pb with darkflow works perfectly for our Android and Windows classifiers. But I'm looking to implement it in iOS with CoreML. Converting the darknet model to keras is a step in that proces. So currently I'm investigating how I could change the code in this converter to work with my own cfg file. Any advice is appreciated.

richard-giantrobot avatar Sep 11 '17 14:09 richard-giantrobot

I also trained darknet with tiny-yolo-voc configuration for only one object. It works before conversion and detects the objects as expected but I cannot get it to work after conversion to h5. I see that in the scripts there are fixed 20 objects, I tried to change these to my own object but didn't work. Did anybody solve how to make this work with a custom object? I'm trying to get the detection to work on iOS and this is one step for it.

sarpsolakoglu avatar Sep 14 '17 21:09 sarpsolakoglu

Have the same issue..

[convolutional]
size=1
stride=1
pad=1
filters=30
activation=linear
[region]
anchors = 1.08,1.19,  3.42,4.41,  6.63,11.38,  9.42,5.11,  16.62,10.52
bias_match=1
classes=1
coords=4
num=5
softmax=1
jitter=.2
rescore=1

after conversion to .h5 with yad2k.py have no detections at all. Original darknet works fine. @allanzelener can you please help to find the way how to solve this?

.weights and .cfg available by link below: https://drive.google.com/file/d/0B9JMtVL5s0N0VThkUDVwSmFISnM/view?usp=sharing

img_0738 predictions 1

ededovets avatar Sep 15 '17 02:09 ededovets

I have the same issue do you guys have any solution please update :(

oishi89 avatar Sep 19 '17 08:09 oishi89

I had the same problem with the conversion from darknet to keras that did not work. The solution to modify yad2k.py from @filipetrocadoferreira worked for me

weights_header = np.ndarray(
        shape=(4, ), dtype='int32', buffer=weights_file.read(20))

yannviellard avatar Sep 20 '17 07:09 yannviellard

@yannviellard that change gives me:

Traceback (most recent call last):
  File "yad2k.py", line 270, in <module>
    _main(parser.parse_args())
  File "yad2k.py", line 156, in _main
    buffer=weights_file.read(weights_size * 4))
TypeError: buffer is too small for requested array

Error.

sarpsolakoglu avatar Sep 20 '17 22:09 sarpsolakoglu

@yannviellard @filipetrocadoferreira I got the same issue after changing weights_header = np.ndarray( shape=(4, ), dtype='int32', buffer=weights_file.read(20)) I'm planing to re training my model using retrain_yolo.py but don't know how to create data_path like "path to numpy data file (.npz) containing np.object array 'boxes' and np.uint8 array 'images'" I'm a newbie in python please help

oishi89 avatar Sep 20 '17 22:09 oishi89

@oishi89 Did you try the following: creat a directory called DATA and placing the .npz and .txt files inside. Then in the retrain_yolo.py script change lines 29 and 35 to the right .npz and txt file names.

yochananscharf avatar Sep 27 '17 11:09 yochananscharf

@yochananscharf I don't know how to convert my dataset into .npz template could you help

oishi89 avatar Oct 03 '17 06:10 oishi89

I suggest you see this link https://github.com/hollance/YOLO-CoreML-MPSNNGraph/issues/7 As answer say , YoloModel convert to Tensorflow ,use it. Or you want coreml, you can convert tf to coreml (offical). not through Keras!! My advise

michaeldong avatar Jan 04 '18 07:01 michaeldong

To be exact the complete fix would be:

weights_header = np.ndarray(
        shape=(4, ), dtype='int32', buffer=weights_file.read(12))
if weights_header[0] > 0 or weights_header[1] > 1:
    weights_file.read(8)
else:
    weights_file.read(4)

Reason being that in version 0.2.0 of the darknet weight format the seen field was changed from uint32 to uint64.

iiroka avatar Jan 09 '18 08:01 iiroka

@iiroka - Exaclty! Here's the snippet from parser.c in Darknet: int major = 0; int minor = 2; int revision = 0; fwrite(&major, sizeof(int), 1, fp); fwrite(&minor, sizeof(int), 1, fp); fwrite(&revision, sizeof(int), 1, fp); fwrite(net->seen, sizeof(size_t), 1, fp); size_t is usually 64-bit nowadays.

tgandor avatar Feb 06 '19 22:02 tgandor

So finally, I'd rather do it like this:

    weights_header = np.ndarray(shape=(3,), dtype='int32', buffer=weights_file.read(12))
    if weights_header[0] > 0 or weights_header[1] > 1:
        seen = np.ndarray(shape=(1,), dtype='int64', buffer=weights_file.read(8))
    else:
        seen = np.ndarray(shape=(1,), dtype='int32', buffer=weights_file.read(4))
    print('Weights Header: ', weights_header, 'seen', seen)

(3 elements for version header, then parse seen separately)

tgandor avatar Feb 06 '19 22:02 tgandor

So finally, I'd rather do it like this:

    weights_header = np.ndarray(shape=(3,), dtype='int32', buffer=weights_file.read(12))
    if weights_header[0] > 0 or weights_header[1] > 1:
        seen = np.ndarray(shape=(1,), dtype='int64', buffer=weights_file.read(8))
    else:
        seen = np.ndarray(shape=(1,), dtype='int32', buffer=weights_file.read(4))
    print('Weights Header: ', weights_header, 'seen', seen)

(3 elements for version header, then parse seen separately)

for god's sake! man!!!! Your change is so good !! I have been torturing by this problem for like a whole day, xxing 24hours! You are my savior!

ikaroso avatar Apr 16 '21 11:04 ikaroso