Login using Social Account
     Continue with GoogleLogin using your credentials
Since it's working, perform a longer optimization.
We shall implement the optimization as follows:
Let us go perform 5 epochs, each having 10 steps.
In each step, we will be calling the train_step
function which implements the actual optimization of the image pixels by calling various fore-defined functions for each iteration.
For each epoch, let us display the image with the updated pixels.
Let us also calculate the amount of time taken to perform this optimization. Let us use the time
module.
Note:
time.time()
method returns the time as a floating-point number expressed in seconds since the epoch, in UTC.
We shall store the starting time in using time.time()
in the beginning of the optimization code, and end=time.time()
. Then, end-start
gives the elapsed seconds taken to perform the optimization.
We imported IPython.display
as display
in the beginning of the exercise. Now,
display.clear_output()
clears the output of the current cell receiving the output.
It has a boolean parameter wait
. If it is turned True
, it means to wait to clear the output until the new output is available to replace it.
display.display()
displays a Python object in all frontends.
Use the below code for optimization:
import time
start = time.time()
epochs = 5
steps_per_epoch = 10
step = 0
for n in range(epochs):
for m in range(steps_per_epoch):
step += 1
train_step(image)
print(".", end='')
display.clear_output(wait=True)
display.display(tensor_to_image(image))
print("Train step: {}".format(step))
end = time.time()
print("Total time: {:.1f}".format(end-start))
Due to the time and resource constraints, we have selected the specified number of epochs and steps.
Let us view the output image after training for 1000 iterations. Use the code below for the same:
stylized_image = load_img("/cxldata/dlcourse/output-stylized-image.png")
plt.figure(figsize=(6,4))
plt.axis('off')
imshow(stylized_image, 'Output Stylized Image')
We could observe the style of the painting to be imparted into the content image, thus making us feel as if the dog image was drawn using the style of the style image. Hurray! You have now become a digital artist who could intelligently use Deep Learning to draw images of various styles. Congrats!
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...