Skip to content

Instantly share code, notes, and snippets.

@ksivaman
Created August 9, 2019 23:47
Show Gist options
  • Save ksivaman/7d897e3ad3f2d92ee2a3bc6d7a373b09 to your computer and use it in GitHub Desktop.
Save ksivaman/7d897e3ad3f2d92ee2a3bc6d7a373b09 to your computer and use it in GitHub Desktop.
Set features and hyperparams for neural style transfer.
# get content and style features only once before training
content_features = get_features(content, vgg)
style_features = get_features(style, vgg)
# calculate the gram matrices for each layer of our style representation
style_grams = {layer: gram_matrix(style_features[layer]) for layer in style_features}
#initialize the target image as the content image
target = content.clone().requires_grad_(True).to(device)
style_weights = {'conv1_1': 1.,
'conv2_1': 0.75,
'conv3_1': 0.2,
'conv4_1': 0.2,
'conv5_1': 0.2}
content_weight = 1
style_weight = 1e6
# iteration hyperparameters
optimizer = optim.Adam([target], lr=0.003)
steps = 2000 # decide how many iterations to update your image (5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment