# DLS Course 4 - Week 3: U-Net Image Segmentation Assignment

**URL:** <https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590>\
**Category:** Convolutional Neural Networks\
**Tags:** coursera-platform\
**Created:** [November 14, 2022, 4:23pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590 "2022-11-14T16:23:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Turo](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/turo/32/28252_2.png) [@Turo](https://community.deeplearning.ai/u/Turo)\
**Post date:** [November 14, 2022, 4:23pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590/1 "2022-11-14T16:23:18Z")

</div>

Hi All!

I’m referring to subsection 2.2 of the Image Segmentation assignment, where in the definition of the process\_path function there’s a line whose purpose I don’t understand:

mask = tf.math.reduce\_max(mask, axis=-1, keepdims=True)

What exactly are we trying to achieve here? I am trying to have this U-Net implementation working with a different dataset (consisting in png images with 3 channels instead of 4 like in the assignment), but something goes wrong here.

Any help would be appreciated!

Cheers!

Turo

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [November 14, 2022, 5:14pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590/2 "2022-11-14T17:14:07Z")

</div>

Look at the shape of `mask` before and after that statement. It turns out that the inputs here are PNG files and they have 4 channels: RGBA. But for the `mask` values, only one of the channels has a non-zero value. So that `reduce_max` just gives you one output channel with the actual mask value.

If your data is in some other format like JPEG your mileage may vary, although even if your masks are prepared in advance with only one channel to hold the mask value, that logic will do no harm. Other than wasting some computation and creating some potential confusion. 🤓

---

<div class="post-metadata">

**Author:** ![Turo](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/turo/32/28252_2.png) [@Turo](https://community.deeplearning.ai/u/Turo)\
**Post date:** [November 14, 2022, 5:51pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590/3 "2022-11-14T17:51:35Z")

</div>

Oh, I see, thank you! So in case we’re working with a dataset where the masks are defined over 3 RGB channels, would it make sense to set the previous line as:

msk = tf.image.decode\_png(msk, channels = 1)

in order to have one grey-scale channel for the masks? Or do I have to adapt the architecture to the masks I’m using?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [November 14, 2022, 6:03pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590/4 "2022-11-14T18:03:53Z")

</div>

Yes, it looks like that would work, but you might want to try it and make sure it does the same thing as the `reduce_max` logic that was shown. Just to make sure their definition of greyscale doesn’t involve any other transformations. You want the mask values to be the “labels” for the types of objects in the image, right? So they should be predefined integer index values.

You can look through how the masks are handled in the rest of the code. It appears that they are handled as one channel images everywhere. Of course the point is you want to train your model to produce those masks as output.

I should say that I have no expertise or experience here beyond what they show us in this notebook. Note that training such a network is going to be computationally expensive.

---

<div class="post-metadata">

**Author:** ![Turo](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/turo/32/28252_2.png) [@Turo](https://community.deeplearning.ai/u/Turo)\
**Post date:** [November 14, 2022, 6:25pm UTC](https://community.deeplearning.ai/t/dls-course-4-week-3-u-net-image-segmentation-assignment/230590/5 "2022-11-14T18:25:40Z")

</div>

Doing so seems to do the trick, but the performance is rather poor. I’ll have a look into what’s the problem! Again, thank you!
