You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to match 2D to 3D but when I run the code I get the error "Expected 5D input( got 4D input)
### Training loop
# Lists
img_list=[]
G_losses = []
D_losses = []
iters = 0
print("start Training Loop...")
# for each epoch
for epoch in range(num_epochs):
for i, data in enumerate(dataloader, 0):
##### (1) Update D Network
## we train with all real_batch
netD.zero_grad()
#format_batch
real_cpu = data[0]#.to(device)
b_size = real_cpu.size(0)
label=torch.full((b_size,), real_label, dtype=torch.float #device=device
)
# forward pass real batch through D
output = netD(real_cpu.permute(1,2,3, 0)).view(-1)
#calculate loss on all real batches
lossD_real = loss_fn(output, label)
#calculate gradients for D in backward pass
lossD_real.backward()
D_x = output.mean().item()
## Train with all fake batch
# Generate batch for latent vetcors
noise = torch.randn(b_size, nz, 1, 1, 1 #device=device
)
#Generate fake image batch with G
fake = netG(noise)
label.fill_(fake_label)
#classify all fake batch with D
output = netD(fake.detach()).view(-1)
#calculate D's loss on the all-fake bach
lossD_fake = loss_fn(output, label)
#calculate the gradient for this batch, accumulated(summed)
lossD_fake.backward()
D_G_z1 = output.mean().item()
#Compute error of D as sum over the fake and real batches
lossD = lossD_real+lossD_fake
#update D
optimizer_D.step()
##### (2) update G network
netG.zero_grad()
label.fill_(real_label)# fake labels are real for generator
#perform forward pass
output = netD(fake).view(-1)
# G's loss based on this output
lossG = loss_fn(output, label)
# Gradients for G
lossG.backward()
D_G_z2 = output.mean().item()
#update G
optimizer_G.step()
#output training stats
if i % 50 == 0:
print(f"epoch: {num_epochs}, Loss_D: {lossD.itemm(): .4f}, Loss_G: {lossG.item(): .4f}, D(x): {D_x: .4f}, D(G(z)): {D_G_z1: .4f/D_G_z2: .4f}")
#save losses fo plotting later
G_losses.append(lossG.item())
D_losses.append(lossD.item())
# Lets save G's output on fixed noise
if (iters % 500 == 0) or ((epoch == num_epochs-1) and (i==len(dataloader)-1)):
with torch.no_grad():
fake = netG(fixed_noise).detach().cpu()
img_list.appen(vutils.make_grid(fake, padding=2, normalize=True))
iters += 1
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was trying to match 2D to 3D but when I run the code I get the error "Expected 5D input( got 4D input)
Beta Was this translation helpful? Give feedback.
All reactions