liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.08k stars 1.71k forks source link

ccv_convnet_encode assertion error #163

Closed genekogan closed 8 years ago

genekogan commented 8 years ago

Great project!

I am trying to encode a single image using ccv_convnet_encode but getting assertion errors that I haven't figured out how to solve.

ccv_enable_default_cache();
string imagenet = "image-net-2012.sqlite3";
convnet = ccv_convnet_read(0, imagenet.c_str());

ccv_dense_matrix_t* a = 0;
ccv_convnet_input_formation(convnet->input, &image, &a);   
ccv_dense_matrix_t** b = 0;
ccv_convnet_encode(convnet, &input, b, 1);

which fails with this assertion:

Assertion failed: ((*a)->rows == convnet->rows), function ccv_convnet_encode, file ccv_convnet.c, line 648.

Am I misusing the encode function? Is there an example somewhere of this being done?

liuliu commented 8 years ago

What's input in your code? Why it is not simply a?

liuliu commented 8 years ago

Also, the encode size required to be the input size of the network (227x227), which could be different from the normal input size for classification (255x255) check the dimension first and see how ccv_convnet_encode is used in ccv_convnet_classify

genekogan commented 8 years ago

ah sorry that was a typo, it was &a in my code, not &input. yes thank you! the input size was the issue. i was able to get it to run successfully with:

ccv_dense_matrix_t* a = 0;
ccv_size_t size = ccv_size(225, 225);
ccv_convnet_input_formation(size, &image, &a);
ccv_dense_matrix_t* b = 0;
ccv_convnet_encode(convnet, &a, &b, 1);

i'm a bit unclear on how to interpret the result. b is now a 1000x1 matrix. are these the final activations of the 1000 output classes? does it make sense to use this as a compact representation of the image, or perhaps the layer before the outputs is better?

liuliu commented 8 years ago

Yes, it is the final activations for the last 1000 output classes. You should just the layer before this as compact representation of the image.

genekogan commented 8 years ago

thanks!