I have a model that I trained on MNIST… what I’m trying to do is to use an optimizer to adjust the input so that it looks more like a picture of a 6.
I’m not sure if this is possible, since I looked at GANs and they all seem to have two networks to do what I am trying with one network.
Starting from random input…
for parameter in model.parameters():
    parameter.requires_grad = False
    print((param.shape, param.requires_grad))

input_data = torch.rand(1,1,28,28)
optimizer = optim.Adadelta(model.parameters(), lr=args.lr)
input_data.requires_grad = True
model.train()
print(input_data.requires_grad)
data = input_data.to(device)
target = torch.tensor([6], dtype=torch.long).to(device)

# the main training loop
for i in range(10):
    optimizer.zero_grad()
    output = model(data)
    loss = F.nll_loss(output, target)
    loss.backward()
    optimizer.step()
    pred = output.argmax(dim=1, keepdim=True)  # get the index of the max log-probability
    print(pred, output)
ninput = data.clone().detach().cpu().numpy()[0][0]
plt.imshow(ninput)