This example illustrates the adversarial methods from on a simple image classification task.
# Author: Théo Gnassounou # # License: BSD 3-Clause # sphinx_gallery_thumbnail_number = 4Load the image datasets
dataset = load_mnist_usps(n_classes=2, n_samples=0.5, return_dataset=True) X, y, sample_domain = dataset.pack_train(as_sources=["mnist"], as_targets=["usps"]) X_test, y_test, sample_domain_test = dataset.pack_test(as_targets=["usps"])
/home/circleci/project/skada/datasets/_mnist_usps.py:72: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor). mnist_target = torch.tensor(mnist_dataset.targets)Train a classic model
epoch train_loss dur ------- ------------ ------ 1 1.8338 5.6983 2 0.6723 4.7002 3 0.2520 8.5028 4 0.1241 6.5940 5 0.0752 7.4009 0.9389067524115756Train a DANN model
model = DANN( MNISTtoUSPSNet(), layer_name="fc1", batch_size=128, max_epochs=5, train_split=False, reg=0.01, num_features=128, lr=1e-2, ) model.fit(X, y, sample_domain=sample_domain) model.score(X_test, y_test, sample_domain=sample_domain_test)
/home/circleci/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1736: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. return self._call_impl(*args, **kwargs) epoch train_loss dur ------- ------------ ------- 1 2.5349 13.5681 2 1.4122 14.4012 3 1.1506 13.5996 4 1.0899 13.6968 5 1.0557 16.1884 0.954983922829582
Total running time of the script: (1 minutes 49.256 seconds)
Gallery generated by Sphinx-Gallery
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4