<p>我正在使用pytorch 0.3.0。我试图有选择地复制同一层中的神经元及其权重,然后用另一组权重替换原始神经元。以下是我的尝试:</p>
<pre><code>reshaped_data2 = data2.unsqueeze(0)
new_layer_data = torch.cat([new_layer.data, reshaped_data2], dim=0)
new_layer_data[i] = data1
new_layer.data.copy_(new_layer_data)
</code></pre>
<p>首先,我解了<code>data2</code>,使之成为<code>1*X</code>张量,而不是<code>0*X</code>。
然后,我将层的张量与沿维度0重新整形的<code>data2</code>连接起来。
然后,我将位于索引<code>i</code>的原始<code>data2</code>替换为<code>data1</code>。
最后,我将所有这些复制到我的图层中</p>
<p>我得到的错误是:</p>
<pre><code>RuntimeError: inconsistent tensor size, expected tensor [10 x 128] and src [11 x 128] to have the same number of elements, but got 1280 and 1408 elements respectively at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorCopy.c:86
</code></pre>
<p>如果我做一个简单的作业而不是复制,我会得到</p>
<pre><code>RuntimeError: The expanded size of the tensor (11) must match the existing size (10) at non-singleton dimension 1. at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensor.c:309
</code></pre>
<p>我理解错误,但正确的方法是什么</p>