Aan de slagGa gratis aan de slag

Working with image data

You are given a black-and-white image of a letter, which has been encoded as a tensor, letter. You want to determine whether the letter is an X or a K. You don't have a trained neural network, but you do have a simple model, model, which can be used to classify letter.

The 3x3 tensor, letter, and the 1x3 tensor, model, are available in the Python shell. You can determine whether letter is a K by multiplying letter by model, summing over the result, and then checking if it is equal to 1. As with more complicated models, such as neural networks, model is a collection of weights, arranged in a tensor.

Note that the functions reshape(), matmul(), and reduce_sum() have been imported from tensorflow and are available for use.

Deze oefening maakt deel uit van de cursus

Introduction to TensorFlow in Python

Cursus bekijken

Oefeninstructies

  • The model, model, is 1x3 tensor, but should be a 3x1. Reshape model.
  • Perform a matrix multiplication of the 3x3 tensor, letter, by the 3x1 tensor, model.
  • Sum over the resulting tensor, output, and assign this value to prediction.
  • Print prediction using the .numpy() method to determine whether letter is K.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Reshape model from a 1x3 to a 3x1 tensor
model = ____(model, (____, ____))

# Multiply letter by model
output = ____(letter, model)

# Sum over output and print prediction using the numpy method
prediction = ____
print(prediction.____)
Code bewerken en uitvoeren