C3W2 Assignment EXERCISE: shuffle and map the batches

Dear Community,

I get the following error for the aforementioned code cell:

TypeError: in converted code: TypeError: tf__format_image() takes 1 positional argument but 2 were given

Code in the cell is this:

def format_image(features):
image = features[‘image’]
image = tf.image.resize(image, IMAGE_SIZE) / 255.0
return image, features[‘label’]

BATCH_SIZE = 16 # DO NOT EDIT

For training batches, shuffle the examples by num_examples, map using the function defined above

and batching using the batch_size.

For validation and test batches, just avoid shuffling and follow the rest as training batch example

train_batches = train_examples.shuffle(num_examples).map(format_image).batch(BATCH_SIZE)
validation_batches = validation_examples.map(format_image).batch(BATCH_SIZE)
test_batches = test_examples.map(format_image).batch(BATCH_SIZE)

I checked the docs, but can’t see any error in my code. Please help me out with a non biased pair of eyes.

Thank you in advance, Zoltan

Hi Zoltan! Welcome to the community! Your examples might be formatted differently, hence the error. After the format_image() function definition, you can insert this code as a sanity check:

for example in train_examples.take(1):
  print(type(example))
  print(len(example))
  print(example.keys())

You should see this as the output:

<class 'dict'>
3
dict_keys(['image', 'image/filename', 'label'])

If it’s different, please review how you split the dataset in the tfds.load() part. The error might be there.

Important Note: After debugging, please remove the code above from your solution to avoid issues with the grader. New code snippets or code cells can halt the grading so it’s best to just modify the lines with # YOUR CODE HERE when submitting the notebook.

Lastly, please remove your solution code from your post to give other learners a chance to implement it on their own. You can use the pen button to edit it.

Hope this helps. Thanks!

Dear Chris,

As it turned out it was some cacheing problem. I reverted to the inital checkpoint of the notebook, cleared all kernel cache, filled the code cells and it worked just fine.

Still thank zou for the help.

Zoltan

Awesome! Glad you figured it out!

I got this same error because I downloaded with as_supervised=True. This gave me a tuple instead of a dictionary and that drove the problem.

The troubleshooting steps you provided led to what I needed to change.

Thanks,

T.

1 Like