Is there any support of fully convolution?
Hi Wonderzy, can you give more information what do you mean by full convolution? Do you mean 2-D convolution for classical image processing? Fully connected Layer convolution layer for CNN?
Yes, I just mean that. @steniu01 Fully connected Layer convolution layer for CNN. How can I use this and how to set the image to the input in this case?
Hi, in the ./examples/neon_cnn.cpp or ./examples/cl_cnn.cpp, you can see how we configured and called FullyConnected Layer. A fully connected layer can take input directly from output of fully connected layer, pooling layer or convolution layer.
Sorry, my fully convolution layer is that, if you configure a convolution layer, for example, a input of 256x256x3. The in the inferece I can put image like 90x90x3 into it. Does this be supported? I just test this but got the wrong answer. I think I should reconfig the convolution shape and the input src shape? @steniu01
Hi @wonderzy , I am bit confused by the terminology :) From what you said in the latest thread, I think you are actually asking fully convolutional network (FCN), i.e a network without fully connected layer? So, if you build a network without adding fully connected layer using our library, yes, you can have different image sizes as input, as long as the input of depth channel same as the fitler's channel and the low 2D input image size is bigger than filter's low 2D. In the current release, we also have provided the NEON 1x1 convolution to support more FCN models. Our library should be able run such network without failing. However, whether the final output match the expectation, I would think it all depends on the model and how well the model has been trained. Since the output of traditional CNN is classifier, I won't expect it could give reasonable result with smaller resolution. Can I ask what model you are building, if it is a published one?
If my understanding of your question is not correct, can you paste the code, the error message thrown by the library with debug build and let me what do you mean by wrong answer?
Hi @steniu01, the point I concern is that how can I use random size to run the inference once I init the network by a max src_image_size, such as 256. in the ./examples/neon_cnn.cpp I got that I can init the src tensor by this:
// Initialize src tensor
constexpr unsigned int width_src_image = 256;
constexpr unsigned int height_src_image = 256;
constexpr unsigned int ifm_src_img = 1;
const TensorShape src_shape(width_src_image, height_src_image, ifm_src_img);
src.allocator()->init(TensorInfo(src_shape, 1, DataType::QS8));
Then I use this to put the random image into the src tensor, when I found that the src tensor size is a const number,
Window input_window;
input_window.use_tensor_dimensions(src.info());
Iterator input_it(&src, input_window);
execute_window_loop(input_window, [&](const Coordinates & id)
{
*reinterpret_cast<int8_t *>(input_it.ptr()) = (src_data[id.z() * (src_width * src_height) + id.y() * src_width + id.x()] - 128);
},
input_it);
Here src_width = src_height = 128, the id index is out of range of the src image. I don't want to resize the src tensor and believe that I can reuse this for performance. If there is something wrong above, please point out that.
Hi Wonderzy, if I understand your question correctly, you want to reuse the memory for different image size without reallocating the memory again? You can try to change the src_shape, weights_shape, bias_shape and out_shape then pass it to the allocator()->init() before calling the function.configure(). Obviously, you don't need to call allocator->allocate() afterwards for the second time run. We have never tried this but it should work in principle. Let me know if you hit problem by doing so.
Emm, that's the point. Then how to do with the next conv layer right after the src layer? Should I also change the shape because this shape is calculated by the first src layer ? Also in my understand I need to do the allocator->init() and function.configure() for each time, right? Meanwhile, will this cost much time?
Yes, you need to re-init all the sub sequential shapes, and yes, you need to call the allocator->init and function.configure() each time. You need to call these anyway when you change the very first input's shape, no matter you reuse the memory or not. Your idea should be able to save the time of memory allocation for the second run but as said, I haven't really tested myself.
It works. Thanks for your patient and I will going to close this. @steniu01 The time looks same.
Thanks to let me know. What time did you measure? Did you only measure the setup time( configure, init, allocation) or measure the overall time. I would expect it could saving the time of memory allocation. Maybe the memory allocation cost is quite small compared to the overall run which hide the improvement?
I tested two versions. One is calling allocation each time, another is calling once then configure and init each time. I measure the overall time (init+configure+allocation+run for former, init+configure+run for later). The result shows that the later version cost just 1/3 time of the former version. So the allocation is so time expensive. The time looks same I said is because I use the fixed src_img size for inferece and test the init+configure+run time.
Cool. Thanks to let us know. In the next one or two release, we would hope provide official support to support reusing the memory ( for both the input/output and the intermediate buffers).