Skip to content

Fixing problem in regions annotations given as a list #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
-------

9.8.3 (2025-03-27)
------------------

- Fixing annotations update for regions as lists.

9.8.2 (2025-03-21)
------------------

Expand Down
11 changes: 3 additions & 8 deletions bigml/api_handlers/sourcehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 5 additions & 6 deletions bigml/bigmlconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions bigml/tests/test_22_source_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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"])

2 changes: 1 addition & 1 deletion bigml/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '9.8.2'
__version__ = '9.8.3'
2 changes: 2 additions & 0 deletions data/images/annotations_list.json
Original file line number Diff line number Diff line change
@@ -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}]}]
5 changes: 5 additions & 0 deletions data/images/metadata_list.json
Original file line number Diff line number Diff line change
@@ -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"}