mirror of
https://github.com/yunjey/pytorch-tutorial.git
synced 2025-07-06 17:44:12 +08:00
@ -61,7 +61,7 @@ optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
|
||||
|
||||
# Truncated Backpropagation
|
||||
def detach(states):
|
||||
return [Variable(state.data) for state in states]
|
||||
return [state.detach() for state in states]
|
||||
|
||||
# Training
|
||||
for epoch in range(num_epochs):
|
||||
|
@ -61,7 +61,7 @@ optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
|
||||
|
||||
# Truncated Backpropagation
|
||||
def detach(states):
|
||||
return [Variable(state.data) for state in states]
|
||||
return [state.detach() for state in states]
|
||||
|
||||
# Training
|
||||
for epoch in range(num_epochs):
|
||||
|
@ -77,7 +77,7 @@ for epoch in range(200):
|
||||
|
||||
noise = Variable(torch.randn(images.size(0), 128)).cuda()
|
||||
fake_images = generator(noise)
|
||||
outputs = discriminator(fake_images)
|
||||
outputs = discriminator(fake_images.detach())
|
||||
fake_loss = criterion(outputs, fake_labels)
|
||||
fake_score = outputs
|
||||
|
||||
|
@ -77,7 +77,7 @@ for epoch in range(200):
|
||||
|
||||
noise = Variable(torch.randn(images.size(0), 128))
|
||||
fake_images = generator(noise)
|
||||
outputs = discriminator(fake_images)
|
||||
outputs = discriminator(fake_images.detach())
|
||||
fake_loss = criterion(outputs, fake_labels)
|
||||
fake_score = outputs
|
||||
|
||||
|
@ -102,7 +102,7 @@ for epoch in range(50):
|
||||
|
||||
noise = Variable(torch.randn(images.size(0), 128)).cuda()
|
||||
fake_images = generator(noise)
|
||||
outputs = discriminator(fake_images)
|
||||
outputs = discriminator(fake_images.detach())
|
||||
fake_loss = criterion(outputs, fake_labels)
|
||||
fake_score = outputs
|
||||
|
||||
|
@ -102,7 +102,7 @@ for epoch in range(50):
|
||||
|
||||
noise = Variable(torch.randn(images.size(0), 128))
|
||||
fake_images = generator(noise)
|
||||
outputs = discriminator(fake_images)
|
||||
outputs = discriminator(fake_images.detch())
|
||||
fake_loss = criterion(outputs, fake_labels)
|
||||
fake_score = outputs
|
||||
|
||||
|
Reference in New Issue
Block a user