Open mnvt opened 1 year ago
@mnvt A good question. Yes, you can modify the code and add a simple return after a saved model is found:
if os.path.exists(save_dir+'model.m'):
model = torch.load(save_dir+'model.m')
print("Saved model {} loaded".format(save_dir+'model.m'))
return
At the time, my intention was by calling train(), the user wants to train the AE model anyway. If such a model doesn't exist, the new one will be trained. Otherwise, the pre-trained one is loaded and re-trained again. For instance, for a certain dataset, a user just trains AE model for say 1000 steps and then later decides to train it more.
Thanks for the answer.
Additionally, I noticed that you used the binary cross entropy loss for both the left and the right part of the autoencoder loss function, when the paper suggests a squared L2 distance for the reconstruction error. So I again wanted to ask the motivation behind this? I suppose a better performance (higher adversarial example generation success rate/ adversarial example closer to original sample) when all other simulation parameters stay the same?
reconst_loss_function = torch.nn.BCELoss()
BCELoss = torch.nn.BCELoss()
def loss_function_ae(reconst_ae, data, pre_trained_model_reconst_probs,
pre_trained_model_data_probs, batch_size, target, device):
prediction_pre_trained_model = pre_trained_model_data_probs.max(1, keepdim=True)[1].cpu().numpy().reshape(batch_size)
reconstrtion_loss = reconst_loss_function(reconst_ae, data)
attacked_targets = torch.zeros(pre_trained_model_data_probs.shape)
for i, j in zip(range(attacked_targets.shape[0]), prediction_pre_trained_model):
attacked_targets[i][target] = 1
attacked_targets = attacked_targets.to(device)
targte_loss = BCELoss(pre_trained_model_reconst_probs, attacked_targets)
return reconstrtion_loss + args.alpha * targte_loss
Hello, When running DeepDIG with the same parameters as a previous run (i.e. same dataset, DNN type and classes), I noticed that every subsequent run loads the autoencoder trained in the previous run, but then trains it a second time for, again, 5000 iterations. I would have expected that loading an AE from a previous run with identical parameters would cause the AE training portion to be skipped and the existing AE to simply be re-used.
Here is the first part (only showing class 1-->2) of the output of my initial run:
As expected, no existing AE was found, so a new one was created. Yet, when running it a second time, I get this:
The train() functions in train_adv.py and train_adv_of_adv.py load the saved AE from the previous run, but then train it for another 5000 steps (where the previous run left off) instead of skipping that part and leaving the pre-trained AE as is because the training code is not indented to be in the else-block (seen below). I wanted to ask if this is intentional? And if it is, why is the existing AE trained for an additional args.steps?