Reputation: 471
What is the code for changing whether the network expects channels to be first or last? I know you can put it in the layer itself, but do I have to write data_format='channels_last'
every time? I can somewhat remember there being an easier way, but I've forgotten, and thus my question.
This is a way of doing it, however:
model = tf.keras.Sequential([tf.keras.layers.Conv2D(1,(3,3),data_format="channels_last")])
Upvotes: 2
Views: 861
Reputation: 801
For versions tensorflow>=2.2.0, it is set "channels_first" (NCHW) by default. We can easily change to "channels_last" (NHWC) by
tf.keras.backend.set_image_data_format('channels_last')
ref: https://www.tensorflow.org/api_docs/python/tf/keras/backend/set_image_data_format
Upvotes: 2