ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

failure in configuration of fully connected layer

Open joel-mi opened this issue 9 years ago • 12 comments

I'm trying to configure a fully connected layer, to be activated after a Max Pool layer, and its failing in NEGEMMMatrixMultiplyKernel::configure, on : ARM_COMPUTE_ERROR_ON(input0->info()->dimension(0) != input1->info()->dimension(1))

Input tensor for Max Pool layer is configured as 8x8x120, output tensor - as 4x4x120 Max Pool layer's output tensor is used as Fully Connected layer's input tensor Fully Connected layer's weight tensor is configured as 4x4x120x120 (4D tensor) Fully Connected layer's bias tensor is 1D tensor, of size 120 Fully Connected layer's output tensor is configured as 1x1x120

joel-mi avatar May 08 '17 10:05 joel-mi

Hello @joel-mi,

Our implementation of fully connected layer simulates the "legacy" connected layer. What you are doing is performing a convolution fully connected layer, which our fully connected layer will not handle properly. Either you can use the ConvolutionLayer if you want to do something like this or flatten your weights to a 2D matrix [1920,120] and change your output to [120]. It depends on your model which solution is better. It is strange that you didn't take an error that you weights are not two-dimensional.

Have a look here to check how FullyConnected layer works.

GeorgeARM avatar May 08 '17 11:05 GeorgeARM

Hello George So it seems that fully connected layer works only with 2D tensor for weights ? That's also what the documentation says, I guess it has been updated recently because a couple of weeks ago it said that either 2D or 4D tensors could be used (depends if it follows another convolution layer or not). Maybe there were also changes in NEFullyConnectedLayer recently ? In the version I'm using, there are only 4 parameters for configure function (bool transpose_weights is missing) - am I working with an outdated version ? Do I have to update it for correct operation of Fully Connected ?

What I actually tried is your first suggestion - working with NEConvolutionLayer for performing the operation as I configured it; but it failed exactly as it did for configuring NEFullyConnectedLayer, in the same function and same ARM_COMPUTE_ERROR_ON (it is actually executing the same code, with Boolean _is_fc == TRUE). What is wrong with my configuration of NEConvolutionLayer ? I'm using the same configuration as described above for NEFullyConnectedLayer, and in addition PadStrideInfo (1, 1, 0, 0); perhaps some other setting is needed for PadStrideInfo ?

joel-mi avatar May 08 '17 14:05 joel-mi

Hello @joel-mi,

Can you please update to the latest version and try again?

GeorgeARM avatar May 08 '17 14:05 GeorgeARM

Sure Do you suggest that I try again with NEConvolutionLayer ? And the same settings as before (also for PadStrideInfo = (1, 1, 0, 0)) ?

joel-mi avatar May 08 '17 14:05 joel-mi

Hi @joel-mi ,

yes it is correct, the NEFullyConnectedLayer has been updated and has an extra (optional) argument for transposing the weights of your layer (transpose_weights). By default, transpose_weights = true so it tranposes your weights. As George said, could you try your test with the new release and evaluate if the NEFullyConnectedLayer works as expected? You can try also to disable the transpose_weights.

Thanks

gmiodice avatar May 09 '17 07:05 gmiodice

Can you please help me with the setting of tensors when using either NEFullyConnectedLayer or NEConvolutionLayer for implementing the "fully connected" convolution that I'm concerned about ?

  1. NEConvolutionLayer :
  • input is 4x4x120 --> 3D input tensor set to (4, 4, 120)
  • output is 1x1x120 --> 3D output tensor set to (1, 1, 120)
  • weights - kernel size = 4 --> 4D tensor set to (4, 4, 120, 120)
  • bias : 1D tensor of size 120
  • how to set PadStrideInfo ? is (1, 1, 0, 0) OK ?
  1. NEFullyConnectedLayer :
  • 3D input tensor set to (4, 4, 120) ?
  • 3D output tensor set to (1, 1, 120) ?
  • must be 2D tensor, how to set it ?
  • bias : 1D tensor of size 120

joel-mi avatar May 09 '17 10:05 joel-mi

@GeorgeARM Do you have any suggestions about how to configure either NEFullyConnectedLayer or NEConvolutionLayer for implementing the "fully connected" convolution according to my needs ? I first tried NEFullyConnectedLayer with the following settings : input tensor : (4, 4, 120) weights tensor : (1920, 120) output tensor : (1, 120) There was no crash in NEFullyConnectedLayer::configure, but the layer's output was totally wrong. All other attempts I made for configuring this layer - such as setting output tensor to (120, 1), for instance, ended up with a crash in NEFullyConnectedLayer::configure.

I then tried NEConvolution layers with the settings above (see my previous post) and it failed during configuration, due to the following error, in NEGEMMMatrixMultiplyKernel::configure : if(output->info()->dimension(1) == 1) { ARM_COMPUTE_ERROR_ON(input0->info()->dimension(0) != input1->info()->dimension(1)); } from what I can see, the tensors sizes have the following values at this stage : input0 : _num_dimensions = 3, dimension(0) = 7684, dimension(1) = 1, dimension(2) = 1 input1 : _num_dimensions = 2, dimension(0) = 7684, dimension(1) = 30 output : _num_dimensions = 3, dimension(0) = 120, dimension(1) = 1, dimension(2) = 1

What am I doing wrong ?

joel-mi avatar May 22 '17 15:05 joel-mi

@gmiodice Please see my question to George above

joel-mi avatar May 22 '17 15:05 joel-mi

Hello @joel-mi ,

Unfortunately, it seems to be an issue with the Convolution layer when trying to create a "fully connected" convolution layer, it has been identified and will be fixed for the next release. On the other hand I would expect the FullyConnectedLayer to work as expected if you pass an input of size (4x4x120), weights of size (1920,120) and output of size (120).

GeorgeARM avatar May 22 '17 17:05 GeorgeARM

@GeorgeARM That's right, FullyConnectedLayer works fine now ! The mistake I made was trying to configure output tensor as a 2-D tensor, now I understand that I had to configure it as a 1-D tensor

joel-mi avatar May 23 '17 11:05 joel-mi

Glad to hear @joel-mi . Will mark this issue as a bug in order to fix the Convolution Layer as well.

GeorgeARM avatar May 23 '17 12:05 GeorgeARM

This was fixed in the latest release (17.06). Closing. Reopen if you face the same issue again.

GeorgeARM avatar Jul 03 '17 09:07 GeorgeARM