WePCf / darknet-mobilenet-v2

Darknet for MobileNet v2
Other
80 stars 27 forks source link

why do these in load_image_stb #3

Open azuryl opened 5 years ago

azuryl commented 5 years ago

//For MobileNet v2 for(k = 0; k < c; ++k){ for(j = 0; j < h; ++j){ for(i = 0; i < w; ++i){ if (k==0) { int dst_index = i + wj + wh(k+2); int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-123.68)0.017; } if (k==1) { int dst_index = i + wj + whk; int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-116.78)0.017; } if (k==2) { int dst_index = i + wj + wh(k-2); int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-103.94)*0.017; } } } }

WePCf commented 5 years ago

This was inherited from original Caffe's preprocessing method. Just image normalization.

azuryl commented 5 years ago

thank you I have converted Squeezenet 1.1 caffe model to darknet format and use the method as you used , you can download from https://github.com/azuryl/squeezenet-darknet-model

WePCf commented 5 years ago

First I would say it's a really nice work. But may I ask have you tested the model on darknet? I tried to use "predict" to see some images' results, however, the results were all wrong.

Could you please show more details, for example, the normalization method or "synset.labels.list" or "imagenet.labels.list"?

azuryl commented 5 years ago

classes=1000 train = /data/imagenet/imagenet1k.train.list valid = squeezenet/inet.val.list backup = /home/pjreddie/backup/

labels = data/imagenet.labels.list

labels = squeezenet/synsets.labels.list names = data/imagenet.shortnames.list top=5

the inet.val.list is created by youself

./darknet classifier predict squeezenet/imagenet1k.data squeezenet/squeezenet.cfg squeezenet/squeezenet_darknetformat.weights data/eagle.jpg 9 layer filters size input output 0 conv 64 3 x 3 / 2 227 x 227 x 3 -> 113 x 113 x 64 1 max 3 x 3 / 2 113 x 113 x 64 -> 57 x 57 x 64 2 conv 16 1 x 1 / 1 57 x 57 x 64 -> 57 x 57 x 16 3 conv 64 1 x 1 / 1 57 x 57 x 16 -> 57 x 57 x 64 4 route 2 5 conv 64 3 x 3 / 1 57 x 57 x 16 -> 57 x 57 x 64 6 route 3 5 7 conv 16 1 x 1 / 1 57 x 57 x 128 -> 57 x 57 x 16 8 conv 64 1 x 1 / 1 57 x 57 x 16 -> 57 x 57 x 64 9 route 7 10 conv 64 3 x 3 / 1 57 x 57 x 16 -> 57 x 57 x 64 11 route 8 10 12 max 3 x 3 / 2 57 x 57 x 128 -> 29 x 29 x 128 13 conv 32 1 x 1 / 1 29 x 29 x 128 -> 29 x 29 x 32 14 conv 128 1 x 1 / 1 29 x 29 x 32 -> 29 x 29 x 128 15 route 13 16 conv 128 3 x 3 / 1 29 x 29 x 32 -> 29 x 29 x 128 17 route 14 16 18 conv 32 1 x 1 / 1 29 x 29 x 256 -> 29 x 29 x 32 19 conv 128 1 x 1 / 1 29 x 29 x 32 -> 29 x 29 x 128 20 route 18 21 conv 128 3 x 3 / 1 29 x 29 x 32 -> 29 x 29 x 128 22 route 19 21 23 max 3 x 3 / 2 29 x 29 x 256 -> 15 x 15 x 256 24 conv 48 1 x 1 / 1 15 x 15 x 256 -> 15 x 15 x 48 25 conv 192 1 x 1 / 1 15 x 15 x 48 -> 15 x 15 x 192 26 route 24 27 conv 192 3 x 3 / 1 15 x 15 x 48 -> 15 x 15 x 192 28 route 25 27 29 conv 48 1 x 1 / 1 15 x 15 x 384 -> 15 x 15 x 48 30 conv 192 1 x 1 / 1 15 x 15 x 48 -> 15 x 15 x 192 31 route 29 32 conv 192 3 x 3 / 1 15 x 15 x 48 -> 15 x 15 x 192 33 route 30 32 34 conv 64 1 x 1 / 1 15 x 15 x 384 -> 15 x 15 x 64 35 conv 256 1 x 1 / 1 15 x 15 x 64 -> 15 x 15 x 256 36 route 34 37 conv 256 3 x 3 / 1 15 x 15 x 64 -> 15 x 15 x 256 38 route 35 37 39 conv 64 1 x 1 / 1 15 x 15 x 512 -> 15 x 15 x 64 40 conv 256 1 x 1 / 1 15 x 15 x 64 -> 15 x 15 x 256 41 route 39 42 conv 256 3 x 3 / 1 15 x 15 x 64 -> 15 x 15 x 256 43 route 40 42 44 dropout p = 0.50 115200 -> 115200 45 conv 1000 1 x 1 / 1 15 x 15 x 512 -> 15 x 15 x1000 46 avg 15 x 15 x1000 -> 1000 47 softmax 1000 48 cost 1000 Loading weights from squeezenet/squeezenet_darknetformat.weights...

predictions:0.000000 data/eagle.jpg: Predicted in 0.598544 seconds. 30.64%: bald eagle 19.15%: ruddy turnstone 14.06%: kite 8.25%: dowitcher 3.65%: vulture

azuryl commented 5 years ago

you need to change image load_image_stb_squeezenet(char filename, int channels) { int w, h, c; unsigned char data = stbi_load(filename, &w, &h, &c, channels); if (!data) { fprintf(stderr, "Cannot load image!!!!!!!!!!!! "%s"\nSTB Reason: %s\n", filename, stbi_failure_reason()); exit(0); image im; im.data=0; return im; } if(channels) c = channels; int i,j,k; image im = make_image(w, h, c);

//For Squeezenet for(k = 0; k < c; ++k){ for(j = 0; j < h; ++j){ for(i = 0; i < w; ++i){ if (k==0) { int dst_index = i + wj + wh(k+2); int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-123); } if (k==1) { int dst_index = i + wj + whk; int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-117); } if (k==2) { int dst_index = i + wj + wh(k-2); int src_index = k + ci + cwj; im.data[dst_index] = ((float)data[src_index]-104); } } } }

free(data); return im;