RuntimeError: thnn_conv2d_forward is not implemented for type torch.ByteTensor

Traceback (most recent call last):                                                                                
File "train.py", line 155, in <module>                                                                          
main()                                                                                                        
File "train.py", line 150, in main                                                                              
trainer.train()                                                                                               
File "C:\myFile\code\image_scene_classification\CH\model\trainer.py", line 314, in train                        
self.train_epoch()                                                                                            
File "C:\myFile\code\image_scene_classification\CH\model\trainer.py", line 228, in train_epoch                  
self.validate()                                                                                               
File "C:\myFile\code\image_scene_classification\CH\model\trainer.py", line 123, in validate                     
output = self.model(inputs)                                                                                   
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torch\nn\modules\module.py", line 491, in __call__  
result = self.forward(*input, **kwargs)                                                                       
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torchvision\models\alexnet.py", line 43, in forward 
x = self.features(x)                                                                                          
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torch\nn\modules\module.py", line 491, in __call__  
result = self.forward(*input, **kwargs)                                                                       
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torch\nn\modules\container.py", line 91, in forward 
input = module(input)                                                                                         
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torch\nn\modules\module.py", line 491, in __call__  
result = self.forward(*input, **kwargs)                                                                       
File "C:\Users\chmtt\Anaconda3\envs\SCENE\lib\site-packages\torch\nn\modules\conv.py", line 301, in forward     
self.padding, self.dilation, self.groups)                                                                     
RuntimeError: thnn_conv2d_forward is not implemented for type torch.ByteTensor  

and my code is

// this is for get the file_path
model_path = load_model_from_name('alexnet')

model= torch.load(model_path)

the output is gotten when call model(inputs)

The problem is that the input you give to your network is of type ByteTensor while only float operations are implemented for conv like operations.

1 Like

Thanks. I review my code again.

Iā€™m getting the same error, Could you tell how did you fix it?

Basically you just need to change the type similar to how explaing in this link

Just try this

a = a.type('torch.DoubleTensor') # for converting to double tensor (cpu)
1 Like

Thanks, I could fix it following the given help.