Defining a tf.data.Dataset

Helper functions

Now, let’s look at how we can create a tf.data.Dataset using the data. We’ll first write a few helper functions. Namely, we’ll define:

  • parse_image() to load and process an image from a filepath.

  • generate_tokenizer() to generate a tokenizer trained on the data passed to the function.

The parse_image() function

First, let’s discuss the parse_image() function. It takes three arguments:

  • filepath: Location of the image

  • resize_height: Height to resize the image to

  • resize_width: Width to resize the image to

The function is defined as follows:

Get hands-on with 1200+ tech skills courses.