February 2018
Intermediate to advanced
262 pages
6h 59m
English
The training method is different compared to the other models that we have trained till now. Here, we need to calculate loss at multiple layers, and every time the optimizer is called, it will change the input image so that its content and style gets close to the target's content and style. Let's look at the code used for training, and then we will walk through the important steps in the training:
max_iter = 500show_iter = 50n_iter=[0]while n_iter[0] <= max_iter: def closure(): optimizer.zero_grad() out = extract_layers(loss_layers,opt_img,model=vgg) layer_losses = [weights[a] * loss_fns[a](A, targets[a]) for a,A in enumerate(out)] loss = sum(layer_losses) loss.backward() n_iter[0]+=1 #print loss if n_iter[0]%show_iter == (show_iter-1): ...
Read now
Unlock full access