U-Net Error: InvalidArgumentError: Graph execution error

Hi there,

I’m using a base code for image segmentation using U-Net and I’m adapting it because my images are in grayscale and the reference code uses RGB images. Link: python_for_microscopists/216_mito_unet__xferlearn_12_training_images.py at master · bnsreenu/python_for_microscopists · GitHub

However, when fit the model, it is giving this error

Code:

model = sm.Unet(BACKBONE, encoder_weights=‘imagenet’)
model.compile(‘Adam’, loss=sm.losses.bce_jaccard_loss, metrics=[sm.metrics.iou_score])
print(model.summary())

history = model.fit(my_generator, validation_data=validation_datagen, steps_per_epoch=50, validation_steps=50, epochs=50)

Error:

Epoch 1/50

InvalidArgumentError Traceback (most recent call last)
in
----> 1 history = model.fit(my_generator, validation_data=validation_datagen, steps_per_epoch=50, validation_steps=50, epochs=50)

1 frames
/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
56 try:
57 ctx.ensure_initialized()
—> 58 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
59 inputs, attrs, num_outputs)
60 except core._NotOkStatusException as e:

InvalidArgumentError: scale must have the same number of elements as the channels of x, got 3 and 1
[[node model_4/bn_data/FusedBatchNormV3
(defined at /usr/local/lib/python3.8/dist-packages/keras/layers/normalization/batch_normalization.py:589)
]] [Op:__inference_train_function_24050]

Errors may have originated from an input operation.
Input Source operations connected to node model_4/bn_data/FusedBatchNormV3:
In[0] IteratorGetNext (defined at /usr/local/lib/python3.8/dist-packages/keras/engine/training.py:866)
In[1] model_4/bn_data/scale:
In[2] model_4/bn_data/ReadVariableOp:
In[3] model_4/bn_data/FusedBatchNormV3/ReadVariableOp:
In[4] model_4/bn_data/FusedBatchNormV3/ReadVariableOp_1:

I’m new in this area I’m using it for my master’s degree, if you can help I’m very grateful.
Thank you in advance!

Hi i am trying to do image masking using unet if you have found the solution for the above problem do share