jonasricker / diffusion-model-deepfake-detection

[VISAPP2024] Towards the Detection of Diffusion Model Deepfakes
https://arxiv.org/abs/2210.14571
MIT License
82 stars 10 forks source link

Inference with Mandelli models fails here (Google Colab Pro) #9

Closed aditipanda closed 4 months ago

aditipanda commented 4 months ago

I am evaluating the pre-trained models on my dataset, and I finished with wang and gragnaniello. But for mandelli, the inference begins - runs till 36th epoch then throws this error:

File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/collate.py", line 212, in collate_tensor_fn
    out = elem.new(storage).resize_(len(batch), *list(elem.size()))
RuntimeError: Trying to resize storage that is not resizable

Did some google search and found a variation of collate_fn for the DataLoader:

def collate_fn(batch):
  return {
      'pixel_values': torch.stack([x['pixel_values'] for x in batch]),
      'labels': torch.tensor([x['labels'] for x in batch])
}

DataLoader(..., collate_fn=collate_fn)

Put this in wrappers.py, while calling dataloader, but now getting another error:

  File "/content/diffusion-model-deepfake-detection/src/wrappers.py", line 54, in <listcomp>
    return  { 'pixel_values': torch.stack([x['pixel_values'] for x in batch]), 'labels': torch.tensor([x['labels'] for x in batch]) }
TypeError: tuple indices must be integers or slices, not str

Pls help! Also, do all my images have to be of the same size?

jonasricker commented 4 months ago

If the error only occurs later I could imagine that it has to do something with the image dimensions. Usually having images with different dimensions in a single batch leads to problems. You could set the batch size to 1.

Please note that in this repository we simply adapted the models from their original repositories, so you could also use their repositories directly or open an issue there: https://github.com/polimi-ispl/gan-image-detection (for Mandelli2022).