ÎncepețiÎncepe gratuit

Preprocess image datasets

You're developing a precision agriculture system to help farmers monitor crop health, using a pre-trained transformer model, which you can later fine-tune on agricultural imagery. Preprocess the dataset using AutoImageProcessor to prepare for training!

Some data has been pre-loaded:

  • The AutoImageProcessor class has been imported from transformers
  • model is equal to microsoft/swin-tiny-patch4-window7-224
  • A sample dataset has been defined, with a sample image loaded into the variable image

Acest exercițiu face parte din cursul

Efficient AI Model Training with PyTorch

Vezi cursul

Instrucțiuni pentru exercițiu

  • Load a pre-trained image processor from the pre-defined model.
  • Map the image_processor to the entire dataset.

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

# Load a pre-trained image processor
image_processor = ____.____(model)

# Map the image_processor to the entire dataset
dataset = dataset.____(
    lambda examples: {
        "pixel_values": [
            image_processor(image, return_tensors="pt").pixel_values
            for image in examples["img"]
        ]
    },
    batched=True,
)
print(dataset[0]["img"])
Editează și rulează codul