MulaiMulai sekarang secara gratis

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

Latihan ini adalah bagian dari kursus

Efficient AI Model Training with PyTorch

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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"])
Edit dan Jalankan Kode