AdaMatch is one training method that covers semi-supervised learning (SSL), unsupervised domain adaptation (UDA), and semi-supervised domain adaptation (SSDA). To implement it in Keras, start from the Keras example by Sayak Paul, which trains with MNIST as labeled source data and SVHN as unlabeled target data, then replace the data and splits to match your own setting. The arrangement of your labeled and unlabeled data across source and target domains decides which problem you are solving. The code comes second.
Decide which setting you are in before writing training code
The three settings differ only in where labels exist and which domain each example comes from. AdaMatch was written to handle all three with one training procedure, so the first job is to classify your data.
As an Amazon Associate I earn from qualifying purchases.
| Setting | Labeled data | Unlabeled data | How the Keras example relates to it |
|---|---|---|---|
| SSL (semi-supervised learning) | A small labeled set from the same task and domain | A larger unlabeled set from that same domain | Described conceptually on the Keras page; not the example’s main run |
| UDA (unsupervised domain adaptation) | Source-domain examples only | Target-domain examples with no labels | The example’s main setup: MNIST source, SVHN target |
| SSDA (semi-supervised domain adaptation) | Source-domain examples plus a small labeled set from the target domain | Unlabeled target-domain examples | Described on the Keras page as adding a few labeled target examples to the UDA setup |
The AdaMatch paper introduces the method as a unified approach to all three tasks, and its abstract uses the phrase “With the goal of generality, we introduce AdaMatch, a method that unifies the tasks of unsupervised domain adaptation (UDA), semi-supervised learning (SSL), and semi-supervised domain adaptation (SSDA).” The authors are David Berthelot, Rebecca Roelofs, Kihyuk Sohn, Nicholas Carlini, and Alex Kurakin. The paper appeared on arXiv in June 2021 and is listed by Google Research as an ICLR 2022 paper (arXiv abstract; Google Research publication record).
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsHow AdaMatch’s training step works
The Keras example explains three components. Each one is a place where a custom implementation can go wrong, so it helps to know what each is for.
#1 Best Overall
- Use scikit-learn to track an example ML project end to end
- Explore several models, including support vector machines, decision trees, random forests, and ensemble methods
- Exploit unsupervised learning techniques such as dimensionality reduction, clustering, and anomaly detection
- Dive into neural net architectures, including convolutional nets, recurrent nets, generative adversarial networks, autoencoders, diffusion models, and transformers
- Use TensorFlow and Keras to build and train neural nets for computer vision, natural language processing, generative models, and deep reinforcement learning
Weak and strong views of each example
Consistency-based learning needs two versions of the same image. The example makes a weakly augmented view with horizontal flipping and random translation, and a strongly augmented view with RandAugment. The model’s predictions on the two views are then compared, which is how unlabeled examples contribute to training.
| View | Augmentation in the Keras example | Purpose |
|---|---|---|
| Weak | Horizontal flipping and random translation | Gives a near-original input that the model can predict with confidence |
| Strong | RandAugment | Gives a heavily distorted input that the prediction should still match |
If you change augmentation, change it in both views deliberately. Making the strong view too weak removes the consistency signal, and making the weak view too aggressive makes the pseudo-targets noisy.
Rank #2
Random logit interpolation
The example runs two forward passes. The first uses the mixed source-and-target batch and updates Batch Normalization statistics. The second is a source-only pass in which Batch Normalization runs in inference mode. Source logits from the two passes are interpolated, and the example describes this as a form of consistency regularization. Keep the two passes separate in your own code. If the source-only pass also updates the Batch Normalization statistics, the normalization will be computed from a different batch composition than the one the example intends.
Distribution alignment
The example aligns the label distribution of the target predictions with that of the source. The Keras page says this matters most in UDA, where target labels are not available to correct the model directly. Because it relies on the source label distribution, it assumes the two domains share a label space. If your source and target classes differ, this step is not a drop-in fit.
Rank #3
Set up the Keras example
- Install Keras 3, a backend, and the example’s image dependencies. Run
pip install --upgrade keras, install the TensorFlow backend the example selects, then install SciPy and Pillow (pip install scipy pillow). Check the installation cell on the current Keras page, because the example was last modified on 12 May 2026 and package choices can change. - Select the backend before Keras is imported. Keras 3 reads the backend at import time, so set it first:
import os os.environ['KERAS_BACKEND'] = 'tensorflow' import keras print(keras.__version__)If you import Keras first, the environment variable is ignored for that session, and you need to restart the kernel.
- Open the example at keras.io/examples/vision/adamatch. Copy the augmentation, model, and training-step definitions as a block. Do not copy only the loss function, because the two forward passes, the Batch Normalization handling, and the interpolation depend on each other.
- Replace the data loader. Build your labeled source, unlabeled target, and test sets as described in the next section.
- Train a short run first. Confirm that each batch produces the expected shapes and that the loss is finite before starting a long run.
- Evaluate on target labels that the training loop never sees. Use a held-out target test set for the accuracy you report.
Load data with keras.utils.PyDataset
For custom data loading in Keras 3, the Keras page recommends keras.utils.PyDataset. It supports thread-safe iteration and works across the multiple backends Keras 3 supports. A subclass defines __len__ for the number of batches and __getitem__ for returning one batch. AdaMatch needs paired batches (source labeled, target unlabeled, plus any labeled target examples for SSDA), so write one PyDataset per stream and combine them in the training loop instead of forcing everything into one generator.
Split labeled, unlabeled, and test data correctly
Most failed adaptation experiments trace back to the splits, not the model. Check these before each run:
Rank #4
- Source labels are used for supervised loss only. Do not reuse source examples as the target unlabeled stream.
- Target labels in UDA are withheld from training. If you use them to pick a checkpoint, report that choice, because it gives the method information it would not have in a true UDA setting.
- In SSDA, the labeled target examples should be a separate draw from the unlabeled target pool, and the evaluation set should contain neither.
- Record the random seed. The reference repository exposes it as an argument, and an unseeded split makes comparisons between runs unreliable.
- Confirm the number of labeled target examples per class. The paper reports results for one and five labeled examples per target class, so a count per class is the comparable unit.
Use the Google Research code as reference, not as a dependency
The Google Research adamatch repository contains the original code and command examples for domain adaptation, semi-supervised domain adaptation, and semi-supervised learning on DomainNet-based tasks. The command examples take arguments for the dataset, source domain, target domain, number of labeled target examples, and random seed. The repository was archived by its owner on 19 April 2026 and is read-only. Treat it as the reference for the original training setup and check its dependencies before running it, because it will not receive fixes. For a current Keras implementation, the Keras example is the more practical starting point.
Recommended Free Tools
What the reported results do and do not tell you
The following figures come from the AdaMatch paper and are repeated on the Google Research publication page. They describe specific experiments in that paper and are not expected accuracy on your data.
Best Value
- THE FASTEST WAY TO PHONICS MASTERY - Teach and Learn Phonics with Audio Sounds, learners get to see the spelling pattern and hear the related phonetic sounds. The audio reinforcement demonstrates the content and solidifies the learning quicker than flash cards and workbooks.
- PHONICS SYSTEM QUIZZES THEM IN 13 STEPS - The electronic phonics workbook starts with single letter sounds like a, b and c. This progresses through short and long vowel sounds, consonant digraphs, trigraphs, diphthongs, bossy R, silent letters and irregular phonics.
- TEST AND BUILD PHONEMIC AWARENESS - Our Educational Learn to Read Machine challenges them to find words which contain a particular phonetic sound or pick out phonetic sounds from the given vocabulary. All created with American English Audio.
- LEARNING THAT CHILDREN ENJOY - The Screenless Educational Tablet With Talking Flash Cards tests and quizzes children on their reading and phonics knowledge while correcting errors and compounding knowledge, all the while putting a smile on their face.
- UNLOCK YOUR CHILD'S POTENTIAL WITH BAMBINO TREE! - From numbers and pictures bingo to letter flashcards and phonics games, we offer a variety of learning materials and games for children with effective tested teaching strategies.
| Reported result | Setting as described in the sources | Attribution |
|---|---|---|
| “Nearly doubles” the prior state of the art | The paper’s DomainNet UDA task | AdaMatch authors, 2021 paper (ICLR 2022) |
| 6.4% higher accuracy than the prior result that used pretraining | AdaMatch trained from scratch, compared with the cited pretrained result | AdaMatch authors, 2021 paper (ICLR 2022) |
| 6.1% additional target accuracy | One labeled example per target class (SSDA) | AdaMatch authors, 2021 paper (ICLR 2022) |
| 13.6% additional target accuracy | Five labeled examples per target class (SSDA) | AdaMatch authors, 2021 paper (ICLR 2022) |
The abstract does not give the full baseline details behind these relative improvements, so do not convert them into a single expected score for your task. Use the paper’s experiment tables when you need a precise comparison against a specific baseline.
Read the hosted MNIST-to-SVHN model card carefully
Keras-I/O publishes a hosted AdaMatch model card for an MNIST-source, SVHN-target model. Its stated results are:
| Metric | Value | Scope |
|---|---|---|
| Source accuracy (MNIST) | 98.46% | That published artifact and its stated configuration |
| Target accuracy (SVHN) | 26.51% | That published artifact and its stated configuration |
The gap between the two numbers is the core lesson of this setup. A model can fit the labeled source domain almost perfectly and still transfer poorly to the target domain. The card’s figures apply only to that artifact. They are not a benchmark for AdaMatch in general, and they should not be read as the method’s typical target performance.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Compare implementations on the right axes
No current controlled comparison of Keras implementations of AdaMatch was found, so choose on the following criteria rather than on a ranking:
Quick Recap
- Which of the three tasks it covers: SSL, UDA, or SSDA.
- Framework and backend, and whether the pinned versions match your installed Keras and backend.
- Input preprocessing and which datasets it supports.
- The weak and strong augmentation design.
- How Batch Normalization and random logit interpolation are handled.
- Target-label assumptions and split hygiene.
- Maintenance status, and whether you can reproduce the cited setup from it.
Troubleshooting checklist
- The backend setting has no effect. Restart the kernel after setting
KERAS_BACKEND, and set it before any Keras import. - The first-epoch loss is much larger than the second. The Keras page’s two-epoch log shows this. Do not treat that short run as evidence of convergence. Inspect the loss components and the batch construction before tuning anything.
- Accuracy on target is near chance. Check that target labels did not leak into the unlabeled stream and that the test split is disjoint from training data.
- Source accuracy is high but target accuracy is low. This is the transfer gap shown in the model card. Review the augmentation strength, the Batch Normalization handling, and whether the label spaces of the two domains match.
- Dependency errors from the archived repository. Pin versions yourself, and prefer the Keras example’s code when the two disagree.
The Bottom Line
“”
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




