1- import logging
21import os
32import shutil
43import warnings
54from itertools import compress
65import numpy as np
7-
8- from rich .logging import RichHandler
96from tqdm import tqdm
10-
117from .calculations import calculate_kmeans , calculate_pca , get_embeddings
128from .utils import (
139 create_dir ,
1410 create_image_grid ,
1511 read_images_from_directory ,
1612 read_with_pil ,
1713)
14+ from .logger import info , error
1815
1916warnings .filterwarnings ("ignore" )
2017
2118
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-
2919class Tasnif :
3020 def __init__ (self , num_classes , pca_dim = 16 , use_gpu = False ):
3121 self .num_classes = num_classes
@@ -93,16 +83,13 @@ def export(self, output_folder="./"):
9383 try :
9484 shutil .copy2 (img_path , target_directory )
9585 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 } " )
9987
10088 # Create an image grid for the current label
10189 label_images = list (compress (self .images , label_mask ))
10290 create_image_grid (label_images , project_path , label_number )
10391
104- logging .info (f"Exported images and grids to { project_path } " )
105-
92+ info (f"Exported images and grids to { project_path } " )
10693
10794 def export_embeddings (self , output_folder = "./" ):
10895 """
@@ -111,11 +98,10 @@ def export_embeddings(self, output_folder="./"):
11198 Parameters:
11299 - output_folder (str): The directory to export the embeddings into.
113100 """
114-
101+
115102 if self .embeddings is None :
116103 raise ValueError ("Embeddings can not be empty. Please call the calculate method first." )
117-
118-
104+
119105 embeddings_path = os .path .join (output_folder , f"{ self .project_name } _embeddings.npy" )
120106 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