<p dir="auto">I am using the BCELoss for input and target with size of batchsize * channel * height * width, I also want to weight the loss using a weight matrix of the same size, then I get the below error:</p>
<p dir="auto">File "/home/nianliu/anaconda3/lib/python3.6/site-packages/torch/nn/_functions/thnn/loss.py", line 15, in _resize_weight<br>
self.weight = self.weight.view(1, target.size(1)).expand_as(target)<br>
RuntimeError: size '[1 x 1]' is invalid for input of with 320 elements at /py/conda-bld/pytorch_1493680494901/work/torch/lib/TH/THStorage.c:59</p>
<p dir="auto">Apparently, on this line, it's incorrect to reshape the weight matrix to the size of 1*target.size(1), unless only the channel-wise weights are allowed.</p>
<p dir="auto">Since one may want to use sample-wise weights, channel-wise weights, pixel-wise weights, element-wise weights (jusk like my case), or other forms, I think we may remove the expanding operation and let users do it by themselves to ensure the flexibility.</p>
<p dir="auto">How can I save some tensor in python, but load it in libtorch:</p>
<p dir="auto">I save tensor named piror using python, using the code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="torch.save(prior,  'prior.pth')"><pre class="notranslate"><code class="notranslate">torch.save(prior,  'prior.pth')
</code></pre></div>
<p dir="auto">And I load the tensor in libtorch using C++, by the following code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="std::vector&lt;torch::Tensor&gt; tensorVec;
torch::load(tensorVec, &quot;/app/model/prior.pth&quot;);
torch::Tensor priors = tensorVec[0];"><pre class="notranslate"><code class="notranslate">std::vector&lt;torch::Tensor&gt; tensorVec;
torch::load(tensorVec, "/app/model/prior.pth");
torch::Tensor priors = tensorVec[0];
</code></pre></div>
<p dir="auto">But I got the error:<br>
terminate called after throwing an instance of 'c10::Error'<br>
what():  <code class="notranslate">torch::jit::load()</code> received a file from <code class="notranslate">torch.save()</code>, but <code class="notranslate">torch::jit::load()</code> can only load files produced by <code class="notranslate">torch.jit.save()</code> (load at ../torch/csrc/jit/serialization/import.cpp:285)</p>
<p dir="auto">Why is that? And what should I do to solve the issue? Thanks in advance.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/suo/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/suo">@suo</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/yf225/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yf225">@yf225</a></p>