mstutils 0.1.0__tar.gz → 0.2.0__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.
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.3
2
+ Name: mstutils
3
+ Version: 0.2.0
4
+ Summary: This package contains some useful functions for image processing and torch gpu releasing. To run in Google Colab
5
+ Author: mstytn
6
+ Author-email: mstytn <mustafayatagan@gmail.com>
7
+ Requires-Dist: pillow>=10.0.0
8
+ Requires-Dist: requests>=2.31.0
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+
12
+ # mstutils
13
+
14
+ A lightweight personal utility package designed primarily for Google Colab workflows. It provides quick helpers for PyTorch GPU memory cleanup and batch image handling (loading from local paths, directories, or URLs, and saving results).
15
+
16
+ >[!IMPORTANT]
17
+ > **Note:** This package is tailored for personal research and Colab notebooks. Breaking changes may occur without notice.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install mstutils
23
+
24
+ ```
25
+
26
+ To upgrade to the latest release in Google Colab:
27
+
28
+ ```bash
29
+
30
+ pip install -q --upgrade mstutils
31
+
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### GPU Memory Cleanup
37
+
38
+ Clears Python garbage collection and empties the PyTorch CUDA cache if a GPU is available:
39
+
40
+ ```python
41
+ from mstutils import Performance
42
+
43
+ Performance.clear_gpu_memory()
44
+
45
+ ```
46
+
47
+ ### Image Helpers
48
+
49
+ Load, manage, and export PIL images easily:
50
+
51
+ ```python
52
+ from mstutils import ImageHelpers
53
+
54
+ helper = ImageHelpers()
55
+
56
+ # Load from a URL
57
+ helper.load_image_from_url("[https://example.com/sample.jpg](https://example.com/sample.jpg)")
58
+
59
+ # Load a single image or a list of paths
60
+ helper.load_image_from_disk("./input.png")
61
+ stats = helper.load_images_from_path(["./a.jpg", "./b.png"])
62
+
63
+ # Load all matching images from a directory
64
+ helper.load_images_from_disk(path="./images/", extensions=["jpg", "png"])
65
+
66
+ # Save all stored images sequentially (0.png, 1.png, ...)
67
+ helper.save_images(path="./output/")
68
+
69
+ ```
70
+
71
+ ## Requirements
72
+
73
+ * Python `>=3.10`
74
+ * `pillow >= 10.0.0`
75
+ * `requests >= 2.31.0`
76
+ * `torch` *(optional, required only for `Performance.clear_gpu_memory()`)*
@@ -0,0 +1,65 @@
1
+ # mstutils
2
+
3
+ A lightweight personal utility package designed primarily for Google Colab workflows. It provides quick helpers for PyTorch GPU memory cleanup and batch image handling (loading from local paths, directories, or URLs, and saving results).
4
+
5
+ >[!IMPORTANT]
6
+ > **Note:** This package is tailored for personal research and Colab notebooks. Breaking changes may occur without notice.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install mstutils
12
+
13
+ ```
14
+
15
+ To upgrade to the latest release in Google Colab:
16
+
17
+ ```bash
18
+
19
+ pip install -q --upgrade mstutils
20
+
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### GPU Memory Cleanup
26
+
27
+ Clears Python garbage collection and empties the PyTorch CUDA cache if a GPU is available:
28
+
29
+ ```python
30
+ from mstutils import Performance
31
+
32
+ Performance.clear_gpu_memory()
33
+
34
+ ```
35
+
36
+ ### Image Helpers
37
+
38
+ Load, manage, and export PIL images easily:
39
+
40
+ ```python
41
+ from mstutils import ImageHelpers
42
+
43
+ helper = ImageHelpers()
44
+
45
+ # Load from a URL
46
+ helper.load_image_from_url("[https://example.com/sample.jpg](https://example.com/sample.jpg)")
47
+
48
+ # Load a single image or a list of paths
49
+ helper.load_image_from_disk("./input.png")
50
+ stats = helper.load_images_from_path(["./a.jpg", "./b.png"])
51
+
52
+ # Load all matching images from a directory
53
+ helper.load_images_from_disk(path="./images/", extensions=["jpg", "png"])
54
+
55
+ # Save all stored images sequentially (0.png, 1.png, ...)
56
+ helper.save_images(path="./output/")
57
+
58
+ ```
59
+
60
+ ## Requirements
61
+
62
+ * Python `>=3.10`
63
+ * `pillow >= 10.0.0`
64
+ * `requests >= 2.31.0`
65
+ * `torch` *(optional, required only for `Performance.clear_gpu_memory()`)*
@@ -1,16 +1,16 @@
1
- [project]
2
- name = "mstutils"
3
- version = "0.1.0"
4
- description = "This package contains some useful functions for image processing and torch gpu releasing. To run in Google Colab"
5
- readme = "README.md"
6
- authors = [
7
- { name = "mstytn", email = "mustafayatagan@gmail.com" }
8
- ]
9
- requires-python = ">=3.10"
10
- dependencies = [
11
- "pillow>=10.0.0",
12
- "requests>=2.31.0",
13
- ]
14
- [build-system]
15
- requires = ["uv_build>=0.10.12,<0.11.0"]
1
+ [project]
2
+ name = "mstutils"
3
+ version = "0.2.0"
4
+ description = "This package contains some useful functions for image processing and torch gpu releasing. To run in Google Colab"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "mstytn", email = "mustafayatagan@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "pillow>=10.0.0",
12
+ "requests>=2.31.0",
13
+ ]
14
+ [build-system]
15
+ requires = ["uv_build>=0.10.12,<0.11.0"]
16
16
  build-backend = "uv_build"
@@ -0,0 +1,19 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class cc(StrEnum):
5
+ HEADER = '\033[95m'
6
+ OKBLUE = '\033[94m'
7
+ OKCYAN = '\033[96m'
8
+ OKGREEN = '\033[92m'
9
+ WARNING = '\033[93m'
10
+ FAIL = '\033[91m'
11
+ E = '\033[0m'
12
+ BOLD = '\033[1m'
13
+ UNDERLINE = '\033[4m'
14
+
15
+ def setup_plt() -> None:
16
+ import matplotlib.pyplot as plt
17
+ plt.style.use('dark_background')
18
+ plt.rcParams['figure.facecolor'] = '#27292b'
19
+ plt.rcParams['axes.facecolor'] = '#27292b'
@@ -72,4 +72,26 @@ class ImageHelpers:
72
72
  def load_image_from_disk(self, path: str) -> None:
73
73
  """Loads a single image from disk."""
74
74
  with self._Image.open(path) as img:
75
- self.images.append(img.copy())
75
+ self.images.append(img.copy())
76
+
77
+
78
+ class ImagePlotter():
79
+ def __init__(self, cols: int = 3):
80
+ self.cols = cols
81
+ self.rows = 1
82
+
83
+ def plot_images(self, images: list[Image.Image]):
84
+ if len(images) == 0:
85
+ return
86
+ self.cols = min(self.cols, len(images))
87
+ if len(images) % self.cols == 0:
88
+ self.rows = len(images) // self.cols
89
+ else:
90
+ self.rows = len(images) // self.cols + 1
91
+ fig, ax = plt.subplots(self.rows, self.cols, figsize=(15, 15))
92
+ for i, ax in enumerate(ax.flatten()):
93
+ ax.axis('off')
94
+ try:
95
+ ax.imshow(images[i])
96
+ except IndexError as _e:
97
+ break
@@ -0,0 +1,30 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class CudaInfo:
6
+ DEVICE: str
7
+ CUDA_VERSION: str
8
+ TORC_VERSION: str
9
+
10
+ class Performance:
11
+ @staticmethod
12
+ def clear_gpu_memory() -> None:
13
+ """Clears PyTorch CUDA cache and runs garbage collection."""
14
+ import gc
15
+ import torch
16
+
17
+ gc.collect()
18
+ if torch.cuda.is_available():
19
+ torch.cuda.empty_cache()
20
+ @staticmethod
21
+ def get_cuda_info() -> CudaInfo:
22
+ """Gets cuda information and torch versions"""
23
+ return CudaInfo(
24
+ DEVICE=torch.cuda.get,
25
+ CUDA_VERSION=torch.version.cuda,
26
+ TORC_VERSION=torch.__version__
27
+ )
28
+
29
+
30
+
mstutils-0.1.0/PKG-INFO DELETED
@@ -1,11 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: mstutils
3
- Version: 0.1.0
4
- Summary: This package contains some useful functions for image processing and torch gpu releasing. To run in Google Colab
5
- Author: mstytn
6
- Author-email: mstytn <mustafayatagan@gmail.com>
7
- Requires-Dist: pillow>=10.0.0
8
- Requires-Dist: requests>=2.31.0
9
- Requires-Python: >=3.10
10
- Description-Content-Type: text/markdown
11
-
mstutils-0.1.0/README.md DELETED
File without changes
@@ -1,10 +0,0 @@
1
- class Performance:
2
- @staticmethod
3
- def clear_gpu_memory() -> None:
4
- """Clears PyTorch CUDA cache and runs garbage collection."""
5
- import gc
6
- import torch
7
-
8
- gc.collect()
9
- if torch.cuda.is_available():
10
- torch.cuda.empty_cache()
File without changes