todd-tasks 0.7.1__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 (134) hide show
  1. todd_tasks/__init__.py +1 -0
  2. todd_tasks/image_classification/__init__.py +1 -0
  3. todd_tasks/image_classification/datasets/__init__.py +2 -0
  4. todd_tasks/image_classification/datasets/imagenet.py +125 -0
  5. todd_tasks/image_classification/datasets/satin.py +81 -0
  6. todd_tasks/image_classification/models/__init__.py +1 -0
  7. todd_tasks/image_classification/models/ram.csv +4585 -0
  8. todd_tasks/image_classification/models/ram.py +368 -0
  9. todd_tasks/image_generation/__init__.py +3 -0
  10. todd_tasks/image_generation/datasets/__init__.py +1 -0
  11. todd_tasks/image_generation/datasets/laion_aesthetics.py +98 -0
  12. todd_tasks/image_generation/fid.py +139 -0
  13. todd_tasks/image_generation/registries.py +11 -0
  14. todd_tasks/image_segmentation/__init__.py +1 -0
  15. todd_tasks/image_segmentation/datasets/__init__.py +1 -0
  16. todd_tasks/image_segmentation/datasets/sa_med2d.py +64 -0
  17. todd_tasks/knowledge_distillation/__init__.py +2 -0
  18. todd_tasks/knowledge_distillation/distillers/__init__.py +4 -0
  19. todd_tasks/knowledge_distillation/distillers/adapts/__init__.py +9 -0
  20. todd_tasks/knowledge_distillation/distillers/adapts/attention.py +43 -0
  21. todd_tasks/knowledge_distillation/distillers/adapts/base.py +11 -0
  22. todd_tasks/knowledge_distillation/distillers/adapts/custom.py +37 -0
  23. todd_tasks/knowledge_distillation/distillers/adapts/decouple.py +45 -0
  24. todd_tasks/knowledge_distillation/distillers/adapts/detach.py +15 -0
  25. todd_tasks/knowledge_distillation/distillers/adapts/dict_tensor.py +170 -0
  26. todd_tasks/knowledge_distillation/distillers/adapts/list_tensor.py +30 -0
  27. todd_tasks/knowledge_distillation/distillers/adapts/model.py +46 -0
  28. todd_tasks/knowledge_distillation/distillers/adapts/null.py +15 -0
  29. todd_tasks/knowledge_distillation/distillers/base.py +163 -0
  30. todd_tasks/knowledge_distillation/distillers/hooks/__init__.py +4 -0
  31. todd_tasks/knowledge_distillation/distillers/hooks/append.py +21 -0
  32. todd_tasks/knowledge_distillation/distillers/hooks/base.py +101 -0
  33. todd_tasks/knowledge_distillation/distillers/hooks/duplicate.py +17 -0
  34. todd_tasks/knowledge_distillation/distillers/hooks/vanilla.py +19 -0
  35. todd_tasks/knowledge_distillation/distillers/registries.py +14 -0
  36. todd_tasks/knowledge_distillation/distillers/single_student.py +252 -0
  37. todd_tasks/knowledge_distillation/models/__init__.py +2 -0
  38. todd_tasks/knowledge_distillation/models/losses/__init__.py +1 -0
  39. todd_tasks/knowledge_distillation/models/losses/mimic.py +41 -0
  40. todd_tasks/knowledge_distillation/models/registries.py +11 -0
  41. todd_tasks/knowledge_distillation/registries.py +21 -0
  42. todd_tasks/knowledge_distillation/utils/__init__.py +1 -0
  43. todd_tasks/knowledge_distillation/utils/processors.py +326 -0
  44. todd_tasks/knowledge_graph/__init__.py +1 -0
  45. todd_tasks/knowledge_graph/conceptnet.py +65 -0
  46. todd_tasks/large_multimodal_model/__init__.py +4 -0
  47. todd_tasks/large_multimodal_model/c2i_data.py +50 -0
  48. todd_tasks/large_multimodal_model/image_data.py +42 -0
  49. todd_tasks/large_multimodal_model/interleaved_data.py +123 -0
  50. todd_tasks/large_multimodal_model/x2i_data.py +85 -0
  51. todd_tasks/natural_language_processing/__init__.py +3 -0
  52. todd_tasks/natural_language_processing/bpe.py +263 -0
  53. todd_tasks/natural_language_processing/registries.py +11 -0
  54. todd_tasks/natural_language_processing/runners/__init__.py +1 -0
  55. todd_tasks/natural_language_processing/runners/registries.py +11 -0
  56. todd_tasks/natural_language_processing/segmentors/__init__.py +2 -0
  57. todd_tasks/natural_language_processing/segmentors/base.py +28 -0
  58. todd_tasks/natural_language_processing/segmentors/regex.py +18 -0
  59. todd_tasks/natural_language_processing/tokenizers/__init__.py +2 -0
  60. todd_tasks/natural_language_processing/tokenizers/base.py +84 -0
  61. todd_tasks/natural_language_processing/tokenizers/clip.py +190 -0
  62. todd_tasks/natural_language_processing/tokenizers/clip_bpe.txt.gz +0 -0
  63. todd_tasks/object_detection/__init__.py +3 -0
  64. todd_tasks/object_detection/bboxes.py +503 -0
  65. todd_tasks/object_detection/datasets/__init__.py +4 -0
  66. todd_tasks/object_detection/datasets/coco.py +228 -0
  67. todd_tasks/object_detection/datasets/lvis.py +154 -0
  68. todd_tasks/object_detection/datasets/objects365.py +182 -0
  69. todd_tasks/object_detection/datasets/v3det.py +50 -0
  70. todd_tasks/object_detection/models/__init__.py +2 -0
  71. todd_tasks/object_detection/models/losses/__init__.py +1 -0
  72. todd_tasks/object_detection/models/losses/focal.py +53 -0
  73. todd_tasks/object_detection/models/registries.py +11 -0
  74. todd_tasks/object_detection/registries.py +21 -0
  75. todd_tasks/object_detection/visuals/__init__.py +1 -0
  76. todd_tasks/object_detection/visuals/annotations.py +102 -0
  77. todd_tasks/object_detection_knowledge_distillation/__init__.py +2 -0
  78. todd_tasks/object_detection_knowledge_distillation/distillers/__init__.py +1 -0
  79. todd_tasks/object_detection_knowledge_distillation/distillers/adapts/__init__.py +2 -0
  80. todd_tasks/object_detection_knowledge_distillation/distillers/adapts/iou.py +87 -0
  81. todd_tasks/object_detection_knowledge_distillation/distillers/adapts/mask.py +298 -0
  82. todd_tasks/object_detection_knowledge_distillation/distillers/registries.py +13 -0
  83. todd_tasks/object_detection_knowledge_distillation/models/__init__.py +2 -0
  84. todd_tasks/object_detection_knowledge_distillation/models/losses/__init__.py +3 -0
  85. todd_tasks/object_detection_knowledge_distillation/models/losses/ckd.py +129 -0
  86. todd_tasks/object_detection_knowledge_distillation/models/losses/mimic.py +197 -0
  87. todd_tasks/object_detection_knowledge_distillation/models/losses/rcnn.py +145 -0
  88. todd_tasks/object_detection_knowledge_distillation/models/registries.py +13 -0
  89. todd_tasks/object_detection_knowledge_distillation/registries.py +19 -0
  90. todd_tasks/optical_flow_estimation/__init__.py +3 -0
  91. todd_tasks/optical_flow_estimation/datasets/__init__.py +5 -0
  92. todd_tasks/optical_flow_estimation/datasets/access_layers/__init__.py +2 -0
  93. todd_tasks/optical_flow_estimation/datasets/access_layers/optical_flow.py +52 -0
  94. todd_tasks/optical_flow_estimation/datasets/access_layers/spring.py +60 -0
  95. todd_tasks/optical_flow_estimation/datasets/base.py +36 -0
  96. todd_tasks/optical_flow_estimation/datasets/registries.py +11 -0
  97. todd_tasks/optical_flow_estimation/datasets/sintel.py +80 -0
  98. todd_tasks/optical_flow_estimation/datasets/spring.py +67 -0
  99. todd_tasks/optical_flow_estimation/optical_flow.py +216 -0
  100. todd_tasks/optical_flow_estimation/registries.py +16 -0
  101. todd_tasks/point_tracking/__init__.py +3 -0
  102. todd_tasks/point_tracking/datasets/__init__.py +2 -0
  103. todd_tasks/point_tracking/datasets/access_layers/__init__.py +1 -0
  104. todd_tasks/point_tracking/datasets/access_layers/tap_vid_davis.py +58 -0
  105. todd_tasks/point_tracking/datasets/registries.py +10 -0
  106. todd_tasks/point_tracking/datasets/tap_vid_davis.py +79 -0
  107. todd_tasks/point_tracking/points.py +51 -0
  108. todd_tasks/point_tracking/registries.py +11 -0
  109. todd_tasks/point_tracking/visuals.py +129 -0
  110. todd_tasks/py.typed +0 -0
  111. todd_tasks/registries.py +44 -0
  112. todd_tasks/text_to_speech/__init__.py +3 -0
  113. todd_tasks/text_to_speech/f5_tts/__init__.py +1 -0
  114. todd_tasks/text_to_speech/f5_tts/api.py +144 -0
  115. todd_tasks/text_to_speech/f5_tts/constants.py +34 -0
  116. todd_tasks/text_to_speech/f5_tts/lines.py +50 -0
  117. todd_tasks/text_to_speech/f5_tts/modules/__init__.py +5 -0
  118. todd_tasks/text_to_speech/f5_tts/modules/audio_embedding.py +21 -0
  119. todd_tasks/text_to_speech/f5_tts/modules/dit.py +284 -0
  120. todd_tasks/text_to_speech/f5_tts/modules/model.py +110 -0
  121. todd_tasks/text_to_speech/f5_tts/modules/text_embedding.py +146 -0
  122. todd_tasks/text_to_speech/f5_tts/modules/time_embedding.py +56 -0
  123. todd_tasks/text_to_speech/f5_tts/tokenizer.py +58 -0
  124. todd_tasks/text_to_speech/f5_tts/utils.py +30 -0
  125. todd_tasks/text_to_speech/f5_tts/voices.py +49 -0
  126. todd_tasks/text_to_speech/lines.py +38 -0
  127. todd_tasks/text_to_speech/utils/__init__.py +1 -0
  128. todd_tasks/text_to_speech/utils/normalize_text.py +26 -0
  129. todd_tasks/text_to_speech/voices.py +107 -0
  130. todd_tasks-0.7.1.dist-info/METADATA +36 -0
  131. todd_tasks-0.7.1.dist-info/RECORD +134 -0
  132. todd_tasks-0.7.1.dist-info/WHEEL +5 -0
  133. todd_tasks-0.7.1.dist-info/licenses/LICENSE +201 -0
  134. todd_tasks-0.7.1.dist-info/top_level.txt +1 -0
todd_tasks/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .registries import *
@@ -0,0 +1 @@
1
+ from . import datasets, models
@@ -0,0 +1,2 @@
1
+ from .imagenet import *
2
+ from .satin import *
@@ -0,0 +1,125 @@
1
+ __all__ = [
2
+ 'ImageNetDataset',
3
+ ]
4
+
5
+ import json
6
+ import os
7
+ import pathlib
8
+ from abc import ABC
9
+ from typing import Literal, TypedDict
10
+
11
+ import torch
12
+
13
+ from todd_torch.datasets import KeysProtocol, PILDataset
14
+ from todd_torch.datasets.access_layers import PILAccessLayer
15
+ from todd_torch.registries import DatasetRegistry
16
+
17
+ Split = Literal['train', 'val']
18
+
19
+
20
+ class Synset(TypedDict):
21
+ WNID: str
22
+ words: str
23
+ gloss: str
24
+ num_children: int
25
+ children: list[int]
26
+ wordnet_height: int
27
+ num_train_images: int
28
+
29
+
30
+ Synsets = dict[int, Synset]
31
+
32
+
33
+ class Annotation(TypedDict):
34
+ name: str
35
+ synset_id: int
36
+
37
+
38
+ Annotations = list[Annotation]
39
+
40
+
41
+ class Keys(KeysProtocol[str]): # pylint: disable=unsubscriptable-object
42
+
43
+ def __init__(
44
+ self,
45
+ annotations: Annotations,
46
+ synsets: Synsets,
47
+ suffix: str,
48
+ ) -> None:
49
+ self._annotations = annotations
50
+ self._synsets = synsets
51
+ self._suffix = suffix
52
+
53
+ def __len__(self) -> int:
54
+ return len(self._annotations)
55
+
56
+ def __getitem__(self, index: int) -> str:
57
+ annotation = self._annotations[index]
58
+ return os.path.join(
59
+ self._synsets[annotation['synset_id']]['WNID'],
60
+ annotation['name'].removesuffix(f'.{self._suffix}'),
61
+ )
62
+
63
+
64
+ class T(TypedDict):
65
+ id_: str
66
+ image: torch.Tensor
67
+ category: int
68
+
69
+
70
+ @DatasetRegistry.register_()
71
+ class ImageNetDataset(PILDataset[T], ABC):
72
+ DATA_ROOT = pathlib.Path('data/imagenet')
73
+ ANNOTATIONS_ROOT = DATA_ROOT / 'annotations'
74
+ SYNSETS_FILE = DATA_ROOT / 'synsets.json'
75
+ SUFFIX = 'JPEG'
76
+
77
+ def __init__(
78
+ self,
79
+ *args,
80
+ split: Split,
81
+ access_layer: PILAccessLayer | None = None,
82
+ annotations_file: pathlib.Path | str | None = None,
83
+ synsets_file: pathlib.Path | str | None = None,
84
+ **kwargs,
85
+ ) -> None:
86
+ if access_layer is None:
87
+ access_layer = PILAccessLayer(
88
+ data_root=str(self.DATA_ROOT),
89
+ task_name=split,
90
+ subfolder_action='walk',
91
+ suffix=self.SUFFIX,
92
+ )
93
+ if annotations_file is None:
94
+ annotations_file = self.ANNOTATIONS_ROOT / f'{split}.json'
95
+ elif isinstance(annotations_file, str):
96
+ annotations_file = pathlib.Path(annotations_file)
97
+ if synsets_file is None:
98
+ synsets_file = self.SYNSETS_FILE
99
+ elif isinstance(synsets_file, str):
100
+ synsets_file = pathlib.Path(synsets_file)
101
+
102
+ with annotations_file.open() as f:
103
+ self._annotations: Annotations = json.load(f)
104
+
105
+ with self.SYNSETS_FILE.open() as f:
106
+ synsets: dict[str, Synset] = json.load(f)
107
+ synsets_: Synsets = {int(k): v for k, v in synsets.items()}
108
+ self._synsets = synsets_
109
+
110
+ self._categories = {
111
+ synset_id: i
112
+ for i, synset_id in enumerate(sorted(synsets_))
113
+ }
114
+
115
+ super().__init__(*args, access_layer=access_layer, **kwargs)
116
+
117
+ def build_keys(self) -> Keys:
118
+ return Keys(self._annotations, self._synsets, self.SUFFIX)
119
+
120
+ def __getitem__(self, index: int) -> T:
121
+ key, image = self._access(index)
122
+ tensor = self._transform(image)
123
+ synset_id = self._annotations[index]['synset_id']
124
+ category = self._categories[synset_id]
125
+ return T(id_=key, image=tensor, category=category)
@@ -0,0 +1,81 @@
1
+ __all__ = [
2
+ 'SATINDataset',
3
+ ]
4
+
5
+ import io
6
+ import pathlib
7
+ from typing import Any, Literal, TypedDict
8
+
9
+ import datasets
10
+ import torch
11
+ import torchvision.transforms.functional as F
12
+ from PIL import Image
13
+
14
+ from todd import Config
15
+ from todd_torch.datasets import AccessLayerRegistry, BaseDataset, IndexKeys
16
+ from todd_torch.datasets.access_layers import HFAccessLayer
17
+ from todd_torch.patches.pil import convert_rgb
18
+ from todd_torch.registries import DatasetRegistry
19
+
20
+
21
+ class T(TypedDict):
22
+ id_: int
23
+ image: torch.Tensor
24
+ data: dict[str, Any]
25
+
26
+
27
+ Split = Literal['SAT-4', 'SAT-6', 'NASC-TG2', 'WHU-RS19', 'RSSCN7', 'RS_C11',
28
+ 'SIRI-WHU', 'EuroSAT', 'NWPU-RESISC45', 'PatternNet',
29
+ 'RSD46-WHU', 'GID', 'CLRS', 'Optimal-31',
30
+ 'Airbus-Wind-Turbines-Patches', 'USTC_SmokeRS',
31
+ 'Canadian_Cropland', 'Ships-In-Satellite-Imagery',
32
+ 'Satellite-Images-of-Hurricane-Damage',
33
+ 'Brazilian_Coffee_Scenes', 'Brazilian_Cerrado-Savanna_Scenes',
34
+ 'Million-AID', 'UC_Merced_LandUse_MultiLabel', 'MLRSNet',
35
+ 'MultiScene', 'RSI-CB256', 'AID_MultiLabel']
36
+
37
+
38
+ @DatasetRegistry.register_()
39
+ class SATINDataset(BaseDataset[T, int, dict[str, Any]]):
40
+ DATA_ROOT = pathlib.Path('data/satin')
41
+
42
+ def __init__(
43
+ self,
44
+ *args,
45
+ split: Split,
46
+ access_layer: HFAccessLayer | None = None,
47
+ **kwargs,
48
+ ) -> None:
49
+ if access_layer is None:
50
+ access_layer = AccessLayerRegistry.build(
51
+ Config(
52
+ type=HFAccessLayer.__name__,
53
+ data_root=str(self.DATA_ROOT),
54
+ task_name=str(datasets.Split.TRAIN),
55
+ datasets=dict(
56
+ path='jonathan-roberts1/satin',
57
+ name=split,
58
+ trust_remote_code=True,
59
+ ),
60
+ ),
61
+ )
62
+
63
+ super().__init__(*args, access_layer=access_layer, **kwargs)
64
+ self._split = split
65
+
66
+ def build_keys(self) -> IndexKeys:
67
+ return IndexKeys(len(self._access_layer))
68
+
69
+ def _transform(self, image: Image.Image) -> torch.Tensor:
70
+ if self._transforms is None:
71
+ return F.pil_to_tensor(image)
72
+ return self._transforms(image)
73
+
74
+ def __getitem__(self, index: int) -> T:
75
+ key, data = self._access(index)
76
+ image = data.pop('image')
77
+ if not isinstance(image, Image.Image):
78
+ image = Image.open(io.BytesIO(image['bytes']))
79
+ image = convert_rgb(image)
80
+ tensor = self._transform(image)
81
+ return T(id_=key, image=tensor, data=data)
@@ -0,0 +1 @@
1
+ from .ram import *