1
- import logging
2
1
import os
3
2
import shutil
4
3
import warnings
5
4
from itertools import compress
6
5
import numpy as np
7
-
8
- from rich .logging import RichHandler
9
6
from tqdm import tqdm
10
-
11
7
from .calculations import calculate_kmeans , calculate_pca , get_embeddings
12
8
from .utils import (
13
9
create_dir ,
14
10
create_image_grid ,
15
11
read_images_from_directory ,
16
12
read_with_pil ,
17
13
)
14
+ from .logger import info , error
18
15
19
16
warnings .filterwarnings ("ignore" )
20
17
21
18
22
- # Configure logging
23
- LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
24
- logging .basicConfig (
25
- level = "INFO" , format = LOG_FORMAT , datefmt = "[%X]" , handlers = [RichHandler ()]
26
- )
27
-
28
-
29
19
class Tasnif :
30
20
def __init__ (self , num_classes , pca_dim = 16 , use_gpu = False ):
31
21
self .num_classes = num_classes
@@ -93,16 +83,13 @@ def export(self, output_folder="./"):
93
83
try :
94
84
shutil .copy2 (img_path , target_directory )
95
85
except Exception as e :
96
- logging .error (
97
- f"Error copying { img_path } to { target_directory } : { e } "
98
- )
86
+ error (f"Error copying { img_path } to { target_directory } : { e } " )
99
87
100
88
# Create an image grid for the current label
101
89
label_images = list (compress (self .images , label_mask ))
102
90
create_image_grid (label_images , project_path , label_number )
103
91
104
- logging .info (f"Exported images and grids to { project_path } " )
105
-
92
+ info (f"Exported images and grids to { project_path } " )
106
93
107
94
def export_embeddings (self , output_folder = "./" ):
108
95
"""
@@ -111,11 +98,10 @@ def export_embeddings(self, output_folder="./"):
111
98
Parameters:
112
99
- output_folder (str): The directory to export the embeddings into.
113
100
"""
114
-
101
+
115
102
if self .embeddings is None :
116
103
raise ValueError ("Embeddings can not be empty. Please call the calculate method first." )
117
-
118
-
104
+
119
105
embeddings_path = os .path .join (output_folder , f"{ self .project_name } _embeddings.npy" )
120
106
np .save (embeddings_path , self .embeddings )
121
- logging . info (f"Embeddings have been saved to { embeddings_path } " )
107
+ info (f"Embeddings have been saved to { embeddings_path } " )
0 commit comments