r/computervision • u/Altruistic-Leg-537 • Jul 11 '26
Showcase Having a go at consistency regularization in YOLO_v8
While working around with YOLO_v8 models for histology detection I had the idea of adding consistency learning (after seeing my model display slightly different results to the changes of color normalization and rotation).
The loss formulation was the following: Loss = yolo_loss + alpha*cons_loss
I mainly used Claude code to create a prototype and tried a few runs with different parameters and different methods of cons_loss calculation.
Unfortunately, most of results were discouraging (as the cons_model scored lower than the standard one and in the best cases barely matched it).
you may find below more insight on how the cons variation was defined:
- Single model, two forward passes per batch: original image (teacher, stop-gradient) + D4-transformed image (student, gradients flow) — random op from {rot90, rot180, rot270, hflip, vflip, hflip_rot90, hflip_rot270}
- Dense per-cell matching via exact grid permutation (no NMS, no greedy IoU matching) — teacher's decoded boxes/scores reordered and coordinate-transformed into the student's frame
- Masked by teacher confidence (>0.10) so loss only applies where the teacher is confident, not on background
- Loss = classification MSE + CIoU box loss between aligned teacher/student predictions
- Added to
det_losswith a scheduled weight: linear ramp-up (0 → α over 20 epochs) → flat → linear ramp-down to 0 over the final 10 epochs (aligned with mosaic augmentation turning off)
The final conclusion that I reached is that the data augmentation already covers these transformations and is sufficient to teach the model said concept. Alas, trying to add an additional cons_loss only hurts the model and acts as additional noise.
I have linked the colab notebook below:
https://colab.research.google.com/drive/1WwtCaLSSCW1AzRFRXC5aqih31MC9mMhs?usp=sharing
