nn-transfer icon indicating copy to clipboard operation
nn-transfer copied to clipboard

image_data_format('channels_last')

Open birdyalex opened this issue 6 years ago • 1 comments

Hi Guido,

it looks like all Keras->Pytorch examples provided with the package are for the case of "channels_first" image data format. I have been struggling to make it work for the case of "channels_last" format (default tensorflow behaviour). But I can't figure out how to handle one specific case.

I modified a little bit the example notebook and put it here for clarity (https://github.com/birdyalex/nn-transfer/blob/master/example_channels_last.ipynb).

The Keras->Pytorch conversion works fine if the number of out-channels before flattening equals 1 (the latest block of conv/pool just before FC-layers). But when one increases the number of channels to 2+ something starts to go wrong. I included a variable NUM_OUT_CHANNEL_BEFORE_FLATTENING in the begging of the notebook which controls how many channels should the network have.

It looks like the concatenation-by-channel pattern (Keras' Flatten() vs. Pytorch .view()) differs between these two frameworks. Do you have any idea what can cause such a behaviour and maybe a way how to handle it?

birdyalex avatar Jun 02 '18 15:06 birdyalex

Also want to know how to deal with the "channels_last" format~

KLH1472 avatar Nov 12 '18 10:11 KLH1472