flaxdiff 0.1.36.1__py3-none-any.whl → 0.1.36.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. flaxdiff/data/__init__.py +1 -0
  2. flaxdiff/data/dataset_map.py +71 -0
  3. flaxdiff/data/datasets.py +169 -0
  4. flaxdiff/data/online_loader.py +363 -0
  5. flaxdiff/data/sources/gcs.py +81 -0
  6. flaxdiff/data/sources/tfds.py +67 -0
  7. flaxdiff/metrics/inception.py +658 -0
  8. flaxdiff/metrics/utils.py +49 -0
  9. flaxdiff/models/__init__.py +1 -0
  10. flaxdiff/models/attention.py +368 -0
  11. flaxdiff/models/autoencoder/__init__.py +2 -0
  12. flaxdiff/models/autoencoder/autoencoder.py +19 -0
  13. flaxdiff/models/autoencoder/diffusers.py +91 -0
  14. flaxdiff/models/autoencoder/simple_autoenc.py +26 -0
  15. flaxdiff/models/common.py +346 -0
  16. flaxdiff/models/favor_fastattn.py +723 -0
  17. flaxdiff/models/simple_unet.py +233 -0
  18. flaxdiff/models/simple_vit.py +180 -0
  19. flaxdiff/predictors/__init__.py +96 -0
  20. flaxdiff/samplers/__init__.py +7 -0
  21. flaxdiff/samplers/common.py +165 -0
  22. flaxdiff/samplers/ddim.py +10 -0
  23. flaxdiff/samplers/ddpm.py +37 -0
  24. flaxdiff/samplers/euler.py +56 -0
  25. flaxdiff/samplers/heun_sampler.py +27 -0
  26. flaxdiff/samplers/multistep_dpm.py +59 -0
  27. flaxdiff/samplers/rk4_sampler.py +34 -0
  28. flaxdiff/schedulers/__init__.py +6 -0
  29. flaxdiff/schedulers/common.py +98 -0
  30. flaxdiff/schedulers/continuous.py +12 -0
  31. flaxdiff/schedulers/cosine.py +40 -0
  32. flaxdiff/schedulers/discrete.py +74 -0
  33. flaxdiff/schedulers/exp.py +13 -0
  34. flaxdiff/schedulers/karras.py +69 -0
  35. flaxdiff/schedulers/linear.py +14 -0
  36. flaxdiff/schedulers/sqrt.py +10 -0
  37. flaxdiff/trainer/__init__.py +2 -0
  38. flaxdiff/trainer/autoencoder_trainer.py +182 -0
  39. flaxdiff/trainer/diffusion_trainer.py +326 -0
  40. flaxdiff/trainer/simple_trainer.py +540 -0
  41. flaxdiff/trainer/video_diffusion_trainer.py +62 -0
  42. {flaxdiff-0.1.36.1.dist-info → flaxdiff-0.1.36.3.dist-info}/METADATA +1 -1
  43. flaxdiff-0.1.36.3.dist-info/RECORD +47 -0
  44. flaxdiff-0.1.36.1.dist-info/RECORD +0 -6
  45. {flaxdiff-0.1.36.1.dist-info → flaxdiff-0.1.36.3.dist-info}/WHEEL +0 -0
  46. {flaxdiff-0.1.36.1.dist-info → flaxdiff-0.1.36.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,67 @@
1
+ import cv2
2
+ import jax.numpy as jnp
3
+ import grain.python as pygrain
4
+ from flaxdiff.utils import AutoTextTokenizer
5
+ from typing import Dict
6
+ import random
7
+
8
+ # -----------------------------------------------------------------------------------------------#
9
+ # Oxford flowers and other TFDS datasources -----------------------------------------------------#
10
+ # -----------------------------------------------------------------------------------------------#
11
+
12
+ PROMPT_TEMPLATES = [
13
+ "a photo of a {}",
14
+ "a photo of a {} flower",
15
+ "This is a photo of a {}",
16
+ "This is a photo of a {} flower",
17
+ "A photo of a {} flower",
18
+ ]
19
+
20
+ def data_source_tfds(name, use_tf=True, split="all"):
21
+ import tensorflow_datasets as tfds
22
+ if use_tf:
23
+ def data_source(path_override):
24
+ return tfds.load(name, split=split, shuffle_files=True)
25
+ else:
26
+ def data_source(path_override):
27
+ return tfds.data_source(name, split=split, try_gcs=False)
28
+ return data_source
29
+
30
+ def labelizer_oxford_flowers102(path):
31
+ with open(path, "r") as f:
32
+ textlabels = [i.strip() for i in f.readlines()]
33
+
34
+ def load_labels(sample):
35
+ raw = textlabels[int(sample['label'])]
36
+ # randomly select a prompt template
37
+ template = random.choice(PROMPT_TEMPLATES)
38
+ # format the template with the label
39
+ caption = template.format(raw)
40
+ # return the caption
41
+ return caption
42
+ return load_labels
43
+
44
+ def tfds_augmenters(image_scale, method):
45
+ labelizer = labelizer_oxford_flowers102("/home/mrwhite0racle/tensorflow_datasets/oxford_flowers102/2.1.1/label.labels.txt")
46
+ if image_scale > 256:
47
+ interpolation = cv2.INTER_CUBIC
48
+ else:
49
+ interpolation = cv2.INTER_AREA
50
+ class augmenters(pygrain.MapTransform):
51
+ def __init__(self, *args, **kwargs):
52
+ super().__init__(*args, **kwargs)
53
+ self.tokenize = AutoTextTokenizer(tensor_type="np")
54
+
55
+ def map(self, element) -> Dict[str, jnp.array]:
56
+ image = element['image']
57
+ image = cv2.resize(image, (image_scale, image_scale),
58
+ interpolation=interpolation)
59
+ # image = (image - 127.5) / 127.5
60
+ caption = labelizer(element)
61
+ results = self.tokenize(caption)
62
+ return {
63
+ "image": image,
64
+ "input_ids": results['input_ids'][0],
65
+ "attention_mask": results['attention_mask'][0],
66
+ }
67
+ return augmenters