From 73c97000235fda8ca988f20df5c57fdf4bf2f40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Thu, 27 Mar 2025 17:29:30 +0100 Subject: [PATCH] Fixing problem in regions annotations given as a list --- HISTORY.rst | 5 +++++ bigml/api_handlers/sourcehandler.py | 11 +++-------- bigml/bigmlconnection.py | 11 +++++------ bigml/tests/test_22_source_args.py | 6 ++++-- bigml/version.py | 2 +- data/images/annotations_list.json | 2 ++ data/images/metadata_list.json | 5 +++++ 7 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 data/images/annotations_list.json create mode 100644 data/images/metadata_list.json diff --git a/HISTORY.rst b/HISTORY.rst index 63308907..6c85c8cd 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,11 @@ History ------- +9.8.3 (2025-03-27) +------------------ + +- Fixing annotations update for regions as lists. + 9.8.2 (2025-03-21) ------------------ diff --git a/bigml/api_handlers/sourcehandler.py b/bigml/api_handlers/sourcehandler.py index 71863b34..bd4b6e6b 100644 --- a/bigml/api_handlers/sourcehandler.py +++ b/bigml/api_handlers/sourcehandler.py @@ -61,19 +61,14 @@ HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED, HTTP_PAYMENT_REQUIRED, HTTP_NOT_FOUND, HTTP_TOO_MANY_REQUESTS, - HTTP_INTERNAL_SERVER_ERROR, GAE_ENABLED, SEND_JSON) + HTTP_INTERNAL_SERVER_ERROR, GAE_ENABLED, SEND_JSON, LOGGER) from bigml.bigmlconnection import json_load from bigml.api_handlers.resourcehandler import check_resource_type, \ resource_is_ready, get_source_id, get_id from bigml.constants import SOURCE_PATH, IMAGE_EXTENSIONS -from bigml.api_handlers.resourcehandler import ResourceHandlerMixin, LOGGER +from bigml.api_handlers.resourcehandler import ResourceHandlerMixin from bigml.fields import Fields -LOG_FORMAT = '%(asctime)-15s: %(message)s' -LOGGER = logging.getLogger('BigML') -CONSOLE = logging.StreamHandler() -CONSOLE.setLevel(logging.WARNING) -LOGGER.addHandler(CONSOLE) MAX_CHANGES = 5 MAX_RETRIES = 5 @@ -548,7 +543,7 @@ def update_composite_annotations(self, source, images_file, "components": source_ids}) elif optype == "regions": for value, source_id in values: - if isinstance(value, dict): + if isinstance(value, list): # dictionary should contain the bigml-coco format value = compact_regions(value) changes.append( diff --git a/bigml/bigmlconnection.py b/bigml/bigmlconnection.py index c1b337f0..1e680915 100644 --- a/bigml/bigmlconnection.py +++ b/bigml/bigmlconnection.py @@ -50,7 +50,7 @@ LOG_FORMAT = '%(asctime)-15s: %(message)s' LOGGER = logging.getLogger('BigML') -CONSOLE = logging.StreamHandler() +CONSOLE = logging.StreamHandler(sys.stdout) CONSOLE.setLevel(logging.WARNING) LOGGER.addHandler(CONSOLE) @@ -138,7 +138,7 @@ def debug_request(method, url, **kwargs): """ response = original_request(method, url, **kwargs) - logging.debug("Data: %s", response.request.body) + LOGGER.debug("Data: %s", response.request.body) try: response_content = "Download status is %s" % response.status_code \ if "download" in url else \ @@ -147,7 +147,7 @@ def debug_request(method, url, **kwargs): response_content = response.content response_content = response_content[0: 256] if short_debug else \ response_content - logging.debug("Response: %s\n", response_content) + LOGGER.debug("Response: %s\n", response_content) return response original_request = requests.api.request @@ -213,9 +213,8 @@ def __init__(self, username=None, api_key=None, # when using GAE will fail pass - logging.basicConfig(format=LOG_FORMAT, - level=logging_level, - stream=sys.stdout) + LOGGER.forma = LOG_FORMAT, + LOGGER.level = logging_level if username is None: try: diff --git a/bigml/tests/test_22_source_args.py b/bigml/tests/test_22_source_args.py index 8fe3567e..b66edc9e 100644 --- a/bigml/tests/test_22_source_args.py +++ b/bigml/tests/test_22_source_args.py @@ -126,7 +126,7 @@ def test_scenario3(self): source_create.the_source_is_finished( self, example["source_wait"]) source_create.the_cloned_source_origin_is(self, source) - + def test_scenario4(self): """ Scenario: Successfully adding annotatations to composite source: @@ -142,6 +142,8 @@ def test_scenario4(self): ['data/images/metadata.json', '500', '500', '12', '100002'], ['data/images/metadata_compact.json', '500', '500', '3', + '100003'], + ['data/images/metadata_list.json', '500', '500', '3', '100003']] show_doc(self.test_scenario4) for example in examples: @@ -157,7 +159,7 @@ def test_scenario4(self): dataset_create.i_create_a_dataset(self) dataset_create.the_dataset_is_finished_in_less_than( self, example["dataset_wait"]) - dataset_create.check_annotations(self, + dataset_create.check_annotations(self, example["annotations_field"], example["annotations_num"]) diff --git a/bigml/version.py b/bigml/version.py index 977225b8..68512901 100644 --- a/bigml/version.py +++ b/bigml/version.py @@ -1 +1 @@ -__version__ = '9.8.2' +__version__ = '9.8.3' diff --git a/data/images/annotations_list.json b/data/images/annotations_list.json new file mode 100644 index 00000000..ecfee3db --- /dev/null +++ b/data/images/annotations_list.json @@ -0,0 +1,2 @@ +[{"file": "f1/fruits1f.png", "my_regions": [{"label": "region1", "xmin": 0.2, "ymin": 0.2, "xmax": 0.4, "ymax": 0.4}]}, + {"file": "f1/fruits1.png", "my_regions": [{"label": "region2", "xmin": 0.2, "ymin": 0.2, "xmax": 0.4, "ymax": 0.4}, {"label": "region1", "xmin": 0.5, "ymin": 0.5, "xmax": 0.7, "ymax": 0.7}]}] diff --git a/data/images/metadata_list.json b/data/images/metadata_list.json new file mode 100644 index 00000000..1bf61c67 --- /dev/null +++ b/data/images/metadata_list.json @@ -0,0 +1,5 @@ +{"description": "Fruit images to test colour distributions with regions", + "images_file": "./fruits_hist.zip", + "new_fields": [{"name": "my_regions", "optype": "regions"}], + "source_id": null, + "annotations": "./annotations_list.json"}