Cannot batch tensors with different shapes in component 0. First element had shape [224,224,3] and element 2 had shape [224,224,4]

Hello thanks for looking up my querry, may god bless you
I was trying the segmentation code (i.e camvid problem)

When i tried it with my own dataset i wasn’t able to train the model, it was showing an error,
The error was,

I don’t know what to do please help me

Thanks,
Rohit

Hi there,

Thw error basically says there is shape mismatch images. It should be something with the image processing i guess.

Thanks for picking my thread up, may god bless you,

Yeah I overcame the error but the when i tried to display the masks with the images it was showing some weird stuff, It was totally blue I couldn’t see any thing.

I was trying to do a binary examples, where we could segment the human from an image

Just like these,

But when I loaded the images with the masks it was showing me weird things

Like these

Please help me out, I need to learn this skill, Please,

Thanks,

Rohit Kumar

In some image formats (e.g. png), there is an alpha channel in addition to the R, G and B color channels, which is used for masking or “alpha blending”. If your input images have 4 channels, but your model is written to expect just RGB, then you just need to strip off the alpha channel. If you print the values for a few of your pixels, it should be clear which is alpha. Typically it has a constant value like 0 or 255. Just do something like:

image3 = image4[:,:,0:2]

In a loop.

2 Likes

Obviously you have to understand the lab process in order to replicate it. From the blue part I think the model is not learning the right things, maybe you need to change the dense output classification layer to fit your case, also the loss you are using depends on the classification problem (accuracy too). What images are using to train the model and setting of the number of bounding boxes…and so on.

No it wasn’t predicted by the model, I manually displayed the image along with the masks, The image was on the left side and the mask was (i.e the blue image) on the left side,

I don’t know what the mistake is on the images .

I took the dataset from kaggle,

Link :- Human Segmentation MADS Dataset, 1192 images | Kaggle

I used the images along with the masks folder,

Thanks,
Rohit

I just want to know how can i load any custom dataset so I can process it to the model

The first step is that you need to understand what the new dataset contains. What is the format of the data? What are the labels? E.g. in this particular case, what are the “masks” for and do you need them for whatever your purpose is?

What is the format that your model requires? Do you need to preprocess the input data in some way to get it into the format you need?

1 Like

Thanks for replying sir,

Yes I was trying to do the segmentation task as provided in the tensorflow advanvced course specialization,

The mask is indeed needed for the segmentation,

The model was working fine, when I tried to display the images the masked images were not properly displayed.

It had to show the masked images just like these corresponding to the original image,

But it was showing like this,

It was showing blue color, don’t know why

Please help me
Rohit

Did you print the shapes the images? I’ll bet that they have 4 channels. This is what I said before: in PNG format, they support the added “alpha” channel to express “transparency”. Try googling “png alpha channel”. If you find that the images have 4 channels, then I gave you a suggestion earlier for eliminating the alpha channel. Did you actually read what I said? The other way to accomplish that would be to convert the images to JPEG format first: JPEG does not support “alpha”. Try googling “convert png to jpg python”.

But the overall point is what I said in my second reply above: you have to start by understanding your data. What is the format? What does it mean? You need to develop the skills to do that kind of analysis. Follow the types of suggestions I gave above: just do a google search for something like “png image format” and start reading.