Τεχνικός ΟΔΗΓΟΣ

Mixup και CutMix Augmentation

Mixup and CutMix are data augmentation techniques that train a neural network on blends of two examples instead of single ones.

Ακούστε αυτόν τον οδηγόαφήγηση με AI · ~8 min

Σε αυτήν τη σελίδα9 min read
  1. Επισκόπηση
  2. Βασικά takeaways
  3. Βαθιά κατάδυση
  4. Mixing one CIFAR-10 batch by hand
  5. Υλοποίηση σε πραγματικό κόσμο
  6. The Future of Mixup and CutMix Augmentation
  7. Κάνοντάς το στην πράξη
  8. Πηγές και περαιτέρω ανάγνωση
  9. Συνεχίστε την εξερεύνηση
  10. Συχνές ερωτήσεις

Επισκόπηση

Mixup averages two whole images and their labels; CutMix pastes a rectangle from one image onto another and mixes labels by area. Both cost almost nothing to add, reduce overfitting, and are standard in modern image classifier training recipes.

Βασικά takeaways

  1. Mixup trains on weighted averages of two images and their labels, with the mixing weight drawn from a Beta distribution controlled by alpha.
  2. CutMix pastes a random rectangle from one image onto another and sets the label weights in proportion to each image's visible area.
  3. In the CutMix paper, ResNet-50 ImageNet top-1 error fell from 23.68% to 21.40%, better than both Cutout and mixup in the same comparison.
  4. The mixup authors found alpha between 0.1 and 0.4 helped on ImageNet while larger values caused underfitting, so alpha needs tuning.
  5. Both methods add negligible compute because they mix examples already in the current batch, and torchvision ships ready-made MixUp and CutMix transforms.

Βαθιά κατάδυση

Data augmentation creates new training examples from existing ones so a model sees more variety and memorizes less. Classic image augmentations transform one picture at a time: flip it, crop it, shift its colors. Mixup and CutMix take a different approach and combine two pictures, along with their labels, into one training example. The label is no longer a single class but a weighted mix, such as 60% dog and 40% cat. This encourages the network to make smooth, proportionate predictions rather than overconfident ones.

Mixup was introduced by Hongyi Zhang of MIT with Moustapha Cisse, Yann Dauphin and David Lopez-Paz of Facebook AI Research in "mixup: Beyond Empirical Risk Minimization" (arXiv October 2017, ICLR 2018). Empirical risk minimization (ERM) is the standard practice of minimizing average loss on the training examples themselves. Mixup instead trains on points in between examples. The procedure has four steps. First, draw a random mixing weight lambda from a Beta distribution with parameter alpha. Second, take two random training examples, often a batch and a shuffled copy of the same batch. Third, form the new input as lambda times the first input plus one minus lambda times the second. Fourth, form the new label the same way from the two one-hot label vectors, and train on that pair with ordinary cross-entropy loss. The authors note it takes a few lines of code and adds minimal computation.

The mixup paper reported gains across several domains. On ImageNet-2012, with 1.3 million training images in 1,000 classes, top-1 error for ResNet-50 trained for 200 epochs fell from 23.6% to 22.1%, and for ResNet-101 from 22.0% to 20.8%. The authors found that alpha between 0.1 and 0.4 helped on ImageNet while larger alpha caused underfitting, and that bigger models and longer training benefited most. They also showed mixup reduced memorization of deliberately corrupted labels, improved robustness to adversarial examples, and stabilized the training of generative adversarial networks.

CutMix came from Sangdoo Yun and colleagues at Naver's Clova AI Research and was published at ICCV 2019. It addressed a weakness the authors saw in two earlier methods. Cutout, from 2017, erases a random square of an image, forcing the model to look beyond the most obvious feature, but wastes those pixels. Mixup uses every pixel, but blended images look unnatural and locally ambiguous, and the CutMix paper reports that mixup lowered weakly supervised localization accuracy on ImageNet and object detection performance after transfer. CutMix replaces the erased rectangle with the matching patch from a second image and sets the label weights in proportion to the area each image occupies. The rectangle's size is drawn from the same Beta distribution, with alpha set to 1 so the area ratio is uniform between 0 and 1, and its position is drawn uniformly.

CutMix's results were strong across tasks. On ImageNet with ResNet-50, top-1 error fell from 23.68% to 21.40%, against 22.93% for Cutout, 22.58% for mixup and 22.50% for Manifold Mixup, a variant that mixes hidden-layer features. ResNet-101 improved by 1.70 percentage points. On CIFAR-100 it reached 14.47% top-1 error, a state-of-the-art result at the time. The paper also reported better weakly supervised object localization, gains when the pretrained network was fine-tuned for detection and captioning, improved robustness and reduced overconfidence.

Compared with alternatives, the two methods complement single-image augmentations rather than replacing them. Flips, crops and color jitter teach invariance to transformations of one image. Cutout and random erasing teach the model to use partial evidence. Mixup and CutMix additionally soften labels in a data-dependent way, which is related to label smoothing, a technique that replaces hard one-hot targets with slightly softened ones; the mixup paper's ablations found mixup beat combinations of input mixing and label smoothing. In practice, training recipes often apply both: libraries such as torchvision provide CutMix and MixUp transforms that can be randomly alternated per batch, and the DeiT recipe for vision transformers used both together with RandAugment and random erasing.

The methods have trade-offs. Because labels become fractional, training accuracy is no longer directly comparable to the usual metric, and the mixup authors found that longer training runs and larger models benefited most, so gains may be small on short schedules. Too strong a mix underfits, which is why alpha is tuned. Mixed images are not realistic, so mixup can hurt tasks that depend on precise spatial evidence, as the CutMix paper's localization and detection numbers show for mixup. CutMix can paste a patch that contains none of the second image's object, such as a patch of background, while the label still assigns that class weight in proportion to area. Both assume label mixing is meaningful, which is natural for classification but needs care for tasks such as segmentation or detection.

The cost is minimal. Both methods operate on a batch already in memory and add only a few tensor operations and a random draw per batch, so training time barely changes; the CutMix authors describe the overhead as negligible. The real cost is tuning: choosing alpha, the probability of applying each method, and the number of training epochs. Labels must be represented as probability vectors over classes rather than integer class indices, which torchvision's transforms handle by converting labels to a batch size by number of classes tensor.

04Δουλευμένο παράδειγμα

Mixing one CIFAR-10 batch by hand

  1. Load a batch of 8 CIFAR-10 images of size 32 by 32 with their integer labels, and convert labels to one-hot vectors of length 10.

  2. Create a shuffled copy of the batch by applying a random permutation, so each image is paired with another image from the same batch.

  3. For mixup, sample lambda from Beta(0.2, 0.2), say 0.7, and compute 0.7 times each image plus 0.3 times its partner, and the same weighting for the labels.

  4. For CutMix, sample lambda from Beta(1, 1), say 0.75, giving a box of side 32 times sqrt(0.25), or 16 pixels, at a random center.

  5. Paste that 16 by 16 region from each partner image into the original, clip it at the border, and recompute lambda as 1 minus the pasted area divided by 1,024.

  6. Display both mixed batches with their soft labels and feed either one to a model trained with cross-entropy on soft targets.

Αυτό που δείχνει

You get two augmented batches: blended, ghost-like images labeled for example 0.7 airplane and 0.3 ship, and patched images whose label weights equal the visible areas. Check correctness by confirming each soft label sums to 1 and that the CutMix weight matches the fraction of pixels from each source image.

Υλοποίηση σε πραγματικό κόσμο

On ImageNet, the original 2017 mixup paper reduced ResNeXt-101 32x4d top-1 error from 21.3% to 20.1% when training for 200 epochs, using a blending strength alpha of 0.4.

CutMix (ICCV 2019) cut ResNet-50's ImageNet top-1 error from 23.68% to 21.40%, beating Cutout at 22.93% and mixup at 22.58% in the same comparison.

Models pretrained with CutMix transferred better to other tasks: the CutMix authors report about 1 mAP gain on Pascal VOC object detection and 2 BLEU points on MS-COCO image captioning.

Facebook AI's DeiT recipe for training vision transformers on ImageNet alone (2021) includes both mixup and CutMix and notes that these regularizers improve performance.

Mixup is not limited to images: its authors also applied it to the Google Speech Commands dataset of 65,000 one-second spoken commands and to tabular UCI datasets.

The Future of Mixup and CutMix Augmentation

Since 2019, research has produced many mixing variants. Manifold Mixup mixes hidden-layer features rather than pixels, and the CutMix paper itself tested a feature-level CutMix that scored 21.80% top-1 error on ImageNet against 21.40% for pixel CutMix. Transformer-era recipes such as DeiT (2021) combine mixup and CutMix with other augmentations such as RandAugment and random erasing. Open questions remain about why and when mixing works. Mixed labels interact with calibration, how well predicted probabilities match real accuracy; the CutMix authors reported reduced overconfidence, and how far that holds across models and datasets is still studied. Extending label mixing to dense tasks like segmentation and detection, to text, and to multimodal models requires deciding what a mixed label should mean. As training increasingly uses very large datasets and self-supervised pretraining, the relative value of mixing augmentations compared with simply adding more data is an active area of study, and practical guidance still relies heavily on tuning per task.

Κάνοντάς το στην πράξη

Γιατί έχει σημασία

  • Κόστος και προϋπολογισμός. Οι αποφάσεις για την αρχιτεκτονική καθορίζουν την απόδοση και το λειτουργικό κόστος για χρόνια.
  • Σαφέστερες αποφάσεις. Η τεχνική εκπαίδευση βοηθά τις ομάδες να επιλέξουν τη σωστή στοίβα, όχι μόνο τη νεότερη.
  • Ελεγχος ποιότητας. Οι καλύτερες επιλογές μηχανικής μειώνουν τα περιστατικά αξιοπιστίας στην παραγωγή.

Προσέξτε

  • Η βελτιστοποίηση ενός σημείου αναφοράς μπορεί να κρύψει ευρύτερες αδυναμίες του συστήματος.
  • Το κόστος υποδομής και συντήρησης συχνά υποτιμάται.
  • Τα κενά ασφάλειας και παρατηρητικότητας μπορούν να αυξηθούν καθώς τα συστήματα γίνονται πιο πολύπλοκα.

Επόμενα βήματα

  1. Καθορίστε τους στόχους καθυστέρησης, ποιότητας και κόστους πριν από την εφαρμογή.
  2. Σημείο αναφοράς υπό ρεαλιστικές συνθήκες φορτίου και δεδομένων.
  3. Παρακολούθηση οργάνου για σφάλματα, μετατόπιση και επιπτώσεις από τον χρήστη.
  4. Προετοιμάστε διαδρομές επαναφοράς και απόκρισης συμβάντος πριν την κλιμάκωση.

Πηγές και περαιτέρω ανάγνωση

  1. arXiv (ICLR 2018)mixup: Beyond Empirical Risk Minimization
  2. arXiv (ICCV 2019)CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features
  3. arXivTraining data-efficient image transformers and distillation through attention
  4. PyTorch torchvision documentationHow to use CutMix and MixUp

Συνεχίστε την εξερεύνηση

Δωρεάν ενημερωτικό δελτίο

Λάβετε την καθημερινή ενημέρωση AI

Τρία επαληθευμένα νέα AI κάθε πρωί της εβδομάδας, γραμμένα σε απλή αγγλική. Δωρεάν για πάντα, χωρίς διαφημίσεις.

Ένα email κάθε εργάσιμη ημέρα. Κατάργηση συνδρομής με ένα κλικ. Δεν πουλάμε ή μοιραζόμαστε ποτέ τη διεύθυνσή σας.

Δοκιμάστε τον εαυτό σας

Take the Mixup and CutMix Augmentation quiz

Άμεση ανάδραση σε κάθε απάντηση, και πιστοποιητικό με επαληθεύσιμο ID μόλις περάσετε το μάθημα.

Έναρξη κουίζ

Υποστηρίξτε τη δωρεάν εκπαίδευση AI. AI Understanding είναι μια μη κερδοσκοπική οργάνωση 501(c)(3) — χωρίς διαφημίσεις, χωρίς τοίχο πληρωμής, ποτέ. Κάντε μια δωρεά

Συχνές ερωτήσεις

Τι είναι το Mixup και το CutMix Augmentation;

Mixup and CutMix are data augmentation techniques that train a neural network on blends of two examples instead of single ones. Mixup averages two whole images and their labels; CutMix pastes a rectangle from one image onto another and mixes labels by area. Both cost almost nothing to add, reduce overfitting, and are standard in modern image classifier training recipes.

Πώς δημιουργεί το Mixup ένα νέο παράδειγμα εκπαίδευσης;

Η μίξη σχηματίζει x̃ = λx_a + (1−λ)x_b και αναμιγνύει τις ετικέτες με το ίδιο λ που προέρχεται από μια κατανομή Beta.

Ποια είναι η βασική διαφορά μεταξύ CutMix και Mixup;

Το CutMix αντιγράφει μια ορθογώνια περιοχή από μια εικόνα σε μια άλλη, διατηρώντας τοπικά συνεκτικό περιεχόμενο αντί να δημιουργεί δύο εικόνες μαζί.

Στο CutMix, πώς προσδιορίζεται το βάρος ανάμειξης (λάμδα) για τις ετικέτες;

Η αναλογία ετικετών στο CutMix ορίζεται από την περιοχή του επικολλημένου πλαισίου σε σχέση με ολόκληρη την εικόνα, διατηρώντας τις ετικέτες συνεπείς με τα ορατά pixel.

Εκτός από την εικόνα εισόδου, τι άλλο τροποποιούν το Mixup και το CutMix;

Και οι δύο μέθοδοι αναμειγνύουν τις ετικέτες, δημιουργώντας μαλακούς στόχους που λειτουργούν σαν μια μορφή εξομάλυνσης ετικετών που εξαρτάται από τα δεδομένα.

Ποια κατανομή χρησιμοποιείται συνήθως για τη δειγματοληψία του συντελεστή ανάμειξης λάμδα;

Το Mixup και το CutMix συνήθως αντλούν λ από μια διανομή Beta, η οποία ελέγχει πόσο ισχυρά αναμιγνύονται τα δύο παραδείγματα.

Συνέχισε να μαθαίνεις

Σχετικοί οδηγοί

Επιλέχθηκαν περισσότεροι οδηγοί για αυτό το θέμα

Λάβετε ένα δωρεάν πιστοποιητικό AIΈνα σύντομο δωρεάν μάθημα και εξέταση. Χωρίς κόστος, χωρίς κάρτα. Περίπου 2,5 ώρες.Ξεκινήστε δωρεάν →