From 302d7734aead9a5aef315285f864df06f8e044c4 Mon Sep 17 00:00:00 2001 From: imhuwq Date: Tue, 2 Jan 2024 15:09:26 +0800 Subject: [PATCH 1/2] bugfix(config yaml): fix parsing verbose_log and quickstart configs --- deepdataspace/scripts/start.py | 2 +- deepdataspace/services/dds.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deepdataspace/scripts/start.py b/deepdataspace/scripts/start.py index 39c539c..788323b 100644 --- a/deepdataspace/scripts/start.py +++ b/deepdataspace/scripts/start.py @@ -44,7 +44,7 @@ help="Set the http service port, default 8765.") @click.option("--reload", is_flag=True, default=None, help="Auto reload service on code change, for development only.") -@click.option("--configfile", +@click.option("--configfile", "-C", help="Load the target yaml file to initialize more configurations. " "The command line options take precedence of the config file.") def start_dds(data_dir, quickstart, verbose, public, host, port, reload, configfile): diff --git a/deepdataspace/services/dds.py b/deepdataspace/services/dds.py index 2390e24..e48d13a 100644 --- a/deepdataspace/services/dds.py +++ b/deepdataspace/services/dds.py @@ -66,10 +66,11 @@ def __init__(self, for key, val in config_data.items(): if val is not None: self.config_data[key] = val + print(f"reading config, {key} = {val}") self.data_dir = self.argument_or_config("data_dir", data_dir, None) - self.quickstart = self.argument_or_config("quickstart", quickstart, False) - self.verbose = self.argument_or_config("verbose", verbose, False) + self.quickstart = self.argument_or_config("quick_start", quickstart, False) + self.verbose = self.argument_or_config("verbose_log", verbose, False) self.public = public or False if host is None and public: host = get_output_ip_address() From 65ec16bf3ce93e1ea9a19034a880ac82d10ba877 Mon Sep 17 00:00:00 2001 From: imhuwq Date: Thu, 4 Jan 2024 10:21:14 +0800 Subject: [PATCH 2/2] bugfix(finish_batch_add_annotation): fix parameter error --- deepdataspace/model/image.py | 2 +- deepdataspace/plugins/coco2017/importer.py | 3 +++ deepdataspace/utils/function.py | 23 ++++++++++++++++++++++ requirements-dev.txt | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/deepdataspace/model/image.py b/deepdataspace/model/image.py index 24e5466..2840232 100644 --- a/deepdataspace/model/image.py +++ b/deepdataspace/model/image.py @@ -461,7 +461,7 @@ def batch_add_annotation(self, self.objects.append(anno_obj) def finish_batch_add_annotation(self): - self.dataset.batch_save_image(self) + self.dataset.batch_save_image() _image_models: Dict[str, Type[ImageModel]] = {} # a cache for ImageModel for each dataset diff --git a/deepdataspace/plugins/coco2017/importer.py b/deepdataspace/plugins/coco2017/importer.py index f50393e..1d4ba15 100644 --- a/deepdataspace/plugins/coco2017/importer.py +++ b/deepdataspace/plugins/coco2017/importer.py @@ -33,6 +33,9 @@ def __init__(self, meta_path: str, enforce: bool = False): self.meta_path = os.path.abspath(meta_path) info = self.parse_meta(meta_path) + if info is None: + raise RuntimeError(f"Cannot import coco dataset: {meta_path}") + dataset_name = info["dataset_name"] self.ground_truth = info["ground_truth"] self.image_root = info["image_root"] diff --git a/deepdataspace/utils/function.py b/deepdataspace/utils/function.py index ae5d9ad..8202c99 100644 --- a/deepdataspace/utils/function.py +++ b/deepdataspace/utils/function.py @@ -4,6 +4,8 @@ Convenient functions about python function. """ +import cProfile +import pstats import time from contextlib import contextmanager @@ -32,6 +34,27 @@ def count_block_time(block_id: str, logger=print): logger(f"time cost of block[{block_id}]: {end - start}ms") +@contextmanager +def profile_perf(report_file: str, turn_on: bool = True): + """ + Profile the performance of a code block, and save the result to report_file. + :param report_file: the target path where the performance data is saved to. + :param turn_on: only run the profile this is True or evaluates to True. + """ + profile = cProfile.Profile() + + if turn_on: + profile.enable() + + try: + yield + finally: + if turn_on is True: + profile.disable() + stats = pstats.Stats(profile).sort_stats("cumulative") + stats.dump_stats(report_file) + + def retry(times: int, sleep: int = 0, exceptions: tuple = (Exception,)): """ Retry a function or a method. diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c24060..c155d40 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,3 +3,4 @@ pytest==7.2.2 pytest-cov==4.0.0 Sphinx==5.3.0 sphinx-rtd-theme==1.2.0 +snakeviz==2.2.0