Aan de slagGa gratis aan de slag

Reshaping tensors

Later in the course, you will classify images of sign language letters using a neural network. In some cases, the network will take 1-dimensional tensors as inputs, but your data will come in the form of images, which will either be either 2- or 3-dimensional tensors, depending on whether they are grayscale or color images.

The figure below shows grayscale and color images of the sign language letter A. The two images have been imported for you and converted to the numpy arrays gray_tensor and color_tensor. Reshape these arrays into 1-dimensional vectors using the reshape operation, which has been imported for you from tensorflow. Note that the shape of gray_tensor is 28x28 and the shape of color_tensor is 28x28x3.

This figure shows grayscale and color images of the sign language letter "A".

Deze oefening maakt deel uit van de cursus

Introduction to TensorFlow in Python

Cursus bekijken

Oefeninstructies

  • Reshape gray_tensor from a 28x28 matrix into a 784x1 vector named gray_vector.
  • Reshape color_tensor from a 28x28x3 tensor into a 2352x1 vector named color_vector.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Reshape the grayscale image tensor into a vector
gray_vector = reshape(____, (____, 1))

# Reshape the color image tensor into a vector
color_vector = reshape(____, (____, ____))
Code bewerken en uitvoeren