The above code produces results that look more like this:

It should produce results like these:

2480×410


This version of the training function uses a randomly generated tensor as the item being optimized, and works correctly:
# Use random tensor instead of CPPN
def dream_cppn(net, image_size, iterations, lr, use_device):
    # Create random image 
    img = nn.Parameter(torch.randn(1, 3, image_size[0], image_size[1]).to(use_device))       
    # Setup optimizer to optimize random image
    optimizer = torch.optim.Adam([img], lr=lr)

    # Training loop
    for i in range(iterations):
        optimizer.zero_grad()
        out = net(img) # Get activations from CNN

        loss = -out.pow(2).sum().sqrt()
        loss.backward()

        # Uncomment to save iterations		
        #simple_deprocess(img.detach(), 'iters/out_'+str(i)+'.png')

        print('Iteration', str(i+1), 'Loss', str(loss.item()))

        optimizer.step()
    return img



There are structures from the target layer visible.


It seems to work better with non random images:
from PIL import Image
def preprocess(image_name, image_size):
    Loader = transforms.Compose([transforms.Resize(image_size), transforms.ToTensor()])
    Normalize = transforms.Compose([transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[1,1,1])])
    return Normalize(Loader(Image.open(image_name).convert('RGB'))).unsqueeze(0)
def deprocess(output_tensor, name='out.png'):
    Normalize = transforms.Compose([transforms.Normalize(mean=[-0.485, -0.456, -0.406], std=[1,1,1])])
    output_tensor = Normalize(output_tensor.squeeze(0).cpu())
    Image2PIL = transforms.ToPILImage()
    image = Image2PIL(output_tensor.clamp_(0, 1).cpu()).save(name)

def dream_cppn(...
    img = nn.Parameter(preprocess('test.jpg', image_size).to(use_device)) 



lr = 0.015