I know this question is already one year old, but it is the most related to what I was looking for. My question applies to the code snippet (process_path()) as cited by @rvh, which is exactly the same in the current notebook.
I am very confused about the creation of the masks; I really wish that was explained a bit more clearly in the notebook.
I have pieced the following together from this post and another one; can you please confirm that this is correct:
- A fourth ‘alpha’ channel has been added at the end of the RGB channels, i.e., to axis 2 of the image. So we have images of dimension (h, w, 4).
- When preprocessing, this fourth channel is simply ignored by setting the
channelsargument intf.image.decode_png()to 3; i.e., this function only looks at the first three channels of the image. (I actually couldn’t find the function in the TF apidocs, but discovered that it has been moved totf.io.decode_png().) - Finally, the max value along the last (-1) axis of the image (i.e., axis 2) is taken for each pixel - meaning the max value of R, G, and B. This is the value that that pixel in the mask will have. But apparently these max values are always stored in the R channel, so the pixel colour will always be some shade of red? (I guess it doesn’t matter whether it’s a shade of R, G, or B - as long as each class has a different colour?)
Is this correct so far?
Then I am also wondering why it is necessary to set keepdims in tf.math.reduce_max() to True. I don’t understand the explanation of that argument in the TF apidocs: “If true, retains reduced dimensions with length 1.”
Thanks!