0
$\begingroup$

I trying to replicate the semantic segmentation example https://keras.io/examples/vision/oxford_pets_image_segmentation/ but train on my own data. I have 8 labels (7 features + background). My images are 775 by 770 pixels.

I changed num_classes to 8, img_size to (775,770) (and changed the input and target directories), otherwise I run the example code exactly. When I fit the model, I get the following error:

ValueError                                Traceback (most recent call last)
Cell In[32], line 14
     12 # Train the model, doing validation at the end of each epoch.
     13 epochs = 50
---> 14 model.fit(
     15     train_dataset,
     16     epochs=epochs,
     17     validation_data=valid_dataset,
     18     callbacks=callbacks,
     19     verbose=2,
     20 )
ValueError: in user code:
ValueError: Shapes (None, 775, 770, 1) and (None, 784, 784, 8) are incompatible

The model's final output shape is (None, 784, 784, 8).

This is my first foray into neural networks, and I am hoping to learn about functionality and architecture from this example. Explicit instructions, e.g., of the form "You should one-hot encode your labels, do this by..." would be most helpful.

Where am I going wrong? What else should I change in the model to match the size of my inputs and the number of classes?

$\endgroup$

1 Answer 1

0
$\begingroup$

The issue comes from the fact that a max pooling operation is applied to downsample at each level of the U-Net. When the your input is not divisible by two the resulting array after max pooling will have a different shape than the residual layer, and as a result the two cannot be concatenated together. The easiest way to solve this would probably be to simply reshape your inputs to reshape your inputs to (784, 784).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.