I removed the alpha channel from the masks and save the mask files in a new “CameraMaskNoAlpha” subdirectory, like this:
for mask_img in mask_file:
mask = imageio.imread(mask_path + mask_img)
plt.imsave("./data/CameraMaskNoAlpha/" + mask_img, mask[:, :, 0])
I updated the mask_list_ds
and masks_filenames
vars to point to this subdirectory.
I then ran this notebook, but the fit() method gives NaN for the loss and 0.00 for accuracy:
model_history = unet.fit(train_dataset, epochs=EPOCHS)
(TensorSpec(shape=(96, 128, 3), dtype=tf.float32, name=None), TensorSpec(shape=(96, 128, 1), dtype=tf.uint8, name=None))
Epoch 1/40
34/34 [==============================] - 17s 508ms/step - loss: nan - accuracy: 0.0000e+00
Epoch 2/40
34/34 [==============================] - 4s 105ms/step - loss: nan - accuracy: 0.0000e+00
Epoch 3/40
34/34 [==============================] - 4s 104ms/step - loss: nan - accuracy: 0.0000e+00
So maybe the apha channel is getting used somewhere? Without this change, my notebook runs fine.
Also, what does the tf.math.reduce_max() in the following method do?
def process_path(image_path, mask_path):
img = tf.io.read_file(image_path)
img = tf.image.decode_png(img, channels=3)
img = tf.image.convert_image_dtype(img, tf.float32)
mask = tf.io.read_file(mask_path)
mask = tf.image.decode_png(mask, channels=3)
mask = tf.math.reduce_max(mask, axis=-1, keepdims=True)
return img, mask