SakurajimaMaiii / TSD

[CVPR 2023] Feature Alignment and Uniformity for Test Time Adaptation
https://arxiv.org/abs/2303.10902
MIT License
41 stars 1 forks source link

When run the code I get this error :the model is not loaded into cuda #6

Closed yoona-unicorn closed 1 year ago

yoona-unicorn commented 1 year ago

Traceback (most recent call last): File "train.py", line 126, in step_vals = algorithm.update(minibatches_device, opt, sch) File "/data/code/TSD/code/alg/algs/ERM.py", line 28, in update loss = F.cross_entropy(self.predict(all_x), all_y) File "/data/code/TSD/code/alg/algs/ERM.py", line 38, in predict return self.network(x) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, kwargs) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/container.py", line 139, in forward input = module(input) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, *kwargs) File "/data/code/TSD/code/network/img_network.py", line 57, in forward x = self.conv1(x) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(input, kwargs) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 457, in forward return self._conv_forward(input, self.weight, self.bias) File "/home/anaconda3/envs/TTA/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 453, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

yoona-unicorn commented 1 year ago

hope author can fix this bug

SakurajimaMaiii commented 1 year ago

In this, the model has been loaded into GPU. It works correctly on my own machine. May I ask if there is anything special about your environment or modify this code?

yoona-unicorn commented 1 year ago

This is strange, I did not modify this code, the environment installed according to your instructions. In fact, I see the .cuda() function, so this error confused me. The error is that the input and model weights are not of the same type and I'm not sure how to fix it yet.

SakurajimaMaiii commented 1 year ago

Hi, I think this bug is due to "model_dict": alg.cpu().state_dict()" in utils/util.py. I have fixed this bug. You can try it again. See commit 329c8c8.

yoona-unicorn commented 1 year ago

Thanks! Now,I can run the code successfully!