You are on page 1of 11

Exercises

Data Analysis and Artificial Intelligence

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

Connect the GitHub repository to Google Colab:

○ Go to the Google Colab website


○ Click on the “New Notebook” button
○ Mount Google Drive on Google Colab
○ Clone this GitHub repository on your drive
○ Download the PACS dataset through this link
○ Now you can run the code, all changes will be saved on your own Google Drive

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).

d. Change the value of some HPs


Analyze the behavior of the training changing the value of some hyperparameters
(as alpha or LR).

10

You might also like