Error when trying to run network

Fugurcali: <p>Hi. I am trying to build a network and do inference on network with random weights. But I get this Error while tying to run the code:</p>
<pre><code class="lang-auto">terminate called after throwing an instance of 'c10::IndexError'
  what():  select(): index 0 out of range for tensor of size [0, 0, 1, 1] at dimension 0 (select at ../aten/src/ATen/native/TensorShape.cpp:765)
</code></pre>
<p>I don’t know what causes this error.  Can anyone give me some idea about how to solve this?</p>
<p>Complete error message is as follows:</p>
<pre><code class="lang-auto">terminate called after throwing an instance of 'c10::IndexError'
  what():  select(): index 0 out of range for tensor of size [0, 0, 1, 1] at dimension 0 (select at ../aten/src/ATen/native/TensorShape.cpp:765)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0x6a (0x7f74560bdaaa in /home/fugurcal/libtorch/lib/libc10.so)
frame #1: at::native::select(at::Tensor const&amp;, long, long) + 0x3fc (0x7f7447d6afcc in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #2: &lt;unknown function&gt; + 0x12269dd (0x7f74480979dd in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #3: &lt;unknown function&gt; + 0x120ddb7 (0x7f744807edb7 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #4: &lt;unknown function&gt; + 0x2beb918 (0x7f7449a5c918 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #5: &lt;unknown function&gt; + 0x120ddb7 (0x7f744807edb7 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #6: at::Tensor::select(long, long) const + 0xf2 (0x7f74479d7642 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #7: &lt;unknown function&gt; + 0x3373c3d (0x7f744a1e4c3d in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #8: &lt;unknown function&gt; + 0x3373fe4 (0x7f744a1e4fe4 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #9: torch::nn::init::kaiming_uniform_(at::Tensor, double, c10::variant&lt;torch::enumtype::kFanIn, torch::enumtype::kFanOut&gt;, c10::variant&lt;torch::enumtype::kLinear, torch::enumtype::kConv1D, torch::enumtype::kConv2D, torch::enumtype::kConv3D, torch::enumtype::kConvTranspose1D, torch::enumtype::kConvTranspose2D, torch::enumtype::kConvTranspose3D, torch::enumtype::kSigmoid, torch::enumtype::kTanh, torch::enumtype::kReLU, torch::enumtype::kLeakyReLU&gt;) + 0x71 (0x7f744a1e50e1 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #10: &lt;unknown function&gt; + 0x34007c1 (0x7f744a2717c1 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #11: &lt;unknown function&gt; + 0x34063c8 (0x7f744a2773c8 in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #12: torch::nn::Conv2dImpl::Conv2dImpl(torch::nn::ConvOptions&lt;2ul&gt;) + 0x28d (0x7f744a26c7bd in /home/fugurcal/libtorch/lib/libtorch_cpu.so)
frame #13: torch::nn::ModuleHolder&lt;torch::nn::Conv2dImpl&gt;::ModuleHolder&lt;torch::nn::ConvOptions&lt;2ul&gt;&amp;, , void&gt;(torch::nn::ConvOptions&lt;2ul&gt;&amp;) + 0xef (0x55dfbc7fdc41 in ./freespace_torch)
frame #14: torch::nn::Conv2d::ModuleHolder&lt;torch::nn::ConvOptions&lt;2ul&gt;&amp;, , void&gt;(torch::nn::ConvOptions&lt;2ul&gt;&amp;) + 0x23 (0x55dfbc7fb6fb in ./freespace_torch)
frame #15: VggImpl::VggImpl(int, int) + 0x457 (0x55dfbc7f3ddb in ./freespace_torch)
frame #16: torch::nn::ModuleHolder&lt;VggImpl&gt;::ModuleHolder&lt;int, int, void&gt;(int&amp;&amp;, int&amp;&amp;) + 0x57 (0x55dfbc7e840f in ./freespace_torch)
frame #17: Vgg::ModuleHolder&lt;int, int, void&gt;(int&amp;&amp;, int&amp;&amp;) + 0x2b (0x55dfbc7e48ab in ./freespace_torch)
frame #18: main + 0x205 (0x55dfbc7de593 in ./freespace_torch)
frame #19: __libc_start_main + 0xe7 (0x7f740436db97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #20: _start + 0x2a (0x55dfbc7dda6a in ./freespace_torch)

</code></pre>

glaringlee: <p><a class="mention" href="/u/fugurcali">@Fugurcali</a><br>
I think your tensor has a shape(size) [0,0,1,1] and you are trying to access the item in the tensor, let’s say you are trying to access the 1st item,  so the indexing will be something like [0][0][0][1], but since your shape at dim 0 is 0, so even [0][0][0][1] is out of the boundary at dim 0 since the boundary number at dim 0 is shape[0] - 1 == -1 in your case, this is not valid and you get an error.</p>
<p>Can you figure out why you have such tensor with zero shape? [0,0,1,1] is not a valid tensor to index. If this is a valid tensor for you, you should either make it as [1,1], or [1,1,1,1].  A shape [0,0,1,1] to me is not a valid tensor since it does has 1 item based on the shape, so it should be [1,1,1,1] or [1,1].</p>