Project - Introduction to Neural Style Transfer using Deep Learning & TensorFlow 2 (Art Generation Project)

12 / 18

Extracting style and content - 2

We shall now use the class StyleContentModel defined in the previous slide.

When called on an image, this model returns the gram matrix (style) of the style_layers and content of the content_layers:

Note:

  • tf.constant() creates a constant tensor from a tensor-like object.

  • The output returned by the result items are of type tensorflow.python.framework.ops.EagerTensor. So we shall convert that into NumPy array and find the mathematical statistics - like minimum value, mean value, etc - of each output.

INSTRUCTIONS
  • Instantiate the class StyleContentModel and pass the style_layers and content_layers.

    extractor = << your code comes here >>(style_layers, content_layers)
    
  • Now pass the tf.constant(content_image) to the extractor and get the results - which holds the content and style representations of the content_image.

    results = << your code comes here >>(tf.constant(content_image))
    
  • Let us see the statistics of the gram-matrices returned for the content image.

    for name, output in sorted(results['style'].items()):
          print("  ", name)
          print("    shape: ", output.numpy().shape)
          print("    min: ", output.numpy().min())
          print("    max: ", output.numpy().max())
          print("    mean: ", output.numpy().mean())
          print()
    
  • Let us see the statistics of the content matrices returned for the content image.

    for name, output in sorted(results['content'].items()):
           print("  ", name)
           print("    shape: ", output.numpy().shape)
           print("    min: ", output.numpy().min())
           print("    max: ", output.numpy().max())
           print("    mean: ", output.numpy().mean())
    
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...