YOLO is not reading correctly the training data

Hello everybody,

I am training a YOLO algoriths (yolo26n-seg.pt) to detec blastocysts, an early embryo development stage, in photos. However, I am facing some trouble on the training process.

I labeled the images in ROBOFLOW with Instance segmentation tools and exported the labels in .TXT files.

At the end of the training process, yolo provides some files as output, some of them are images with mosaics of the training batch and the validation batch. Here starts my problem. I noticed that in these images the labels do not fit exactly on the top of the structure I labeled in the image, in fact it leaks a bit to the side. This pathern also happens in the predicted imagens, where there are some leak of mask in the direction of the locating box.

I tried to change some paramethers on the training script, but nothing changed.

Could someone help me to identify why is it happening and how to solve this problem?

Exemple of mosaic with validation_labels . All images in this mosaic have masks larger than the embryo. the same happens with train emages. I expected to have masks fitting perfectly on the top of the embryos in the training and validation data.

This is probably because the objects are small. You can try increasing imgsz like using imgsz=1280

And during prediction use retina_masks=True

Thank you for your help. You advice helped me a lot.

My images are 5120 x 2880, a huge size for training. Adjusting the image size and activating the function retina improved the quality of the masks for training and validation set.

I still have one question. Even improving the quality of masks, the images labeled by prediction display a weird leak of the mask in the direction of the locating box. Do you know if it is normal for YOLO predicted images or do I still have a problem?

Here is an example of a image of a blstocyst correctly covered by te mask, but on the areas close to the locating box it has a extension that toutchs it. At the end, the mask is not completly round due to this extension.

Does this occur with retina_masks=True during prediction?

Yes. This is my code for the last trainig I did:

model.train(data = caminho_yaml,

        augment = True,

        project = r'/content/drive/MyDrive/Pseudo-labeling-piloto',

        classes = \[4\],

        name ='pseudo_labiling_piloto_rect_true12',

        degrees = 180.0,

        perspective = 0.0,

        shear = 0.0,

        flipud = 0.0,

        fliplr = 0.0,

        mosaic = 0.0,

        mixup = 0.3,

        scale = 0.0,

        patience = 50,

        optimizer ='AdamW',

        lr0 = 0.001,

        weight_decay = 0.01,

        epochs = 100,

        imgsz = \[1920,

        rect = True,

        retina_masks = True,

        batch = 4,

        )

retina_masks=True is for prediction. You use it with model.predict()

Thank you a lot for your sugestion, it helped a lot.

Now the prediction is much better.

One more question, don’t you recommend to use retina_masks on training?

Here an example showing the improvement on prediction using retina_masks = True. The image on the right is the one with retina_masks = True.

Training shouldn’t be affected with retina_masks. It’s applied during prediction

Ok, thank you again for your help.

You’re welcome — glad it helped.

And yes, that’s correct: retina_masks=True is a prediction/rendering option, not a training option. In the segmentation predictor reference it’s used when constructing inference masks, and in the mask plotting code reference it controls high-resolution mask drawing. So it won’t improve model.train() results directly.

For your case, just keep using it in prediction like:

results = model.predict(source=img, retina_masks=True)

With large images and small round objects like blastocysts, that’s the right approach.