import tkinter.filedialog dir=tkinter.filedialog.askdirectory() files=os.walk(dir) for f1 in files: direct = f1[0].split('\\')[-1] for f in f1[2]: if f.split('.')[-1] == 'jpeg': import PIL.Image jpg = f1[0] + '/' + f img = PIL.Image.open(jpg, mode='r') n={"image":img, "label":labels.index(direct)} # from datasets import Image # feature = Image() # n['image'] = feature.encode_example(n['image']) print(n,'\n',data_set["train"][-1]) data_set["train"].add_item(n) print: {'image': <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=256x256 at 0x2585ACB0D10>, 'label': 0} {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=256x256 at 0x2585ACD9F90>, 'label': 18} err: pyarrow.lib.ArrowInvalid: Could not convert <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=256x256 at 0x2585ACB0D10> with type PngImageFile: did not recognize Python value type when inferring an Arrow data type in \datasets\table.py line 757, in from_pydict when uncomment: from datasets import Image feature = Image() n['image'] = feature.encode_example(n['image']) print: {'image': {'path': 'XXXXX\00227-1230095564.jpeg', 'bytes': None}, 'label': 0} {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=256x256 at 0x1F45ABDAD90>, 'label': 23} err: AttributeError: 'Image' object has no attribute 'items' in datasets\features\features.py line 2248 _align_features Continue reading...