Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to update/assigning new values to elements of a DatasetDict outside the loop (for cycle) in python?

I have a dataset of images, I resize every image of the dataset and then re-assign the i-th element of the dataset with the resized_image. I’m doing this with the following code:

for i in range(0,len(dataset['train'])): #len(dataset['train'])

  ex = dataset['train'][i] #i
  image = ex['image']
  image = image.convert("RGB") # <class 'PIL.Image.Image'> <PIL.Image.Image image mode=RGB size=500x333 at 0x7F84F1948150>
  image_resized = image.resize(size_to_resize) # <PIL.Image.Image image mode=RGB size=224x224 at 0x7F84F17885D0>
  
  dataset['train'][i]['image'] = image_resized

the point is that out of the for loop, the

dataset['train'][Iterator]['image'] # where iterator=0,1,2,3,4...

give me back the i-th image not resized!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Alas, you can’t change it inplace.

DatasetDict is backed by Arrow tables, which are immutable

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading