Skip to content

Commit

Permalink
Merge pull request #118 from IDEA-Research/bugfix/finish_batch_add_an…
Browse files Browse the repository at this point in the history
…notation

Bugfix/finish batch add annotation
  • Loading branch information
imhuwq authored Jan 4, 2024
2 parents 823daf0 + 65ec16b commit 3638c0c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deepdataspace/model/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions deepdataspace/plugins/coco2017/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion deepdataspace/scripts/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions deepdataspace/services/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions deepdataspace/utils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Convenient functions about python function.
"""

import cProfile
import pstats
import time
from contextlib import contextmanager

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3638c0c

Please sign in to comment.