mjkwon2021 / CAT-Net

Official code for CAT-Net: Compression Artifact Tracing Network. Image manipulation detection and localization.
210 stars 25 forks source link

Error when run with CAT_DCT_only #2

Open huytuong010101 opened 2 years ago

huytuong010101 commented 2 years ago

Hi, thank you for perfect project <3 I run python tool/infers.py With this line args = argparse.Namespace(cfg='experiments/CAT_DCT_only.yaml', opts=['TEST.MODEL_FILE', 'output/splicing_dataset/CAT_DCT_only/DCT_only_v2.pth.tar', 'TEST.FLIP_TEST', 'False', 'TEST.NUM_SAMPLES', '0']) To use CAT_DCT_only, but i got this error, can you help me fix it. Thank you

=> loading model from output/splicing_dataset/CAT_DCT_only/DCT_only_v2.pth.tar
Epoch: 199
  0% 0/2 [00:01<?, ?it/s]
Traceback (most recent call last):
  File "tools/infer.py", line 155, in <module>
    main()
  File "tools/infer.py", line 132, in main
    _, pred = model(image, label, qtable)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/parallel/data_parallel.py", line 150, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/drive/My Drive/Colab Notebooks/CAT-net/CAT-Net/tools/../lib/utils/utils.py", line 34, in forward
    outputs = self.model(inputs, qtable)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/drive/My Drive/Colab Notebooks/CAT-net/CAT-Net/tools/../lib/models/network_DCT.py", line 408, in forward
    x = self.dc_layer0_dil(DCTcoef)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 92, in forward
    input = module(input)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py", line 338, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 64 21 3 3, expected input[1, 24, 1280, 960] to have 21 channels, but got 24 channels instead
CauchyComplete commented 2 years ago

Hi,

full CAT-Net takes 24-channel input (3 for RGB and 21 for DCT) and the DCT stream takes 21-channel input.

Due to the input difference, you should uncomment this line: https://github.com/mjkwon2021/CAT-Net/blob/26aa8b06c9a0fa1fe427dbd77b8d327c92b87cba/tools/infer.py#L76

huytuong010101 commented 2 years ago

@CauchyComplete it work for me. Thank you so much <3

CauchyComplete commented 2 years ago

Glad it helped ☺️

Vadim2S commented 2 years ago

Get error. Please ignore line number.

<Splicing.data.dataset_arbitrary.arbitrary object at 0x7fa645dcb160>(116) crop_size=None, grid_crop=True, blocks=('RGB', 'DCTvol', 'qtable'), mode=arbitrary, read_from_jpeg=True, class_weight=tensor([1., 1.])

=> Cannot load pretrained RGB => Cannot load pretrained DCT => loading model from ./output/splicing_dataset/CAT_full/DCT_only_v2.pth.tar Traceback (most recent call last): File "tools/infer.py", line 240, in main() File "tools/infer.py", line 183, in main model.model.load_state_dict(checkpoint['state_dict']) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1406, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for CAT_Net: Missing key(s) in state_dict: "conv1.weight", "bn1.weight", "bn1.bias",

...... .......

          size mismatch for last_layer.0.weight: copying a param with shape torch.Size([672, 672, 1, 1]) from checkpoint, the shape in current model is torch.Size([360, 360, 1, 1]).
    size mismatch for last_layer.0.bias: copying a param with shape torch.Size([672]) from checkpoint, the shape in current model is torch.Size([360]).
    size mismatch for last_layer.1.weight: copying a param with shape torch.Size([672]) from checkpoint, the shape in current model is torch.Size([360]).
    size mismatch for last_layer.1.bias: copying a param with shape torch.Size([672]) from checkpoint, the shape in current model is torch.Size([360]).
    size mismatch for last_layer.1.running_mean: copying a param with shape torch.Size([672]) from checkpoint, the shape in current model is torch.Size([360]).
    size mismatch for last_layer.1.running_var: copying a param with shape torch.Size([672]) from checkpoint, the shape in current model is torch.Size([360]).
    size mismatch for last_layer.3.weight: copying a param with shape torch.Size([2, 672, 1, 1]) from checkpoint, the shape in current model is torch.Size([2, 360, 1, 1]).
CauchyComplete commented 2 years ago

@Vadim2S It's hard to debug your personalized code, especially when you didn't specify your changes. As far as I can tell, from the message => Cannot load pretrained RGB and the code blocks=('RGB', 'DCTvol', 'qtable'), I think you are trying to use the full model. But loading model from DCT_only_v2.pth.tar should be used when you want to use DCT stream only. Plus, next time you ask a question, please be specific and try not to just copy-paste your error message.