sinapsis-generic-data-tools 0.1.0__tar.gz → 0.1.1__tar.gz

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 (20) hide show
  1. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/PKG-INFO +144 -2
  2. sinapsis_generic_data_tools-0.1.1/README.md +136 -0
  3. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/pyproject.toml +16 -3
  4. sinapsis_generic_data_tools-0.1.1/src/sinapsis_generic_data_tools/helpers/file_downloader.py +27 -0
  5. sinapsis_generic_data_tools-0.1.1/src/sinapsis_generic_data_tools/helpers/image_color_space_converter.py +136 -0
  6. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools/templates/__init__.py +1 -0
  7. sinapsis_generic_data_tools-0.1.1/src/sinapsis_generic_data_tools/templates/image_color_conversion.py +62 -0
  8. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools.egg-info/PKG-INFO +144 -2
  9. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools.egg-info/SOURCES.txt +4 -1
  10. sinapsis_generic_data_tools-0.1.1/src/sinapsis_generic_data_tools.egg-info/requires.txt +2 -0
  11. sinapsis_generic_data_tools-0.1.0/src/sinapsis_generic_data_tools/helpers/postprocess.py +0 -33
  12. sinapsis_generic_data_tools-0.1.0/src/sinapsis_generic_data_tools.egg-info/requires.txt +0 -1
  13. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/LICENSE +0 -0
  14. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/setup.cfg +0 -0
  15. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools/__init__.py +0 -0
  16. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools/helpers/__init__.py +0 -0
  17. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools/templates/mask_non_roi.py +0 -0
  18. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py +0 -0
  19. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools.egg-info/dependency_links.txt +0 -0
  20. {sinapsis_generic_data_tools-0.1.0 → sinapsis_generic_data_tools-0.1.1}/src/sinapsis_generic_data_tools.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sinapsis-generic-data-tools
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Collection of generic data tools
5
5
  Author-email: SinapsisAI <dev@sinapsis.tech>
6
6
  License: GNU AFFERO GENERAL PUBLIC LICENSE
@@ -665,6 +665,148 @@ License: GNU AFFERO GENERAL PUBLIC LICENSE
665
665
  For more information on this, and how to apply and follow the GNU AGPL, see
666
666
  <https://www.gnu.org/licenses/>.
667
667
 
668
+ Project-URL: Homepage, https://sinapsis.tech
669
+ Project-URL: Documentation, https://docs.sinapsis.tech/docs
670
+ Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
671
+ Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis-data-tools.git
668
672
  Requires-Python: >=3.10
669
673
  Description-Content-Type: text/markdown
674
+ Requires-Dist: requests>=2.32.3
670
675
  Requires-Dist: sinapsis>=0.1.1
676
+
677
+ <h1 align="center">
678
+ <br>
679
+ <a href="https://sinapsis.tech/">
680
+ <img
681
+ src="https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/logo.png?raw=true"
682
+ alt="" width="300">
683
+ </a>
684
+
685
+ <br>
686
+ Sinapsis Generic Data Tools
687
+ <br>
688
+ </h1>
689
+
690
+ <h4 align="center"> Package with generic data tools for image color conversion, buffering of data packets and other useful tools for handling data</h4>
691
+
692
+ <p align="center">
693
+ <a href="#installation">🐍 Installation</a> •
694
+ <a href="#documentation">📙 Documentation</a> •
695
+ <a href="#license">🔍 License</a>
696
+ </p>
697
+
698
+ <h2 id="installation">🐍 Installation</h2>
699
+
700
+
701
+ Install using your package manager of choice. We encourage the use of <code>uv</code>
702
+
703
+ Example with <code>uv</code>:
704
+
705
+ ```bash
706
+ uv pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
707
+ ```
708
+ or with raw <code>pip</code>:
709
+ ```bash
710
+ pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
711
+ ```
712
+
713
+ > [!IMPORTANT]
714
+ > Templates in each package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:
715
+ >
716
+
717
+ with <code>uv</code>:
718
+
719
+ ```bash
720
+ uv pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
721
+ ```
722
+ or with raw <code>pip</code>:
723
+ ```bash
724
+ pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
725
+ ```
726
+
727
+
728
+
729
+ > [!TIP]
730
+ > Use CLI command ``` sinapsis info --all-template-names``` to show a list with all the available Template names installed with Sinapsis Data Tools.
731
+
732
+ > [!TIP]
733
+ > Use CLI command ```sinapsis info --example-template-config TEMPLATE_NAME``` to produce an example Agent config for the Template specified in ***TEMPLATE_NAME***.
734
+
735
+ For example, for ***ColorConversion*** use ```sinapsis info --example-template-config ImageColorConversion``` to produce the following example config:
736
+
737
+
738
+ ```yaml
739
+ agent:
740
+ name: my_test_agent
741
+ templates:
742
+ - template_name: InputTemplate
743
+ class_name: InputTemplate
744
+ attributes: {}
745
+ - template_name: ImageColorConversion
746
+ class_name: ImageColorConversion
747
+ template_input: InputTemplate
748
+ attributes:
749
+ target_color_space: 2
750
+ ```
751
+
752
+
753
+ <h2 id="usage">📚 Usage example</h2>
754
+ <details id='usage'><summary><strong><span style="font-size: 1.0em;"> Example agent config</span></strong></summary>
755
+ You can copy and paste the following config and run it using the sinapsis cli, changing the <code>data_dir</code> attribute in the <code>FolderImageDatasetCV2</code> and the <code>root_dir</code> attribute in the <code>ImageSaver</code> template
756
+
757
+ ```yaml
758
+ agent:
759
+ name: my_test_agent
760
+ description: agent to save image locally
761
+ templates:
762
+ - template_name: InputTemplate
763
+ class_name: InputTemplate
764
+ attributes: {}
765
+ - template_name: FolderImageDatasetCV2
766
+ class_name: FolderImageDatasetCV2
767
+ attributes:
768
+ data_dir: /path/to/image
769
+ pattern: '**/*'
770
+ batch_size: 1
771
+ load_on_init: true
772
+ label_path_index: 0
773
+ is_ground_truth: false
774
+ - template_name: ImageColorConversion
775
+ class_name: ImageColorConversion
776
+ template_input: FolderImageDatasetCV2
777
+ attributes:
778
+ target_color_space: 2
779
+ - template_name: ImageSaver
780
+ class_name: ImageSaver
781
+ template_input: ColorConversion
782
+ attributes:
783
+ save_dir: /path/to/save/dir
784
+ extension: jpg
785
+ root_dir: '/path/to/sinapsis/cache'
786
+ save_full_image: true
787
+ save_bbox_crops: false
788
+ save_mask_crops: false
789
+ min_bbox_dim: 5
790
+ ```
791
+ </details>
792
+ To run, simply use:
793
+
794
+ ```bash
795
+ sinapsis run name_of_the_config.yml
796
+ ```
797
+ **NOTE**: Make sure to update the `data_dir` attribute in the `FolderImageDatasetCV2`, and the `save_dir` and `root_dir` attributes in the `ImageSaver` templates to actual directories
798
+
799
+ <h2 id="documentation">📙 Documentation</h2>
800
+
801
+ Documentation for this and other sinapsis packages is available on the [sinapsis website](https://docs.sinapsis.tech/docs)
802
+
803
+ Tutorials for different projects within sinapsis are available at [sinapsis tutorials page](https://docs.sinapsis.tech/tutorials)
804
+
805
+ <h2 id="license">🔍 License</h2>
806
+
807
+ This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the [LICENSE](LICENSE) file.
808
+
809
+ For commercial use, please refer to our [official Sinapsis website](https://sinapsis.tech) for information on obtaining a commercial license.
810
+
811
+
812
+
@@ -0,0 +1,136 @@
1
+ <h1 align="center">
2
+ <br>
3
+ <a href="https://sinapsis.tech/">
4
+ <img
5
+ src="https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/logo.png?raw=true"
6
+ alt="" width="300">
7
+ </a>
8
+
9
+ <br>
10
+ Sinapsis Generic Data Tools
11
+ <br>
12
+ </h1>
13
+
14
+ <h4 align="center"> Package with generic data tools for image color conversion, buffering of data packets and other useful tools for handling data</h4>
15
+
16
+ <p align="center">
17
+ <a href="#installation">🐍 Installation</a> •
18
+ <a href="#documentation">📙 Documentation</a> •
19
+ <a href="#license">🔍 License</a>
20
+ </p>
21
+
22
+ <h2 id="installation">🐍 Installation</h2>
23
+
24
+
25
+ Install using your package manager of choice. We encourage the use of <code>uv</code>
26
+
27
+ Example with <code>uv</code>:
28
+
29
+ ```bash
30
+ uv pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
31
+ ```
32
+ or with raw <code>pip</code>:
33
+ ```bash
34
+ pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
35
+ ```
36
+
37
+ > [!IMPORTANT]
38
+ > Templates in each package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:
39
+ >
40
+
41
+ with <code>uv</code>:
42
+
43
+ ```bash
44
+ uv pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
45
+ ```
46
+ or with raw <code>pip</code>:
47
+ ```bash
48
+ pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
49
+ ```
50
+
51
+
52
+
53
+ > [!TIP]
54
+ > Use CLI command ``` sinapsis info --all-template-names``` to show a list with all the available Template names installed with Sinapsis Data Tools.
55
+
56
+ > [!TIP]
57
+ > Use CLI command ```sinapsis info --example-template-config TEMPLATE_NAME``` to produce an example Agent config for the Template specified in ***TEMPLATE_NAME***.
58
+
59
+ For example, for ***ColorConversion*** use ```sinapsis info --example-template-config ImageColorConversion``` to produce the following example config:
60
+
61
+
62
+ ```yaml
63
+ agent:
64
+ name: my_test_agent
65
+ templates:
66
+ - template_name: InputTemplate
67
+ class_name: InputTemplate
68
+ attributes: {}
69
+ - template_name: ImageColorConversion
70
+ class_name: ImageColorConversion
71
+ template_input: InputTemplate
72
+ attributes:
73
+ target_color_space: 2
74
+ ```
75
+
76
+
77
+ <h2 id="usage">📚 Usage example</h2>
78
+ <details id='usage'><summary><strong><span style="font-size: 1.0em;"> Example agent config</span></strong></summary>
79
+ You can copy and paste the following config and run it using the sinapsis cli, changing the <code>data_dir</code> attribute in the <code>FolderImageDatasetCV2</code> and the <code>root_dir</code> attribute in the <code>ImageSaver</code> template
80
+
81
+ ```yaml
82
+ agent:
83
+ name: my_test_agent
84
+ description: agent to save image locally
85
+ templates:
86
+ - template_name: InputTemplate
87
+ class_name: InputTemplate
88
+ attributes: {}
89
+ - template_name: FolderImageDatasetCV2
90
+ class_name: FolderImageDatasetCV2
91
+ attributes:
92
+ data_dir: /path/to/image
93
+ pattern: '**/*'
94
+ batch_size: 1
95
+ load_on_init: true
96
+ label_path_index: 0
97
+ is_ground_truth: false
98
+ - template_name: ImageColorConversion
99
+ class_name: ImageColorConversion
100
+ template_input: FolderImageDatasetCV2
101
+ attributes:
102
+ target_color_space: 2
103
+ - template_name: ImageSaver
104
+ class_name: ImageSaver
105
+ template_input: ColorConversion
106
+ attributes:
107
+ save_dir: /path/to/save/dir
108
+ extension: jpg
109
+ root_dir: '/path/to/sinapsis/cache'
110
+ save_full_image: true
111
+ save_bbox_crops: false
112
+ save_mask_crops: false
113
+ min_bbox_dim: 5
114
+ ```
115
+ </details>
116
+ To run, simply use:
117
+
118
+ ```bash
119
+ sinapsis run name_of_the_config.yml
120
+ ```
121
+ **NOTE**: Make sure to update the `data_dir` attribute in the `FolderImageDatasetCV2`, and the `save_dir` and `root_dir` attributes in the `ImageSaver` templates to actual directories
122
+
123
+ <h2 id="documentation">📙 Documentation</h2>
124
+
125
+ Documentation for this and other sinapsis packages is available on the [sinapsis website](https://docs.sinapsis.tech/docs)
126
+
127
+ Tutorials for different projects within sinapsis are available at [sinapsis tutorials page](https://docs.sinapsis.tech/tutorials)
128
+
129
+ <h2 id="license">🔍 License</h2>
130
+
131
+ This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the [LICENSE](LICENSE) file.
132
+
133
+ For commercial use, please refer to our [official Sinapsis website](https://sinapsis.tech) for information on obtaining a commercial license.
134
+
135
+
136
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sinapsis-generic-data-tools"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Collection of generic data tools"
5
5
  authors = [{ name = "SinapsisAI", email = "dev@sinapsis.tech" }]
6
6
 
@@ -9,11 +9,24 @@ license = { file = "LICENSE" }
9
9
 
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
+ "requests>=2.32.3",
12
13
  "sinapsis>=0.1.1",
13
14
  ]
14
-
15
15
  [build-system]
16
16
  requires = ["setuptools"]
17
17
  build-backend = "setuptools.build_meta"
18
18
  [tool.setuptools]
19
- license-files = []
19
+ license-files = []
20
+
21
+
22
+
23
+ [[tool.uv.index]]
24
+ name = "sinapsis"
25
+ url = "https://pypi.sinapsis.tech/"
26
+
27
+
28
+ [project.urls]
29
+ Homepage = "https://sinapsis.tech"
30
+ Documentation = "https://docs.sinapsis.tech/docs"
31
+ Tutorials = "https://docs.sinapsis.tech/tutorials"
32
+ Repository = "https://github.com/Sinapsis-AI/sinapsis-data-tools.git"
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+
4
+ import requests
5
+ from sinapsis_core.utils.logging_utils import sinapsis_logger
6
+
7
+
8
+ def download_file(url: str, output_path: str, description: str | None = None) -> None:
9
+ """General-purpose function to download a file from a URL.
10
+
11
+ Args:
12
+ url (str): The URL of the file to download.
13
+ output_path (str): The path to save the downloaded file.
14
+ description (Optional[str]): Description for logging purposes.
15
+ """
16
+ if os.path.exists(output_path):
17
+ return
18
+
19
+ sinapsis_logger.info(f"Downloading {description or 'file'} from {url} to {output_path}...")
20
+ response = requests.get(url, stream=True)
21
+ if response.status_code == 200:
22
+ with open(output_path, "wb") as f:
23
+ for chunk in response.iter_content(chunk_size=8192):
24
+ f.write(chunk)
25
+ sinapsis_logger.info(f"{description or 'File'} download completed successfully.")
26
+ else:
27
+ raise RuntimeError(f"Failed to download {description or 'file'}. HTTP status code: {response.status_code}")
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+ import cv2
3
+ import torch
4
+ from numpy import ndarray
5
+ from sinapsis_core.data_containers.data_packet import ImageColor, ImagePacket
6
+ from sinapsis_core.utils.logging_utils import sinapsis_logger
7
+
8
+ color_mapping_cv = {
9
+ (ImageColor.RGB, ImageColor.BGR): cv2.COLOR_RGB2BGR,
10
+ (ImageColor.RGB, ImageColor.GRAY): cv2.COLOR_RGB2GRAY,
11
+ (ImageColor.RGB, ImageColor.RGBA): cv2.COLOR_RGB2RGBA,
12
+ (ImageColor.BGR, ImageColor.RGB): cv2.COLOR_BGR2RGB,
13
+ (ImageColor.BGR, ImageColor.GRAY): cv2.COLOR_BGR2GRAY,
14
+ (ImageColor.BGR, ImageColor.RGBA): cv2.COLOR_BGR2RGBA,
15
+ (ImageColor.GRAY, ImageColor.RGB): cv2.COLOR_GRAY2RGB,
16
+ (ImageColor.GRAY, ImageColor.BGR): cv2.COLOR_GRAY2BGR,
17
+ (ImageColor.GRAY, ImageColor.RGBA): cv2.COLOR_GRAY2RGBA,
18
+ (ImageColor.RGBA, ImageColor.RGB): cv2.COLOR_RGBA2RGB,
19
+ (ImageColor.RGBA, ImageColor.BGR): cv2.COLOR_RGBA2BGR,
20
+ (ImageColor.RGBA, ImageColor.GRAY): cv2.COLOR_RGBA2GRAY,
21
+ }
22
+
23
+
24
+ def convert_color_space(image_packet: ImagePacket, desired_color_space: ImageColor) -> ImagePacket:
25
+ """Converts the color space of the image contained in the ImagePacket to the desired color space.
26
+
27
+ Args:
28
+ image_packet (ImagePacket): The ImagePacket containing the image and its current color space.
29
+ desired_color_space (ImageColor): The target color space to which the image should be converted.
30
+
31
+ Raises:
32
+ TypeError: If the content of the ImagePacket is neither a numpy.ndarray nor a torch.Tensor.
33
+
34
+ Returns:
35
+ ImagePacket: The ImagePacket with the image converted to the desired color space.
36
+ """
37
+ current_color_space = image_packet.color_space
38
+
39
+ if current_color_space == desired_color_space:
40
+ return image_packet
41
+
42
+ if isinstance(image_packet.content, ndarray):
43
+ return convert_color_space_cv(image_packet, current_color_space, desired_color_space)
44
+ elif isinstance(image_packet.content, torch.Tensor):
45
+ return convert_color_space_torch(image_packet, current_color_space, desired_color_space)
46
+ else:
47
+ raise TypeError(f"Unsupported content type: {type(image_packet.content)}")
48
+
49
+
50
+ def convert_color_space_cv(
51
+ image_packet: ImagePacket, current_color_space: ImageColor, desired_color_space: ImageColor
52
+ ) -> ImagePacket:
53
+ """Converts the color space of the image contained in the ImagePacket using OpenCV.
54
+
55
+ Args:
56
+ image_packet (ImagePacket): The ImagePacket containing the image and its current color space.
57
+ current_color_space (ImageColor): The current color space of the image.
58
+ desired_color_space (ImageColor): The target color space to which the image should be converted.
59
+
60
+ Raises:
61
+ ValueError: If the conversion between the current and desired color spaces is not supported.
62
+
63
+ Returns:
64
+ ImagePacket: The ImagePacket with the image converted to the desired color space.
65
+ """
66
+ if (current_color_space, desired_color_space) in color_mapping_cv:
67
+ conversion_code = color_mapping_cv[(current_color_space, desired_color_space)]
68
+ try:
69
+ image_packet.content = cv2.cvtColor(image_packet.content, conversion_code)
70
+ image_packet.color_space = desired_color_space
71
+
72
+ except cv2.error:
73
+ sinapsis_logger.error(f"Invalid conversion between {current_color_space} and {desired_color_space}")
74
+
75
+ else:
76
+ raise ValueError(f"Conversion from {current_color_space} to {desired_color_space} is not supported.")
77
+
78
+ return image_packet
79
+
80
+
81
+ def convert_color_space_torch(
82
+ image_packet: ImagePacket, current_color_space: ImageColor, desired_color_space: ImageColor
83
+ ) -> ImagePacket:
84
+ """Converts the color space of the image contained in the ImagePacket using PyTorch.
85
+
86
+ Args:
87
+ image_packet (ImagePacket): The ImagePacket containing the image and its current color space.
88
+ current_color_space (ImageColor): The current color space of the image.
89
+ desired_color_space (ImageColor): The target color space to which the image should be converted.
90
+
91
+ Raises:
92
+ ValueError: If the conversion between the current and desired color spaces is not supported.
93
+
94
+ Returns:
95
+ ImagePacket: The ImagePacket with the image converted to the desired color space.
96
+ """
97
+ tensor = image_packet.content
98
+
99
+ if (current_color_space, desired_color_space) in {
100
+ (ImageColor.RGB, ImageColor.BGR),
101
+ (ImageColor.BGR, ImageColor.RGB),
102
+ }:
103
+ if tensor.shape[-1] == 3:
104
+ image_packet.content = tensor[..., [2, 1, 0]]
105
+ else:
106
+ image_packet.content = tensor.permute(2, 1, 0)
107
+ image_packet.color_space = desired_color_space
108
+
109
+ elif (current_color_space, desired_color_space) in {
110
+ (ImageColor.RGB, ImageColor.GRAY),
111
+ (ImageColor.BGR, ImageColor.GRAY),
112
+ }:
113
+ if current_color_space == ImageColor.BGR:
114
+ tensor = tensor[..., [2, 1, 0]] if tensor.shape[-1] == 3 else tensor.permute(2, 1, 0)
115
+
116
+ weights = torch.tensor([0.299, 0.587, 0.114], dtype=tensor.dtype, device=tensor.device)
117
+ if tensor.shape[-1] == 3:
118
+ image_packet.content = (tensor * weights).sum(dim=-1, keepdim=True)
119
+ else:
120
+ image_packet.content = (tensor.permute(1, 2, 0) * weights).sum(dim=-1, keepdim=True).permute(2, 0, 1)
121
+ image_packet.color_space = desired_color_space
122
+
123
+ elif (current_color_space, desired_color_space) in {
124
+ (ImageColor.GRAY, ImageColor.RGB),
125
+ (ImageColor.GRAY, ImageColor.BGR),
126
+ }:
127
+ if tensor.shape[-1] == 1:
128
+ image_packet.content = tensor.repeat(1, 1, 3)
129
+ else:
130
+ image_packet.content = tensor.repeat(3, 1, 1)
131
+ image_packet.color_space = desired_color_space
132
+
133
+ else:
134
+ raise ValueError(f"Unsupported Torch conversion: {current_color_space} -> {desired_color_space}")
135
+
136
+ return image_packet
@@ -5,6 +5,7 @@ from typing import Callable
5
5
  _root_lib_path = "sinapsis_generic_data_tools.templates"
6
6
 
7
7
  _template_lookup = {
8
+ "ImageColorConversion": f"{_root_lib_path}.image_color_conversion",
8
9
  "MaskNonROIs": f"{_root_lib_path}.mask_non_roi",
9
10
  "PacketBufferQueue": f"{_root_lib_path}.packet_buffer_queue",
10
11
  }
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+ from sinapsis_core.data_containers.data_packet import (
3
+ DataContainer,
4
+ ImageColor,
5
+ )
6
+ from sinapsis_core.template_base import (
7
+ Template,
8
+ TemplateAttributes,
9
+ )
10
+
11
+ from sinapsis_generic_data_tools.helpers.image_color_space_converter import convert_color_space
12
+
13
+
14
+ class ImageColorConversion(Template):
15
+ """A template for converting the color space of images within a DataContainer.
16
+
17
+ This template applies color space conversion to all image packets contained within a DataContainer.
18
+ The target color space is specified in the template's attributes.
19
+
20
+ Usage example:
21
+
22
+ agent:
23
+ name: my_test_agent
24
+ templates:
25
+ - template_name: InputTemplate
26
+ class_name: InputTemplate
27
+ attributes: {}
28
+ - template_name: ColorConversion
29
+ class_name: ColorConversion
30
+ template_input: InputTemplate
31
+ attributes:
32
+ target_color_space: 2
33
+ """
34
+
35
+ class AttributesBaseModel(TemplateAttributes):
36
+ """Defines the attributes required for the ColorConversion template.
37
+
38
+ Attributes:
39
+ target_color_space (ImageColor): The target color space to which all images will be converted.
40
+ - RGB = 1
41
+ - BGR = 2
42
+ - GRAY = 3
43
+ - RGBA = 4
44
+ """
45
+
46
+ target_color_space: ImageColor
47
+
48
+ def execute(self, container: DataContainer) -> DataContainer:
49
+ """Executes the color space conversion on all image packets within the provided DataContainer.
50
+
51
+ Args:
52
+ container (DataContainer): The DataContainer containing the image packets to be processed.
53
+
54
+ Returns:
55
+ DataContainer: The DataContainer with all image packets converted to the target color space.
56
+ """
57
+ new_image_packets = [
58
+ convert_color_space(image_packet, self.attributes.target_color_space) for image_packet in container.images
59
+ ]
60
+
61
+ container.images = new_image_packets
62
+ return container
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sinapsis-generic-data-tools
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Collection of generic data tools
5
5
  Author-email: SinapsisAI <dev@sinapsis.tech>
6
6
  License: GNU AFFERO GENERAL PUBLIC LICENSE
@@ -665,6 +665,148 @@ License: GNU AFFERO GENERAL PUBLIC LICENSE
665
665
  For more information on this, and how to apply and follow the GNU AGPL, see
666
666
  <https://www.gnu.org/licenses/>.
667
667
 
668
+ Project-URL: Homepage, https://sinapsis.tech
669
+ Project-URL: Documentation, https://docs.sinapsis.tech/docs
670
+ Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
671
+ Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis-data-tools.git
668
672
  Requires-Python: >=3.10
669
673
  Description-Content-Type: text/markdown
674
+ Requires-Dist: requests>=2.32.3
670
675
  Requires-Dist: sinapsis>=0.1.1
676
+
677
+ <h1 align="center">
678
+ <br>
679
+ <a href="https://sinapsis.tech/">
680
+ <img
681
+ src="https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/logo.png?raw=true"
682
+ alt="" width="300">
683
+ </a>
684
+
685
+ <br>
686
+ Sinapsis Generic Data Tools
687
+ <br>
688
+ </h1>
689
+
690
+ <h4 align="center"> Package with generic data tools for image color conversion, buffering of data packets and other useful tools for handling data</h4>
691
+
692
+ <p align="center">
693
+ <a href="#installation">🐍 Installation</a> •
694
+ <a href="#documentation">📙 Documentation</a> •
695
+ <a href="#license">🔍 License</a>
696
+ </p>
697
+
698
+ <h2 id="installation">🐍 Installation</h2>
699
+
700
+
701
+ Install using your package manager of choice. We encourage the use of <code>uv</code>
702
+
703
+ Example with <code>uv</code>:
704
+
705
+ ```bash
706
+ uv pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
707
+ ```
708
+ or with raw <code>pip</code>:
709
+ ```bash
710
+ pip install sinapsis-generic-data-tools --extra-index-url https://pypi.sinapsis.tech
711
+ ```
712
+
713
+ > [!IMPORTANT]
714
+ > Templates in each package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:
715
+ >
716
+
717
+ with <code>uv</code>:
718
+
719
+ ```bash
720
+ uv pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
721
+ ```
722
+ or with raw <code>pip</code>:
723
+ ```bash
724
+ pip install sinapsis-generic-data-tools[all] --extra-index-url https://pypi.sinapsis.tech
725
+ ```
726
+
727
+
728
+
729
+ > [!TIP]
730
+ > Use CLI command ``` sinapsis info --all-template-names``` to show a list with all the available Template names installed with Sinapsis Data Tools.
731
+
732
+ > [!TIP]
733
+ > Use CLI command ```sinapsis info --example-template-config TEMPLATE_NAME``` to produce an example Agent config for the Template specified in ***TEMPLATE_NAME***.
734
+
735
+ For example, for ***ColorConversion*** use ```sinapsis info --example-template-config ImageColorConversion``` to produce the following example config:
736
+
737
+
738
+ ```yaml
739
+ agent:
740
+ name: my_test_agent
741
+ templates:
742
+ - template_name: InputTemplate
743
+ class_name: InputTemplate
744
+ attributes: {}
745
+ - template_name: ImageColorConversion
746
+ class_name: ImageColorConversion
747
+ template_input: InputTemplate
748
+ attributes:
749
+ target_color_space: 2
750
+ ```
751
+
752
+
753
+ <h2 id="usage">📚 Usage example</h2>
754
+ <details id='usage'><summary><strong><span style="font-size: 1.0em;"> Example agent config</span></strong></summary>
755
+ You can copy and paste the following config and run it using the sinapsis cli, changing the <code>data_dir</code> attribute in the <code>FolderImageDatasetCV2</code> and the <code>root_dir</code> attribute in the <code>ImageSaver</code> template
756
+
757
+ ```yaml
758
+ agent:
759
+ name: my_test_agent
760
+ description: agent to save image locally
761
+ templates:
762
+ - template_name: InputTemplate
763
+ class_name: InputTemplate
764
+ attributes: {}
765
+ - template_name: FolderImageDatasetCV2
766
+ class_name: FolderImageDatasetCV2
767
+ attributes:
768
+ data_dir: /path/to/image
769
+ pattern: '**/*'
770
+ batch_size: 1
771
+ load_on_init: true
772
+ label_path_index: 0
773
+ is_ground_truth: false
774
+ - template_name: ImageColorConversion
775
+ class_name: ImageColorConversion
776
+ template_input: FolderImageDatasetCV2
777
+ attributes:
778
+ target_color_space: 2
779
+ - template_name: ImageSaver
780
+ class_name: ImageSaver
781
+ template_input: ColorConversion
782
+ attributes:
783
+ save_dir: /path/to/save/dir
784
+ extension: jpg
785
+ root_dir: '/path/to/sinapsis/cache'
786
+ save_full_image: true
787
+ save_bbox_crops: false
788
+ save_mask_crops: false
789
+ min_bbox_dim: 5
790
+ ```
791
+ </details>
792
+ To run, simply use:
793
+
794
+ ```bash
795
+ sinapsis run name_of_the_config.yml
796
+ ```
797
+ **NOTE**: Make sure to update the `data_dir` attribute in the `FolderImageDatasetCV2`, and the `save_dir` and `root_dir` attributes in the `ImageSaver` templates to actual directories
798
+
799
+ <h2 id="documentation">📙 Documentation</h2>
800
+
801
+ Documentation for this and other sinapsis packages is available on the [sinapsis website](https://docs.sinapsis.tech/docs)
802
+
803
+ Tutorials for different projects within sinapsis are available at [sinapsis tutorials page](https://docs.sinapsis.tech/tutorials)
804
+
805
+ <h2 id="license">🔍 License</h2>
806
+
807
+ This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the [LICENSE](LICENSE) file.
808
+
809
+ For commercial use, please refer to our [official Sinapsis website](https://sinapsis.tech) for information on obtaining a commercial license.
810
+
811
+
812
+
@@ -1,4 +1,5 @@
1
1
  LICENSE
2
+ README.md
2
3
  pyproject.toml
3
4
  src/sinapsis_generic_data_tools/__init__.py
4
5
  src/sinapsis_generic_data_tools.egg-info/PKG-INFO
@@ -7,7 +8,9 @@ src/sinapsis_generic_data_tools.egg-info/dependency_links.txt
7
8
  src/sinapsis_generic_data_tools.egg-info/requires.txt
8
9
  src/sinapsis_generic_data_tools.egg-info/top_level.txt
9
10
  src/sinapsis_generic_data_tools/helpers/__init__.py
10
- src/sinapsis_generic_data_tools/helpers/postprocess.py
11
+ src/sinapsis_generic_data_tools/helpers/file_downloader.py
12
+ src/sinapsis_generic_data_tools/helpers/image_color_space_converter.py
11
13
  src/sinapsis_generic_data_tools/templates/__init__.py
14
+ src/sinapsis_generic_data_tools/templates/image_color_conversion.py
12
15
  src/sinapsis_generic_data_tools/templates/mask_non_roi.py
13
16
  src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py
@@ -0,0 +1,2 @@
1
+ requests>=2.32.3
2
+ sinapsis>=0.1.1
@@ -1,33 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """This module provides utilities for cleaning and post-processing text."""
3
-
4
- import re
5
-
6
-
7
- def postprocess_text(input_text: str, pattern: str | None = None, keep_before: bool = True) -> str:
8
- """
9
- Cleans text by removing or splitting based on structured delimiters using a regex pattern.
10
-
11
- The default pattern detects:
12
- - `<| ... |>`: Matches anything inside `<|` and `|>`, often used in AI outputs.
13
- - `</ ... >`: Matches anything inside `</` and `>`, common in XML-like markup.
14
-
15
- Parameters:
16
- - response (str): The input string to be cleaned.
17
- - pattern (str, optional): A regex pattern to match delimiters. Defaults to handling `<|...|>` and `</...>`.
18
- - keep_before (bool, optional): If True, returns the portion before the first match;
19
- if False, returns the portion after the first match.
20
-
21
- Returns:
22
- - str: The cleaned response string.
23
- """
24
- if pattern is None:
25
- pattern = r"(<\|.*?\|>|</.*?>)"
26
-
27
- match = re.search(pattern, input_text)
28
-
29
- if match:
30
- split_index = match.start() if keep_before else match.end()
31
- return input_text[:split_index].strip() if keep_before else input_text[split_index:].strip()
32
-
33
- return input_text