Код: Выделить всё
# 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)
Код: Выделить всё
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..inner_factory..() takes 1 positional argument but 2 were given
Подробнее здесь: https://stackoverflow.com/questions/790 ... 17-dataset