{"id":14958998,"url":"https://github.com/pumpikano/tf-dann","last_synced_at":"2025-04-04T14:06:58.899Z","repository":{"id":142164273,"uuid":"61097022","full_name":"pumpikano/tf-dann","owner":"pumpikano","description":"Domain-Adversarial Neural Network in Tensorflow","archived":false,"fork":false,"pushed_at":"2021-12-05T21:27:30.000Z","size":1313,"stargazers_count":629,"open_issues_count":10,"forks_count":222,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-28T13:08:00.623Z","etag":null,"topics":["adversarial-learning","domain-adaptation","tensorflow-models"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pumpikano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-06-14T06:19:44.000Z","updated_at":"2025-03-11T12:03:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef05764f-e742-4df8-90ab-03cd23feaffb","html_url":"https://github.com/pumpikano/tf-dann","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pumpikano%2Ftf-dann","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pumpikano%2Ftf-dann/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pumpikano%2Ftf-dann/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pumpikano%2Ftf-dann/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pumpikano","download_url":"https://codeload.github.com/pumpikano/tf-dann/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adversarial-learning","domain-adaptation","tensorflow-models"],"created_at":"2024-09-24T13:18:40.088Z","updated_at":"2025-04-04T14:06:58.881Z","avatar_url":"https://github.com/pumpikano.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Domain-Adversarial Training of Neural Networks in Tensorflow\n\n\"[Unsupervised Domain Adaptation by Backpropagation](http://sites.skoltech.ru/compvision/projects/grl/files/paper.pdf)\" introduced a simple and effective method for accomplishing domain adaptation with SGD with a gradient reversal layer. This work was elaborated and extended in \"[Domain-Adversarial Training of Neural Networks](http://jmlr.org/papers/volume17/15-239/15-239.pdf)\". For more information as well as a link to an equivalent implementation in Caffe, see http://sites.skoltech.ru/compvision/projects/grl/.\n\nThe `Blobs-DANN.ipynb` shows some basic experiments on a very simple dataset. The `MNIST-DANN.ipynb` recreates the MNIST experiment from the papers on a synthetic dataset. Instructions to generate the synthetic dataset are below.\n\nRequires TensorFlow\u003e=1.0 and tested with Python 2.7 and Python 3.4.\n\n## Gradient Reversal Layer\n\nThe `flip_gradient` operation is implemented in Python by using `tf.gradient_override_map` to override the gradient of `tf.identity`. Refer to `flip_gradient.py` to see how this is implemented.\n\n```python\nfrom flip_gradient import flip_gradient\n\n# Flip the gradient of y w.r.t. x and scale by l (defaults to 1.0)\ny = flip_gradient(x, l)\n```\n\n## MNIST Experiments\n\nThe `MNIST-DANN.ipynb` notebook implements the MNIST experiments for the paper with the same model and optimization parameters, including the learning rate and adaptation parameter schedules. Rough results are below (more training would likely improve results - # epochs are not reported in the paper).\n\n| Method | Target acc (paper) | Target acc (this repo w/ 10 epochs) |\n| ------ | ------------------ | ----------------------------------- |\n| Source Only | 0.5225 | 0.4801 |\n| DANN | 0.7666 | 0.7189 |\n\n\n### Build MNIST-M dataset\n\nThe MNIST-M dataset consists of MNIST digits blended with random color patches from the [BSDS500](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/resources.html#bsds500) dataset. To generate a MNIST-M dataset, first download the BSDS500 dataset and run the `create_mnistm.py` script:\n\n```bash\ncurl -L -O http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/BSR/BSR_bsds500.tgz\npython create_mnistm.py\n```\n\nThis may take a couple minutes and should result in a `mnistm_data.pkl` file containing generated images.\n\n\n## Contribution\n\nIt would be great to add other experiments to this repository. Feel free to make a PR if you decide to recreate other results from the papers or new experiments entirely.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpikano%2Ftf-dann","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpumpikano%2Ftf-dann","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpikano%2Ftf-dann/lists"}