InterDigitalInc / CompressAI

A PyTorch library and evaluation platform for end-to-end compression research
https://interdigitalinc.github.io/CompressAI/
BSD 3-Clause Clear License
1.19k stars 232 forks source link

How to encode with codec.py by the flag --cuda and is this recommended? #211

Closed sddai closed 1 year ago

sddai commented 1 year ago

the script I run:

python ./codec.py encode ./dataset/video1_1.jpg --num_of_frames 1 --model bmshj2018-factorized --metric mse -q 1 -o ./test.jpg --cuda

However I got:

Traceback (most recent call last):
  File "./codec.py", line 608, in <module>
    main(sys.argv[1:])
  File "./codec.py", line 602, in main
    encode(argv)
  File "./codec.py", line 560, in encode
    _encode(
  File "./codec.py", line 381, in _encode
    out = encode_func[codec_type](input, codec_info, output)
  File "./codec.py", line 274, in encode_image
    out = codec.net.compress(x)
  File "/root/miniconda3/lib/python3.8/site-packages/compressai/models/google.py", line 155, in compress
    y = self.g_a(x)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/container.py", line 204, in forward
    input = module(input)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 463, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 459, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensor

I know maybe it is due to the fact that input is on cpu but weights are on gpu. but how can i fix it?

thank you very much. could you please figure that why

fracape commented 1 year ago

Hi, thanks for spotting this. I just fixed (c0635d9). Please check!