Clean ENet Keras

Currently looking at this keras tensorflow enet implementation:

What exactly are these lines doing?

The first permute is changing tf’s default [Batch#, Y, X, Channel] and turning it into [Batch#, Y, Channel, X]. The last permute is reversing that operation back to [Batch#, Y, X, Channel]. The pad_featmaps line is looking at the difference in channels (features) between input and output. And then the zeropadding is just ensuring that the output is zero-padded (on the right hand side) up to the desired number of features?

I’m guessing the reason they did this is because zeropadding works on pixel data, so pretend X,Channel are pixels?

Finally, how might one get this code to work in keras over theano, considering TensorVariable objects have no attribute ‘get_shape’? And using inp.shape returns the useless Shape.0 value?

Thank you so much @all.

Hey everyone. While messing around with other code on a completely different problem, I found the answer to this. Hope this helps someone else in the future. In K2, you can use:

K.int_shape(x)

To get the shape of your tensor variable, which will be returned to you in the proper image_data_format, as described by your keras.json file, irrespective of tf or th backend. =)

So in my case, I got back: (None, Batch, h, w) which was exactly what was needed!

1 Like