MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / make_train_dataset

Function make_train_dataset

diffusers/examples/controlnet/train_controlnet.py:606–718  ·  view source on GitHub ↗
(args, tokenizer, accelerator)

Source from the content-addressed store, hash-verified

604
605
606def make_train_dataset(args, tokenizer, accelerator):
607 # Get the datasets: you can either provide your own training and evaluation files (see below)
608 # or specify a Dataset from the hub (the dataset will be downloaded automatically from the datasets Hub).
609
610 # In distributed training, the load_dataset function guarantees that only one local process can concurrently
611 # download the dataset.
612 if args.dataset_name is not None:
613 # Downloading and loading a dataset from the hub.
614 dataset = load_dataset(
615 args.dataset_name,
616 args.dataset_config_name,
617 cache_dir=args.cache_dir,
618 )
619 else:
620 if args.train_data_dir is not None:
621 dataset = load_dataset(
622 args.train_data_dir,
623 cache_dir=args.cache_dir,
624 )
625 # See more about loading custom images at
626 # https://huggingface.co/docs/datasets/v2.0.0/en/dataset_script
627
628 # Preprocessing the datasets.
629 # We need to tokenize inputs and targets.
630 column_names = dataset["train"].column_names
631
632 # 6. Get the column names for input/target.
633 if args.image_column is None:
634 image_column = column_names[0]
635 logger.info(f"image column defaulting to {image_column}")
636 else:
637 image_column = args.image_column
638 if image_column not in column_names:
639 raise ValueError(
640 f"`--image_column` value '{args.image_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
641 )
642
643 if args.caption_column is None:
644 caption_column = column_names[1]
645 logger.info(f"caption column defaulting to {caption_column}")
646 else:
647 caption_column = args.caption_column
648 if caption_column not in column_names:
649 raise ValueError(
650 f"`--caption_column` value '{args.caption_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
651 )
652
653 if args.conditioning_image_column is None:
654 conditioning_image_column = column_names[2]
655 logger.info(f"conditioning image column defaulting to {conditioning_image_column}")
656 else:
657 conditioning_image_column = args.conditioning_image_column
658 if conditioning_image_column not in column_names:
659 raise ValueError(
660 f"`--conditioning_image_column` value '{args.conditioning_image_column}' not found in dataset columns. Dataset columns are: {', '.join(column_names)}"
661 )
662
663 def tokenize_captions(examples, is_train=True):

Callers 1

mainFunction · 0.70

Calls 2

load_datasetFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected