Skip to content

Commit

Permalink
Merge pull request #98 from robert-graf/main
Browse files Browse the repository at this point in the history
Fix Verbose and make Citation Reminder only appeare once
  • Loading branch information
neuronflow authored Apr 18, 2024
2 parents 06a37e9 + e9976b3 commit 0d7e0c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
23 changes: 15 additions & 8 deletions panoptica/panoptic_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def evaluate(
decision_threshold=self.__decision_threshold,
result_all=result_all,
log_times=self.__log_times,
verbose=self.__verbose if verbose is None else verbose,
verbose=True if verbose is None else verbose,
verbose_calc=self.__verbose if verbose is None else verbose,
)


Expand All @@ -98,7 +99,8 @@ def panoptic_evaluate(
edge_case_handler: EdgeCaseHandler | None = None,
log_times: bool = False,
result_all: bool = True,
verbose: bool = False,
verbose=False,
verbose_calc=False,
**kwargs,
) -> tuple[PanopticaResult, dict[str, _ProcessingPair]]:
"""
Expand Down Expand Up @@ -128,14 +130,16 @@ def panoptic_evaluate(
>>> panoptic_evaluate(SemanticPair(...), instance_approximator=InstanceApproximator(), iou_threshold=0.6)
(PanopticaResult(...), {'UnmatchedInstanceMap': _ProcessingPair(...), 'MatchedInstanceMap': _ProcessingPair(...)})
"""
print("Panoptic: Start Evaluation")
if verbose:
print("Panoptic: Start Evaluation")
if edge_case_handler is None:
# use default edgecase handler
edge_case_handler = EdgeCaseHandler()
debug_data: dict[str, _ProcessingPair] = {}
# First Phase: Instance Approximation
if isinstance(processing_pair, PanopticaResult):
print("-- Input was Panoptic Result, will just return")
if verbose:
print("-- Input was Panoptic Result, will just return")
return processing_pair, debug_data

# Crops away unecessary space of zeroes
Expand All @@ -145,7 +149,8 @@ def panoptic_evaluate(
assert (
instance_approximator is not None
), "Got SemanticPair but not InstanceApproximator"
print("-- Got SemanticPair, will approximate instances")
if verbose:
print("-- Got SemanticPair, will approximate instances")
start = perf_counter()
processing_pair = instance_approximator.approximate_instances(processing_pair)
if log_times:
Expand All @@ -161,7 +166,8 @@ def panoptic_evaluate(
)

if isinstance(processing_pair, UnmatchedInstancePair):
print("-- Got UnmatchedInstancePair, will match instances")
if verbose:
print("-- Got UnmatchedInstancePair, will match instances")
assert (
instance_matcher is not None
), "Got UnmatchedInstancePair but not InstanceMatchingAlgorithm"
Expand All @@ -183,7 +189,8 @@ def panoptic_evaluate(
)

if isinstance(processing_pair, MatchedInstancePair):
print("-- Got MatchedInstancePair, will evaluate instances")
if verbose:
print("-- Got MatchedInstancePair, will evaluate instances")
start = perf_counter()
processing_pair = evaluate_matched_instance(
processing_pair,
Expand All @@ -197,7 +204,7 @@ def panoptic_evaluate(

if isinstance(processing_pair, PanopticaResult):
if result_all:
processing_pair.calculate_all(print_errors=verbose)
processing_pair.calculate_all(print_errors=verbose_calc)
return processing_pair, debug_data

raise RuntimeError("End of panoptic pipeline reached without results")
Expand Down
3 changes: 2 additions & 1 deletion panoptica/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"-- {func.__name__} took {elapsed_time} seconds to execute.")
if hasattr(kwargs, "verbose") and getattr(kwargs, "verbose"):
print(f"-- {func.__name__} took {elapsed_time} seconds to execute.")
return result

return wrapper
3 changes: 2 additions & 1 deletion panoptica/utils/citation_reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def wrapper(*args, **kwargs):
console = Console()
console.rule("Thank you for using [bold]panoptica[/bold]")
console.print(
f"Please support our development by citing",
"Please support our development by citing",
justify="center",
)
console.print(
Expand All @@ -22,6 +22,7 @@ def wrapper(*args, **kwargs):
)
console.rule()
console.line()
os.environ["PANOPTICA_CITATION_REMINDER"] = "false" # Show only once
return func(*args, **kwargs)

return wrapper

0 comments on commit 0d7e0c4

Please sign in to comment.