Skip to content

Commit

Permalink
bugfix(finish_batch_add_annotation): fix parameter error
Browse files Browse the repository at this point in the history
  • Loading branch information
imhuwq committed Jan 4, 2024
1 parent 302d773 commit 33014fd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 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
5 changes: 4 additions & 1 deletion 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 Expand Up @@ -148,7 +151,7 @@ def pre_run(self):
self.format_data()

def __iter__(self) -> Tuple[Dict, List[Dict]]:
for coco_image_data in self._images:
for coco_image_data in self._images[:1000000]:
# data_sample = {"license" : 2,
# "file_name" : "000000000139.jpg",
# "coco_url" : "http://images.cocodataset.org/val2017/000000000139.jpg",
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 33014fd

Please sign in to comment.