Professional Documents
Culture Documents
DAAI22 Exercises3
DAAI22 Exercises3
Teaching Assistant:
Silvia
Francesco Bucci
Cappio Borlino
silvia.bucci@polito.it
francesco.cappio@polito.it
Overview
1. Description of the problem: Domain Shift
2. Description of the solution: Domain Adaptation through DANN
3. Dataset: PACS
4. Tools: GitHub + Google Colab
5. Required steps:
a. Implement DANN architecture
b. Train on Cartoon, test on Sketch without adaptation
c. Train on Cartoon, test on Sketch with adaptation (using DANN)
d. Change the values of some hyperparameters
1
Domain Shift
Training Set (Source Domain) Test Set (Target Domain)
2
Adversarial Domain Adaptation (DANN)
Ganin, Y., et al. “Domain-adversarial training of neural networks”. The Journal of Machine Learning Research, 17(1), 2096-2030, 2016. 3
Adversarial Domain Adaptation (DANN)
Ganin, Y., et al. “Domain-adversarial training of neural networks”. The Journal of Machine Learning Research, 17(1), 2096-2030, 2016. 4
Adversarial Domain Adaptation (DANN)
Ganin, Y., et al. “Domain-adversarial training of neural networks”. The Journal of Machine Learning Research, 17(1), 2096-2030, 2016. 5
PACS
● 7 object categories
● 4 domains: Photo, Art painting,
Cartoon,Sketch
Li, Da et al. “Deeper, Broader and Artier Domain Generalization.” 2017 IEEE International Conference on Computer Vision. ICCV, 2017 6
Prepare the environment
7
a. Implement DANN architecture
Starting from the initial code, modify the architecture:
○ modify the init function in the alexnet.py file to add a new classifier for the domain
discrimination
○ all the branches must be initialized with the weights of AlexNet pre-trained on ImageNet
○ implement a flag in the forward function:
i. if data goes to the domain classifier, the gradient has to be reverted with a Gradient
Reversal Layer (GRL)
ii. the reversal is multiplied by an alpha factor in the forward: this is the weight of the
reversed backpropagation and must be optimized as an hyperparameter
8
b. Train without adaptation
For this exercise you have to consider as:
○ Source Domain: Cartoon
○ Target Domain: Sketch
Simply running the main.py file as it is you will do the training on the Photo
domain and the test on the Cartoon domain WITHOUT adaptation.
You should obtain an accuracy of ~ 50.0%
9
c. Train with adaptation
Adding the Domain Classifier with the Gradient Reversal Layer (DANN
architecture), you will obtain an increase in the performances (+2/3 points).
10