ffhibnese / GIFD_Gradient_Inversion_Attack

[ICCV-2023] Gradient inversion attack, Federated learning, Generative adversarial network.
MIT License
29 stars 2 forks source link

About MobileNetV2 support #2

Open kiranosora opened 7 months ago

kiranosora commented 7 months ago

I have a problem when I change “model'" in configs_gan_free.yml from ResNet18 to MobileNet. It says:

Traceback (most recent call last): File "rec_mult.py", line 90, in model, model_seed = inversefed.construct_model(config['model'], num_classes=nclass_dict[config['dataset']], num_channels=3, seed=set_seed) File "GIFD_new/GIFD_Gradient_Inversion_Attack/inversefed/nn/models.py", line 138, in construct_model model.features[0] = torchvision.models.mobilenet.ConvBNReLU(num_channels, 32, stride=1) # this is fixed to width=1 AttributeError: module 'torchvision.models.mobilenet' has no attribute 'ConvBNReLU'

Then I modified line 138 in GIFD_new/GIFD_Gradient_Inversion_Attack/inversefed/nn/models.py to :

model.features[0] = torchvision.models.mobilenetv2.Conv2dNormActivation(num_channels, 32, stride=1) # this is fixed to width=1

It works. But the results are not very good, only blank images are reconstructed.

Then, my problem is, does GIFD supports MobileNetV2?

ffhibnese commented 7 months ago

Thanks for your attention to our work! The model loading code actually inherits from the previous repository. The newer version of the torchvision causes the mentioned issue when loading the mobilenetv2. So I suggest you adopt a different way to load this model tailored to your torchvision version. Once the model is correctly loaded and the gradients can be computed soundly, you can definitely run GIFD to recover the targeted images.