Now I’m trying to create channels-first semantic segmentation model of 2D U-Net with tensorflow v2.5.
Learning phase can run, but the accuracy remains very low (it’s about 0.001-).
I could get high accuracy by channels-last (about 0.9-).
What should I have to confirm ?
— info —
Input shape: (None, 1, 256, 256)
Output shape: (None, 5, 256, 256)
class num: 5
loss : mse
This is an old introduction to the channels-first/channels-last features:
You can convert data between channels-first and channels-last with a ‘permute dims’ tensor call. This can be done with a Lambda layer.
Thank you for your reply.
I checked above link. I had already done everything I had to do.
Though I’ve already build channel-first model architecture, how do I have to use “Permute dims” ?
I do not know about using a channels_first architecture. All of the Keras models support it.
But, channels_last is the “native” format of the API, and you are better off using it.
tf.transpose() does an n-dimensional transpose of the input data.
For 2D data, this turns channels_first into channels_last:
tf.transpose(data, perm=[1, 2, 0])
It shifts the 2D data from (1,2) to (0,1) and moves the channel from (0) to (2).
If you use Keras, a Lambda layer with this will do what you need. This should probably be a built-in convenience layer in Keras.
Thank you for your support.
I found the reason why the accuracy was low with channel-first.
- tensorflow’s metrics of categorical_accuracy which can be get from “model.compile(metrics=[‘acc’])” is only for axis -1.
So I changed axis to 1, then I could same high accuracy as channel-last network.