Attribute Error: IterableDataset object has no attribute 'with_transform'

489 views Asked by At

I have a few noise images which I want to convert into images (and see how they would look like). To do so I am trying to adapt this google colab notebook by using Imagenet-1k dataset.

I can load the Imagenet-qk dataset with logging in with hugging face token, but further in the code it throws this error:

from torchvision import transforms
from torch.utils.data import DataLoader

# define image transformations (e.g. using torchvision)
transform = Compose([
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            transforms.Lambda(lambda t: (t * 2) - 1)
])

# define function
def transforms(examples):
   examples["pixel_values"] = [transform(image.convert("L")) for image in examples["image"]]
   del examples["image"]

   return examples

transformed_dataset = dataset.with_transform(transforms).remove_columns("label")

# create dataloader
dataloader = DataLoader(transformed_dataset["train"], batch_size=batch_size, shuffle=True)
AttributeError                            Traceback (most recent call last)
<ipython-input-29-eb0a7bc7c146> in <cell line: 18>()
     16    return examples
     17 
---> 18 transformed_dataset = dataset.with_transform(transforms).remove_columns("label")
     19 
     20 # create dataloader

AttributeError: 'IterableDataset' object has no attribute 'with_transform'

Why this attribute is missing? What am I doing wrong?

In addition to replacing the data set, I will need to write the uploading of custom image to the colab code.

I am new to working with data and AI so any tips will be appreciated, thank you all!!

I tried to look through documentation for datasets on hugging face but it indicates .with_transform, and the original code using another dataset works.

0

There are 0 answers