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

Function tokenize_captions

diffusers/examples/controlnet/train_controlnet.py:663–680  ·  view source on GitHub ↗
(examples, is_train=True)

Source from the content-addressed store, hash-verified

661 )
662
663 def tokenize_captions(examples, is_train=True):
664 captions = []
665 for caption in examples[caption_column]:
666 if random.random() < args.proportion_empty_prompts:
667 captions.append("")
668 elif isinstance(caption, str):
669 captions.append(caption)
670 elif isinstance(caption, (list, np.ndarray)):
671 # take a random caption if there are multiple
672 captions.append(random.choice(caption) if is_train else caption[0])
673 else:
674 raise ValueError(
675 f"Caption column `{caption_column}` should contain either strings or lists of strings."
676 )
677 inputs = tokenizer(
678 captions, max_length=tokenizer.model_max_length, padding="max_length", truncation=True, return_tensors="pt"
679 )
680 return inputs.input_ids
681
682 image_transforms = transforms.Compose(
683 [

Callers 1

preprocess_trainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected