MCPcopy Create free account
hub / github.com/00why00/JoDiffusion / preprocess_train

Function preprocess_train

train_ldm.py:409–438  ·  view source on GitHub ↗
(examples)

Source from the content-addressed store, hash-verified

407 label_norm = EncodeBitMap(n=math.ceil(math.log(dataset_cls.num_classes, 2)), ignore_label=dataset_cls.ignore_label)
408
409 def preprocess_train(examples):
410 images = [image.convert("RGB") for image in examples[image_column]]
411 labels = [label for label in examples[label_column]]
412 pixel_values = []
413 label_pixel_values = []
414 for image, label in zip(images, labels):
415 # resize
416 image = img_resize(image)
417 label = lbl_resize(label)
418 # crop
419 image = crop(image)
420 label = crop(label)
421 # flip
422 if args.random_flip and random.random() < 0.5:
423 image = flip(image)
424 label = flip(label)
425 # to tensor
426 image = image2tensor(image)
427 label = label2tensor(label)
428 # norm
429 image = image_norm(image)
430 label = label_norm(label)[0]
431 label = 2. * label - 1.
432
433 pixel_values.append(image)
434 label_pixel_values.append(label)
435
436 examples["pixel_values"] = pixel_values
437 examples["label_pixel_values"] = label_pixel_values
438 return examples
439
440 with accelerator.main_process_first():
441 train_dataset = dataset["train"].with_transform(preprocess_train)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected