Skip to content

Commit 01bf00a

Browse files
remove rich
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 4b1e08c commit 01bf00a

File tree

6 files changed

+12
-70
lines changed

6 files changed

+12
-70
lines changed

src/anomalib/engine/engine.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Any
1010

1111
import torch
12-
from lightning.pytorch.callbacks import Callback, RichModelSummary, RichProgressBar
12+
from lightning.pytorch.callbacks import Callback
1313
from lightning.pytorch.loggers import Logger
1414
from lightning.pytorch.trainer import Trainer
1515
from lightning.pytorch.utilities.types import _EVALUATE_OUTPUT, _PREDICT_OUTPUT, EVAL_DATALOADERS, TRAIN_DATALOADERS
@@ -407,7 +407,7 @@ def _setup_transform(
407407

408408
def _setup_anomalib_callbacks(self) -> None:
409409
"""Set up callbacks for the trainer."""
410-
_callbacks: list[Callback] = [RichProgressBar(), RichModelSummary()]
410+
_callbacks: list[Callback] = []
411411

412412
# Add ModelCheckpoint if it is not in the callbacks list.
413413
has_checkpoint_callback = any(isinstance(c, ModelCheckpoint) for c in self._cache.args["callbacks"])

src/anomalib/models/components/sampling/k_center_greedy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import torch
1111
from torch.nn import functional as F # noqa: N812
12+
from tqdm import tqdm
1213

1314
from anomalib.models.components.dimensionality_reduction import SparseRandomProjection
14-
from anomalib.utils.rich import safe_track
1515

1616

1717
class KCenterGreedy:
@@ -98,7 +98,7 @@ def select_coreset_idxs(self, selected_idxs: list[int] | None = None) -> list[in
9898

9999
selected_coreset_idxs: list[int] = []
100100
idx = int(torch.randint(high=self.n_observations, size=(1,)).item())
101-
for _ in safe_track(sequence=range(self.coreset_size), description="Selecting Coreset Indices."):
101+
for _ in tqdm(range(self.coreset_size), desc="Selecting Coreset Indices."):
102102
self.update_distances(cluster_centers=[idx])
103103
idx = self.get_new_idx()
104104
if idx in selected_idxs:

src/anomalib/pipelines/components/base/pipeline.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import yaml
1212
from jsonargparse import ArgumentParser, Namespace
13-
from rich import print, traceback
13+
from rich import traceback
1414

1515
from anomalib.utils.logging import redirect_logs
1616

@@ -66,9 +66,9 @@ def run(self, args: Namespace | None = None) -> None:
6666
except Exception: # noqa: PERF203 catch all exception and allow try-catch in loop
6767
logger.exception("An error occurred when running the runner.")
6868
print(
69-
f"There were some errors when running [red]{runner.generator.job_class.name}[/red] with"
70-
f" [green]{runner.__class__.__name__}[/green]."
71-
f" Please check [magenta]{log_file}[/magenta] for more details.",
69+
f"There were some errors when running {runner.generator.job_class.name} with"
70+
f" {runner.__class__.__name__}."
71+
f" Please check {log_file} for more details.",
7272
)
7373

7474
@staticmethod

src/anomalib/pipelines/components/runners/parallel.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
from concurrent.futures import ProcessPoolExecutor
99
from typing import TYPE_CHECKING
1010

11-
from rich import print
12-
from rich.progress import Progress, TaskID
13-
1411
from anomalib.pipelines.components.base import JobGenerator, Runner
1512
from anomalib.pipelines.types import GATHERED_RESULTS, PREV_STAGE_RESULT
1613

@@ -51,15 +48,11 @@ def __init__(self, generator: JobGenerator, n_jobs: int) -> None:
5148
super().__init__(generator)
5249
self.n_jobs = n_jobs
5350
self.processes: dict[int, Future | None] = {}
54-
self.progress = Progress()
55-
self.task_id: TaskID
5651
self.results: list[dict] = []
5752
self.failures = False
5853

5954
def run(self, args: dict, prev_stage_results: PREV_STAGE_RESULT = None) -> GATHERED_RESULTS:
6055
"""Run the job in parallel."""
61-
self.task_id = self.progress.add_task(self.generator.job_class.name, total=None)
62-
self.progress.start()
6356
self.processes = dict.fromkeys(range(self.n_jobs))
6457

6558
with ProcessPoolExecutor(max_workers=self.n_jobs, mp_context=multiprocessing.get_context("spawn")) as executor:
@@ -71,12 +64,10 @@ def run(self, args: dict, prev_stage_results: PREV_STAGE_RESULT = None) -> GATHE
7164
self.processes[index] = executor.submit(job.run, task_id=index)
7265
self._await_cleanup_processes(blocking=True)
7366

74-
self.progress.update(self.task_id, completed=1, total=1)
75-
self.progress.stop()
7667
gathered_result = self.generator.job_class.collect(self.results)
7768
self.generator.job_class.save(gathered_result)
7869
if self.failures:
79-
msg = f"[bold red]There were some errors with job {self.generator.job_class.name}[/bold red]"
70+
msg = f"There were some errors with job {self.generator.job_class.name}"
8071
print(msg)
8172
logger.error(msg)
8273
raise ParallelExecutionError(msg)
@@ -97,4 +88,3 @@ def _await_cleanup_processes(self, blocking: bool = False) -> None:
9788
logger.exception("An exception occurred while getting the process result.")
9889
self.failures = True
9990
self.processes[index] = None
100-
self.progress.update(self.task_id, advance=1)

src/anomalib/pipelines/components/runners/serial.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import logging
77

8-
from rich import print
9-
from rich.progress import track
8+
from tqdm import tqdm
109

1110
from anomalib.pipelines.components.base import JobGenerator, Runner
1211
from anomalib.pipelines.types import GATHERED_RESULTS, PREV_STAGE_RESULT
@@ -29,7 +28,7 @@ def run(self, args: dict, prev_stage_results: PREV_STAGE_RESULT = None) -> GATHE
2928
results = []
3029
failures = False
3130
logger.info(f"Running job {self.generator.job_class.name}")
32-
for job in track(self.generator(args, prev_stage_results), description=self.generator.job_class.name):
31+
for job in tqdm(self.generator(args, prev_stage_results), desc=self.generator.job_class.name):
3332
try:
3433
results.append(job.run())
3534
except Exception: # noqa: PERF203
@@ -38,7 +37,7 @@ def run(self, args: dict, prev_stage_results: PREV_STAGE_RESULT = None) -> GATHE
3837
gathered_result = self.generator.job_class.collect(results)
3938
self.generator.job_class.save(gathered_result)
4039
if failures:
41-
msg = f"[bold red]There were some errors with job {self.generator.job_class.name}[/bold red]"
40+
msg = f"There were some errors with job {self.generator.job_class.name}"
4241
print(msg)
4342
logger.error(msg)
4443
raise SerialExecutionError(msg)

src/anomalib/utils/rich.py

-47
This file was deleted.

0 commit comments

Comments
 (0)