Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply adversarial training after few epochs. #124

Closed
jhss opened this issue Nov 2, 2022 · 2 comments
Closed

Apply adversarial training after few epochs. #124

jhss opened this issue Nov 2, 2022 · 2 comments
Assignees

Comments

@jhss
Copy link

jhss commented Nov 2, 2022

I want to train the model without adversarial attack at the first two epochs.
After that, I would like to train the model with adversarial learning.

In summary,

1 epoch: Training w/o adversarial
2 epoch: Training w/o adversarial
3 epoch: Training with adversarial
4 epoch: Training with adversarial
....

Is it possible to adjust the start epoch of the adversarial training?
I couldn't find any related parameter in nsl.configs.make_adv_reg_config

@csferng
Copy link
Collaborator

csferng commented Nov 4, 2022

Hi @jhss, thanks for the question.

You're right that make_adv_reg_config doesn't have such parameter for delaying the adversarial training. Instead, you may train a base model for a few epochs before wrapping it with nsl.keras.AdversarialRegularization. This achieves the desired behavior because an AdversarialRegularization-wrapped model and its base model share the model variables. The following code snippet illustrates this idea:

base_model.fit(training_data, epochs=num_epochs_without_adv_training)
adv_model = nsl.keras.AdversarialRegularization(base_model, ...)
adv_model.fit(training_data, epochs=num_epochs_with_adv_training))

@csferng
Copy link
Collaborator

csferng commented Feb 1, 2023

Closing this issue due to inactivity in 30 days. Please feel free to reopen if you have more questions.

@csferng csferng closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants