

 from datasets import Dataset, DatasetDict, Image
image_paths_train = ["path/to/image_1.jpg/jpg", "path/to/image_2.jpg/jpg", , "path/to/image_n.jpg/jpg"]
 label_paths_train = ["path/to/annotation_1.png", "path/to/annotation_2.png", , "path/to/annotation_n.png"]
image_paths_validation = []
 label_paths_validation = []
def create_dataset(image_paths, label_paths):
     dataset = Dataset.from_dict({"image": sorted(image_paths),
                                 "label": sorted(label_paths)})
     dataset = dataset.cast_column("image", Image())
     dataset = dataset.cast_column("label", Image())
     return dataset
# step 1: create Dataset objects
 train_dataset = create_dataset(image_paths_train, label_paths_train)
 validation_dataset = create_dataset(image_paths_validation, label_paths_validation)
# step 2: create DatasetDict
 dataset = DatasetDict({
      "train": train_dataset,
      "validation": validation_dataset,
      }
 )
# step 3: push to Hub (assumes you have ran the huggingface-cli login command in a terminal/notebook)
 dataset.push_to_hub("your-name/dataset-repo")
# optionally, you can push to a private repo on the Hub
 # dataset.push_to_hub("name of repo on the hub", private=True)
 