KhronosGroup / NNEF-Tools

The NNEF Tools repository contains tools to generate and consume NNEF documents
https://www.khronos.org/nnef
222 stars 57 forks source link

conversion of inception v2 depthwise multiplier #69

Closed jnorwood closed 5 years ago

jnorwood commented 5 years ago

the inception v2 model has an initial depthwise convolution with a multiplier of 8. Reading your spec, it wasn't clear to me how to do this conversion, but I did find your answer in another post here. I'd suggest you add that explanation to the spec since the inception networks are one of the few that are currently available as quantized implementation in tflite form. I've confirmed that my v1 and v3 quantized tflite inception translations to nnef are correct, btw. v2 is incorrect due to this depthwise multiplier not being handled.

" That is almost correct, in case 2, groups == input tensor channel, which is in most cases == output tensor channel, but output tensor channel may be an integer multiple of input tensor channel, if there is a so called channel multiplier (if the filter has multiple planes for each input plane)".

gyenesvi commented 5 years ago

Well, there is an explanation of channel multiplier in the spec, in the paragraph for Grouped Convolutions (section 4.3.1). How would you rephrase that to be more informative?

jnorwood commented 5 years ago

The statement that "output tensor channel may be an integer multiple of input tensor channel, if there is a so called channel multiplier (if the filter has multiple planes for each input plane)", It wasn't clear to me that groups parameter needs to be set to out_C when out_C is a greater than 1 integer multiple of in_c. in order to make it explicit that the conv operation is a depthwise convolution with a multiplier.

gyenesvi commented 5 years ago

No, the groups parameter has to be set to in_c or (preferably) 0 to make it a depthwise convolution. And that has nothing to do with whether there is a 'channel' multiplier. You could have a 'group' multiplier even if it is not a depthwise convolution, but otherwise grouped convolution.

So basically the number of output channels is always equal to the number of filters (batch dim of filters). The constraint is that the groups times the filter channels must equal the input channels, and that the groups must divide the number of filters. The rest is just a consequence of special cases, such as groups being equal to number of input channels, or the number of filters being equal to the input channels.

jnorwood commented 5 years ago

Ok, that helps. I misunderstood C to be output channels and c to be input channels in the spec description, which is why I labeled them out_C and in_c in my post.

In that case, no change is required in my tflite_to_nnef conversion ... it is already putting out 0 for groups in this case for inception v2.
This link has a cmake script that will download the four inception and two mobilenet models that I've converted.
https://github.com/jnorwood/NNEF-Tools/tree/master/contrib/converters/tflite_converters/tflite_to_nnef

jnorwood commented 5 years ago

strange that if I click on that link it doesn't go to my branch, but if I copy and paste it, it works. Is that some github restriction?