chuangchuangtan / NPR-DeepfakeDetection

94 stars 2 forks source link

Error(s) in loading state_dict for ResNet #1

Open barcavia opened 5 months ago

barcavia commented 5 months ago

Hi, first of all, great work!

I encountered an issue while attempting to train the model, specifically during the phase where the ResNet50 state dict is being loaded. The error message I encountered is as follows: size mismatch for conv1.weight: copying a param with shape torch.Size([64, 3, 7, 7]) from checkpoint, the shape in current model is torch.Size([64, 3, 3, 3]).

in your ResNet class, you are using kernel_size=3 in self.conv1, but according to resnet state_dict, the kernel_size should be 7. how did you manage to solve this when you trained your model?

Thanks in advance

chuangchuangtan commented 5 months ago

Do not need to load pre-trained models for NPR during training. The classifier is modified from ResNet50. If considering adopting resnet50 as the classifier, please replace the model with https://github.com/pytorch/vision/blob/v0.3.0/torchvision/models/resnet.py

barcavia commented 5 months ago

Thank you for the immediate response! in your code, you are using pretrained=True while training (from Trainer class): self.model = resnet50(pretrained=True) so it loads the pretrained resnet50. so from your resonse, if I understand correctly, when you trained your model, you set pretrained=False? the weights of the model were randomly initiallized?

On Mon, Jan 29, 2024 at 2:20 PM chuangchuangtan @.***> wrote:

Do not need to load pre-trained models for NPR during training. The classifier is modified from ResNet50. If considering adopting resnet50 as the classifier, please replace the model with https://github.com/pytorch/vision/blob/v0.3.0/torchvision/models/resnet.py

— Reply to this email directly, view it on GitHub https://github.com/chuangchuangtan/NPR-DeepfakeDetection/issues/1#issuecomment-1914581214, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYD4DVLUQULZNTJP6D4FL7TYQ6HXPAVCNFSM6AAAAABCEG4WPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJUGU4DCMRRGQ . You are receiving this because you authored the thread.Message ID: @.***>

chuangchuangtan commented 5 months ago

Yes, the model is randomly initialized. We will correct this mistake. Thank you for your time.

barcavia commented 5 months ago

Hi, after running the corrected code, I wasn't able to replicate your evaluation results. here is what I get:

(0 progan ) acc: 99.9; ap: 100.0 (1 stylegan ) acc: 93.2; ap: 99.8 (2 stylegan2 ) acc: 93.5; ap: 99.7 (3 biggan ) acc: 69.7; ap: 82.1 (4 cyclegan ) acc: 68.7; ap: 91.8 (5 stargan ) acc: 57.3; ap: 73.5 (6 gaugan ) acc: 64.4; ap: 82.3 (7 deepfake ) acc: 57.5; ap: 76.6 (8 Mean ) acc: 75.5; ap: 88.2

while you reported: mean acc: 92.5, mean ap: 96.1

On Tue, Jan 30, 2024 at 9:39 AM chuangchuangtan @.***> wrote:

Yes, the model is randomly initialized. We will correct this mistake. Thank you for your time.

— Reply to this email directly, view it on GitHub https://github.com/chuangchuangtan/NPR-DeepfakeDetection/issues/1#issuecomment-1916240939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYD4DVIT535CWR63VPUOCETYRCPR3AVCNFSM6AAAAABCEG4WPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGI2DAOJTHE . You are receiving this because you authored the thread.Message ID: @.***>

chuangchuangtan commented 5 months ago

If possible, please show more training hyperparameters and information about the training process.

barcavia commented 5 months ago

hi, I run your code exactly how you instructed in your repository:

python train.py --name 4class-resnet-car-cat-chair-horse --dataroot {CNNDetection-Path} --classes car,cat,chair,horse --batch_size 32 --delr_freq 10 --lr 0.0002 --niter 50

On Sat, Feb 3, 2024 at 5:11 PM chuangchuangtan @.***> wrote:

If possible, please show more training hyperparameters and information about the training process.

— Reply to this email directly, view it on GitHub https://github.com/chuangchuangtan/NPR-DeepfakeDetection/issues/1#issuecomment-1925353816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYD4DVK4EFC3ASUU2TOJAPTYRZHTBAVCNFSM6AAAAABCEG4WPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVGM2TGOBRGY . You are receiving this because you authored the thread.Message ID: @.***>

barcavia commented 4 months ago

What were your training hyperparameters and information about the training process?

On Sat, Feb 3, 2024 at 5:40 PM Bar Cavia @.***> wrote:

hi, I run your code exactly how you instructed in your repository:

python train.py --name 4class-resnet-car-cat-chair-horse --dataroot {CNNDetection-Path} --classes car,cat,chair,horse --batch_size 32 --delr_freq 10 --lr 0.0002 --niter 50

On Sat, Feb 3, 2024 at 5:11 PM chuangchuangtan @.***> wrote:

If possible, please show more training hyperparameters and information about the training process.

— Reply to this email directly, view it on GitHub https://github.com/chuangchuangtan/NPR-DeepfakeDetection/issues/1#issuecomment-1925353816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYD4DVK4EFC3ASUU2TOJAPTYRZHTBAVCNFSM6AAAAABCEG4WPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVGM2TGOBRGY . You are receiving this because you authored the thread.Message ID: @.***>

chuangchuangtan commented 4 months ago

I'm sorry for the late reply. Recently, I have been on the Lunar New Year holiday. Soon, I will release more detailed training parameters.

chuangchuangtan commented 4 months ago

We have added seed settings and made some modifications to details. In addition, we have released the conda environment, training log on Serve A, and training log on Server B.

Our GPU Server A information is as follows:(Paper results) CPU : Hygon C86 7169 24-core Processor GPU : A4000 Nvidia Driver : 495.29.05 Ubuntu Version: 20.04.1 LTS

Please train the network model using the following command. ''' CUDA_VISIBLE_DEVICES=3 python train.py --name 4class-resnet_car_cat_chair_horsebs32 --dataroot {Path of CNNDetection} --classes car,cat,chair,horse --batch_size 32 --delr_freq 10 --lr 0.0002 --niter 51 '''

Our GPU Server B information is as follows: CPU : Intel(R) Xeon(R) Gold 6248R GPU : 3090 Nvidia Driver : 470.74 Ubuntu Version: 20.04.1 LTS

Please train the network model using the following command. ''' CUDA_VISIBLE_DEVICES=3 python train.py --name 4class-resnet_car_cat_chair_horsebs32 --dataroot {Path of CNNDetection} --classes car,cat,chair,horse --batch_size 32 --delr_freq 10 --lr 0.0002 --niter 98 '''