mstutils 0.1.1__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.
- {mstutils-0.1.1 → mstutils-0.2.0}/PKG-INFO +1 -1
- {mstutils-0.1.1 → mstutils-0.2.0}/pyproject.toml +1 -1
- mstutils-0.2.0/src/mstutils/coloring.py +19 -0
- {mstutils-0.1.1 → mstutils-0.2.0}/src/mstutils/image.py +23 -1
- mstutils-0.2.0/src/mstutils/performance.py +30 -0
- mstutils-0.1.1/src/mstutils/performance.py +0 -10
- {mstutils-0.1.1 → mstutils-0.2.0}/README.md +0 -0
- {mstutils-0.1.1 → mstutils-0.2.0}/src/mstutils/__init__.py +0 -0
- {mstutils-0.1.1 → mstutils-0.2.0}/src/mstutils/py.typed +0 -0
|
@@ -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
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|