I am training mobilenetV2 using COCO2017 to detect people. I am stuck in preprocessing the dataset to change it to a Tensorflow dataset. And when i managed to change, it is not parsed correctly which results in error when i do model.fit(). How to resolve this issue?
# Load the COCO dataset
(ds_train, ds_val), ds_info = tfds.load(
'coco/2017',
split=['train[:80000]', 'validation'],
with_info=True
)
IMG_SIZE = 224
NUM_CLASSES = 80 # Number of valid classes, plus one extra for invalid samples
def preprocess(sample):
image = sample['image']
# Check if 'objects' and 'label' exist and are valid
if 'objects' in sample and 'label' in sample['objects'] and len(sample['objects']['label']) > 0:
label = tf.cast(sample['objects']['label'][0], tf.int64)
else:
# Assign a default class for invalid labels (e.g., the extra class NUM_CLASSES)
label = tf.cast(NUM_CLASSES, tf.int64)
# Resize and preprocess the image
image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE))
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
return image, label
# Apply preprocessing
ds_train = ds_train.map(lambda sample: preprocess(sample)).batch(32).prefetch(tf.data.AUTOTUNE)
I am getting:
TypeError Traceback (most recent call last) Cell In[48], line 20 17 return image, label 19 # Apply preprocessing ---> 20 ds_train = ds_train.map(lambda sample: preprocess(sample)).batch(32).prefetch(tf.data.AUTOTUNE) 21 ds_val = ds_val.map(lambda sample: preprocess(sample)).batch(32).prefetch(tf.data.AUTOTUNE) TypeError: in user code:
TypeError: outer_factory.<locals>.inner_factory.<locals>.<lambda>() takes 1 positional argument but 2 were given
I tried different ways to preprocess it. basically i need to make the input images to 224×224 for the mobilenetv2 model. I trying to get a model so that i can use ot on a Himax WE-I.
Nabil Hakeem is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.