RuntimeError: _thnn_conv2d_forward not supported on CPUType for Byte

username: dickovsky
cooked: <pre><code class="lang-auto">RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-100-118ab5f812d5&gt; in &lt;module&gt;()
     29                 optimizer.zero_grad()
     30                 print(anchor)
---&gt; 31                 a_output = model(anchor)
     32                 p_output = model(positive)
     33                 n_output = model(negative)

5 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
    336                             _pair(0), self.dilation, self.groups)
    337         return F.conv2d(input, self.weight, self.bias, self.stride,
--&gt; 338                         self.padding, self.dilation, self.groups)
    339 
    340 
</code></pre>
<p>When I call the model, this error happens. Anyone knows how to solve this?</p>

username: ptrblck
cooked: <p>It seems you are trying to pass an input as a <code>ByteTensor</code> (uint8), which is not supported.<br>
Could you call <code>input = input.float()</code> before passing it to the model?</p>

username: dickovsky
cooked: <p>The problem is solved. Many thanks!</p>

username: glenn.jocher
cooked: <p>We are getting this same error when trying to adapt our repo (<a href="https://github.com/ultralytics/yolov3" rel="nofollow noopener">https://github.com/ultralytics/yolov3</a>) for FP16 inference. We attempted model.half(), and input.half(), which produces the following error in PyTorch 1.1. Is there a recommended way to do object detection at FP16 inference?</p>
<p>Ironically training works great with FP16 with Nvidia Apex, which is enabled by default in the repo, but only for training. Thank you!</p>
<pre><code class="lang-bash">  File "/System/Volumes/Data/Users/glennjocher/PycharmProjects/yolov3/detect.py", line 145, in &lt;module&gt;
    output=opt.output)
  File "/System/Volumes/Data/Users/glennjocher/PycharmProjects/yolov3/detect.py", line 73, in detect
    pred, _ = model(img)
  File "/Users/glennjocher/anaconda/envs/yolov3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/System/Volumes/Data/Users/glennjocher/PycharmProjects/yolov3/models.py", line 181, in forward
    x = module(x)
  File "/Users/glennjocher/anaconda/envs/yolov3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/Users/glennjocher/anaconda/envs/yolov3/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward
    input = module(input)
  File "/Users/glennjocher/anaconda/envs/yolov3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/Users/glennjocher/anaconda/envs/yolov3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 338, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: _thnn_conv2d_forward not supported on CPUType for Half
</code></pre>

username: ptrblck
cooked: <p>Some FP16 operations are not supported for CPUTensors, so you could try to run your code in the GPU instead.</p>

username: obito
cooked: <p>bro, how do you solve it, can you tell me?</p>

username: Deepak_Agrawal
cooked: <p>you can convert your trained model from half precision to full precision as shown below</p>
<p><code>learn = learn.to_fp32()</code></p>

username: sharkdeng
cooked: <p>It works! Thanks!! And I also changed cell type to TPU from CPU.</p>

username: thiyagu01
cooked: <p>so there’s no workaround to have all fp16 operations working on cpu as well? will this issue be addressed in the future?</p>