Code Monkey home page Code Monkey logo

self-ensemble-visual-domain-adapt's Introduction

Self-ensembling for visual domain adaptation (small images)

Implementation of the paper Self-ensembling for visual domain adaptation, accepted as a poster at ICLR 2018.

For small image datasets including MNIST, USPS, SVHN, CIFAR-10, STL, GTSRB, etc.

For the VisDA experiments go to https://github.com/Britefury/self-ensemble-visual-domain-adapt-photo/.

Installation

You will need:

  • Python 3.6 (Anaconda Python recommended)
  • OpenCV with Python bindings
  • PyTorch

First, install OpenCV and PyTorch as pip may have trouble with these.

OpenCV with Python bindings

On Linux, install using conda:

> conda install opencv

On Windows, go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and download the OpenCV wheel file and install with:

> pip install <path_of_opencv_file>

PyTorch

For installation instructions head over to the PyTorch website.

The rest

Use pip like so:

> pip install -r requirements.txt

Usage

Domain adaptation experiments are run via the experiment_domainadapt_meanteacher.py Python program.

The experiments in our paper can be re-created by running the batch_search_exp.sh shell script like so:

bash batch_search_exp.sh <GPU> <RUN>

Where <GPU> is a string identifying the GPU to use (e.g. cuda:0) and enumerates the experiment number so that you can keep logs of multiple repeated runs separate, e.g.:

bash batch_search_exp.sh cuda:0 01

Will run on GPU 0 and will generate log files with names suffixed with run01.

To re-create the supervised baseline experiments:

bash batch_search_exp_sup.sh <GPU> <RUN

Please see the contents of the shell scripts to see the command line options used to control the experiments.

Syn-Digits, GTSTB and Syn-Signs datasets

You will need to download the Syn-Digits, GTSRB and Syn-signs datasets. After this you will need to create the file domain_datasets.cfg to tell the software where to find them.

The following assumes that you have a directory called data in which you will store these three datasets.

Syn-digits

Download Syn-digits from http://yaroslav.ganin.net, on which you will find a Google Drive link to a file called SynthDigits.zip. Create a directory call syndigits within data and unzip SynthDigits.zip within it.

GTSRB

Download GTSRB from http://benchmark.ini.rub.de/?section=gtsrb&subsection=dataset and get the training 'Images and annotations' (GTSRB_Final_Training_Images.zip), Test 'images and annotations' (GTSRB_Final_Test_Images.zip) and the test 'extended annotations including class IDs' (GTSRB_Final_Test_GT.zip).

Unzip the three files within the data directory. You should end up with the following directory structure:

GTSRB/
GTSRB/Final_Training/
GTSRB/Final_Training/Images/   -- training set images
GTSRB/Final_Training/Images/00000/   -- one directory for each class, contains image files
GTSRB/Final_Training/Images/00001/
...
GTSRB/Final_Training/Images/00042/
GTSRB/Final_Test/
GTSRB/Final_Test/Images/   -- test set images
GTSRB/GT-final_test.csv   -- test set ground truths
GTSRB/Readme-Images.txt
GTSRB/Readme-Images-Final-test.txt

Prepare GTSRB

Convert GTSRB to the required format using:

> python prepare_gtsrb.py

Syn-signs

Download Syn-signs from http://graphics.cs.msu.ru/en/node/1337/. You should get a file called synthetic_data.zip. Create a directory called synsigns within data and unzip synthetic_data.zip within data/synsigns to get the following:

synthetic_data/
synthetic_data/train/   -- contains the images as PNGs
synthetic_data/train_labelling.txt   -- ground truths

Prepare Syn-signs

Convert Syn-signs to the required format using:

> python prepare_synsigns.py

Create domain_datasets.cfg

Create the configuration file domain_datasets.cfg within the same directory as the experiment scripts. Put the following into it (change the paths if they are different):

[paths]
syn_digits=data/syndigits
gtsrb=data/GTSRB
syn_signs=data/synsigns

self-ensemble-visual-domain-adapt's People

Contributors

britefury avatar gfrenchuea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

self-ensemble-visual-domain-adapt's Issues

New state of the arts for CIFAR <-> STL and VisDA

Great work, again :)
I've noticed that your work has been the state of the art, especially for the digits classification. But the performances for the CIFAR <-> STL seem to be improved. I'm wondering whether you've noticed any recent works for the non-digits tasks. If any, please share with us. Thank you very much:)

Small point about the coding

Great work, thank you!
Here is my questions. In the script 'network_architectures.py', many 'pool3's are defined but 'pool2's are used instead. Like this

2019-03-06 10 31 08

Maybe it's not very good even though it doesn't matter.

Another question is that I found the 'Self-Ensembling' algorithm had been integrated into the library 'salad' (https://domainadaptation.org/). I'm wondering if this is consistent with your algorithm and if I can use 'salad' directly.

Thank you again for your great job!

Getting the overall accuracies

I am running the SVHN -> MNIST case. This is the output:

*** Epoch 9 took 68.69s: TRAIN clf loss=0.467770, unsup (tgt) loss=0.013310, conf mask=74.518%, unsup mask=74.518%; SRC TEST ERR=12.734%, TGT TEST student err=3.740%, TGT TEST teacher err=2.570%

How could I get the following accuracies:

  • mnist test accuracy
  • svhn train accuracy
  • svhn test accuracy

I tried figuring it out, you are using batch_map_mean but it seems to not give accuracy, but rather the log loss.

Synthetic Traffic Signs data set link

Hi I am unable to find the Synthetic traffic signs data set on the internet. Could you please share your data set link in the project page? Thanks in advance.

About WeightEMA

Hi @Britefury, in optim_weight_ema.py,
for p, src_p in zip(self.params, self.src_params): p.data[:] = src_p.data[:] this line doesn't seem to really deep copy the student model, so teacher and student may be initialized differently.

Error for --exp=syndigits_svhn and --exp=synsigns_gtsrb

I got the following errors for the two experiments above.

".../domain_datasets.py", line 24, in get_config

raise ValueError('Could not find configuration file domain_datasets.cfg')

These are the two lines from batch_search_exp.sh that I tried running.

python experiment_domainadapt_meanteacher.py --exp=syndigits_svhn --log_file=results_exp_ctaa/log_syndigits_svhn_ctaa_run${2}.txt --standardise_samples --batch_size=128 --cls_balance=0.0 --num_epochs=300

python experiment_domainadapt_meanteacher.py --exp=synsigns_gtsrb --log_file=results_exp_ctaa/log_synsigns_gtsrb_ctaa_run${2}.txt --standardise_samples --batch_size=128 --cls_balance=0.0 --num_epochs=300

Could you help check why this might be the case?

Question about domain adaptation BatchNormalization

the class DomainAdaptModule seems to maintain the different batch normalization parameters for source and target domain. But it seems that only _init_bn_layers function is called in the init and the save/restore the source/target bn function like bn_save_source is never called or appears in any other places.
Could you please help me understand how your code maintain the different source and target BN? And how they are used in the test phase?
Thank you ahead of time

help

thanks your code. and i have some confusion of this code. in this paper, student(target) and teacher(target) have different augmentation, dropout and noise parameters. but i think there are the same setting both student and teacher in the code.

Hope to get your answer. Thank you!

Hello, I read the code carefully and tried to run it, but I still have some doubts. I hope to get your help.

  1. Before the exponential moving average of the first execution weight, are the weights of student network and teacher network random?
  2. My understanding is that the labeled source domain data is used to adjust the weight of the student network, so the student network is more reliable than the teacher network. So when the weight is moved exponentially, shouldn't most of the weight in the teacher network come from the weight of the student network? When updating the weight of teacher network, why not 0.99 times the weight of student network?
    3.In the EMAWeightOptimizer Class, β€œfor tgt_p, src_p in zip(self.target_params, self.source_params): tgt_p[:] = src_p[:]”. What does this code mean?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.