Axes don't match array/size mismatch, m1: [132096 x 344], m2: [118336 x 128]

rr_A: <p>EPOCH = 20<br>
BATCH_SIZE = 128<br>
LR = 0.005  # learning rate</p>
<p>torch.cuda.empty_cache()<br>
data_transforms = torchvision.transforms.Compose([<br>
torchvision.transforms.RandomResizedCrop(344),<br>
torchvision.transforms.RandomHorizontalFlip(),<br>
torchvision.transforms.ToTensor()])<br>
path1 = ‘drive/My Drive/Colab/image/test/’<br>
train_data = torchvision.datasets.ImageFolder(path1, transform=data_transforms)</p>
<p>class AutoEncoder(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(AutoEncoder, self).<strong>init</strong>()</p>
<pre><code>    self.encoder = nn.Sequential(
        nn.Linear(3*344*344, 128),
        nn.Tanh(), # 激活
        nn.Linear(128, 64),
        nn.Tanh(),
        nn.Linear(64, 12),
        nn.Tanh(),
        nn.Linear(12, 3),   # compress to 3 features which can be visualized in plt
    )
    self.decoder = nn.Sequential(
        nn.Linear(3, 12),
        nn.Tanh(),
        nn.Linear(12, 64),
        nn.Tanh(),
        nn.Linear(64, 128),
        nn.Tanh(),
        nn.Linear(128, 3*344*344),
        nn.Sigmoid(),       # compress to a range (0, 1)
    )

def forward(self, x):
    x = x.view(x.size(0), -1)

    encoded = self.encoder(x)
    decoded = self.decoder(encoded)
    return encoded, decoded
</code></pre>
<p>autoencoder = AutoEncoder()</p>
<p>optimizer = torch.optim.Adam(autoencoder.parameters(), lr=LR)<br>
loss_func = nn.MSELoss()</p>
<h1><a name="initialize-figure-1" class="anchor" href="#initialize-figure-1"></a>initialize figure</h1>
<p>f, a = plt.subplots(2, N_TEST_IMG, figsize=(5, 2))<br>
plt.ion()   # continuously plot</p>
<h1><a name="original-data-first-row-for-viewing-2" class="anchor" href="#original-data-first-row-for-viewing-2"></a>original data (first row) for viewing</h1>
<h1><a name="view_data-train_datatrain_datan_test_imgview-1-344344typetorchfloattensor255-3" class="anchor" href="#view_data-train_datatrain_datan_test_imgview-1-344344typetorchfloattensor255-3"></a>view_data = train_data.train_data[:N_TEST_IMG].view(-1, 344*344).type(torch.FloatTensor)/255.</h1>
<h1><a name="for-i-in-rangen_test_img-4" class="anchor" href="#for-i-in-rangen_test_img-4"></a>for i in range(N_TEST_IMG):</h1>
<h1><a name="a0iimshownpreshapeview_datadatanumpyi-344-344-cmaprainbow-a0iset_xticks-a0iset_yticks-5" class="anchor" href="#a0iimshownpreshapeview_datadatanumpyi-344-344-cmaprainbow-a0iset_xticks-a0iset_yticks-5"></a>a[0][i].imshow(np.reshape(view_data.data.numpy()[i], (344, 344)), cmap=‘rainbow’); a[0][i].set_xticks(()); a[0][i].set_yticks(())</h1>
<p>for epoch in range(EPOCH):<br>
for step, (x, b_label) in enumerate(train_loader):<br>
b_x = x.view(-1, 3<em>344</em>344)   # batch x, shape (batch, 28<em>28)<br>
b_y = x.view(-1, 3</em>344<em>344)   # batch y, shape (batch, 28</em>28)</p>
<pre><code>    encoded, decoded = autoencoder(b_x)

    loss = loss_func(decoded, b_y)      # mean square error
    optimizer.zero_grad()               # clear gradients for this training step
    loss.backward()                     # backpropagation, compute gradients
    optimizer.step()                    # apply gradients
</code></pre>
<blockquote>
<p>Above is the training process</p>
</blockquote>
<p>with torch.no_grad():<br>
for img, label in train_loader :<br>
fig = plt.figure()</p>
<h1><a name="printimg-imgshape-6" class="anchor" href="#printimg-imgshape-6"></a>print(‘img’, img.shape)</h1>
<pre><code>imggg = np.transpose(img[0],(1,2,0))
</code></pre>
<h1><a name="printimggg-imgggshape-7" class="anchor" href="#printimggg-imgggshape-7"></a>print(‘imggg’, imggg.shape)</h1>
<pre><code>ax1 = fig.add_subplot(121)
ax1.imshow(imggg)

if torch.cuda.is_available():
  img = Variable(img.to())
else:
  img = Variable(img)

encoded, decoded = autoencoder(img)
</code></pre>
<h1><a name="printdecodedshape-8" class="anchor" href="#printdecodedshape-8"></a>print(decoded.shape)</h1>
<h1><a name="printdecoded-9" class="anchor" href="#printdecoded-9"></a>print(decoded)</h1>
<pre><code>decodeddd = np.transpose(decoded.cpu()[0],(1,2,0))
</code></pre>
<h1><a name="printdecodedddshape-10" class="anchor" href="#printdecodedddshape-10"></a>print(decodeddd.shape)</h1>
<h1><a name="printdecodeddd-11" class="anchor" href="#printdecodeddd-11"></a>print(decodeddd)</h1>
<pre><code>ax2 = fig.add_subplot(122)
ax2.imshow(decodeddd)
</code></pre>
<p><strong>this is the code that i used to plot my decoded picture, but it returns the error:</strong></p>
<p>TypeError                                 Traceback (most recent call last)<br>
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)<br>
55     try:<br>
—&gt; 56         return getattr(obj, method)(*args, **kwds)<br>
57</p>
<p>TypeError: transpose(): argument ‘dim0’ (position 1) must be int, not tuple</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>ValueError                                Traceback (most recent call last)<br>
3 frames<br>
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)<br>
44     except AttributeError:<br>
45         wrap = None<br>
—&gt; 46     result = getattr(asarray(obj), method)(*args, **kwds)<br>
47     if wrap:<br>
48         if not isinstance(result, mu.ndarray):</p>
<p>ValueError: axes don’t match array</p>
<p>How to solve the problem, or what should i do to show my decoded pic?</p>