huanranchen / DiffusionClassifier

Official code implement of Robust Classification via a Single Diffusion Model
44 stars 4 forks source link

the meaning of '1000' #1

Closed wangherr closed 4 months ago

wangherr commented 5 months ago

https://github.com/huanranchen/DiffusionClassifier/blob/5b5b4b50d30d89501985cb20d38f1562014810ea/defenses/PurificationDefenses/DiffPure/DiffusionClassifier/DiffusionClassifier.py#L97

What is the purpose of dividing the gradient by (1000 / batchsize) here?

Could you please explain why this factor 1000 is used and how it affects the gradient update process?

huanranchen commented 5 months ago

Hi, since: total_loss = total_loss / (1000 / batchsize) therefore, x.grad = x.grad / (1000 / batchsize).

This does not have any impact on AutoPGD, since AutoPGD uses grad.sign().