Skip to content

Commit bcb9217

Browse files
authored
Merge pull request #19 from aperture-data/bbox_labels
Fixes for new API
2 parents c6be28a + 64c7a28 commit bcb9217

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

aperturedb/BBoxLoader.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,14 @@ def generate_batch(self, bbox_data):
136136
}
137137

138138
if "properties" in data:
139-
ai["AddBoundingBox"]["properties"] = data[CSVParser.PROPERTIES]
139+
props = data[CSVParser.PROPERTIES]
140+
if "_label" in props:
141+
ai["AddBoundingBox"]["label"] = props["_label"]
142+
props.pop("_label")
143+
144+
# Check if props is not empty after removing "_label"
145+
if props:
146+
ai["AddBoundingBox"]["properties"] = props
140147

141148
q.append(ai)
142149

aperturedb/Images.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from matplotlib.collections import PatchCollection
1212
from matplotlib.patches import Polygon
1313

14+
from aperturedb import Status
15+
1416
class Constraints(object):
1517

1618
def __init__(self):
@@ -88,7 +90,7 @@ def __init__(self, db, batch_size=100):
8890
self.display_limit = 20
8991

9092
self.img_id_prop = "_uniqueid"
91-
self.bbox_label_prop = "label"
93+
self.bbox_label_prop = "_label"
9294

9395
def __retrieve_batch(self, index):
9496

@@ -152,15 +154,19 @@ def __get_bounding_boxes_polygons(self, index):
152154
"blobs": False,
153155
}
154156
}, {
155-
"FindEntity": {
157+
"FindBlob": {
156158
"is_connected_to": {
157159
"ref": 1
158160
},
161+
"constraints": {
162+
"type": ["==", "segmentation"]
163+
},
159164
"blobs": True,
160165
}
161166
}]
162167

163168
res, polygons = self.db_connector.query(query)
169+
164170
ret_poly.append(polygons)
165171

166172
uniqueid_str = str(uniqueid)
@@ -225,9 +231,7 @@ def __retrieve_bounding_boxes(self, index):
225231
"_ref": 2,
226232
"blobs": False,
227233
"coordinates": True,
228-
"results": {
229-
"list": [self.bbox_label_prop],
230-
}
234+
"labels": True,
231235
}
232236
}]
233237

@@ -458,18 +462,12 @@ def display(self, show_bboxes=False, show_segmentation=False, limit=None):
458462

459463
def get_props_names(self):
460464

461-
query = [ {
462-
"GetSchema": {
463-
"type" : "entities"
464-
}
465-
}]
466-
467-
res, images = self.db_connector.query(query)
465+
status = Status.Status(self.db_connector)
466+
schema = status.get_schema()
468467

469468
try:
470-
dictio = res[0]["FindImageInfo"]["entities"]["classes"][0]["_Image"]
471-
search_key = "VD:" # TODO WHAT IS THIS?
472-
props_array = [key for key, val in dictio.items() if not search_key in key]
469+
dictio = schema["entities"]["classes"]["_Image"]["properties"]
470+
props_array = [key for key, val in dictio.items()]
473471
except:
474472
props_array = []
475473
print("Cannot retrieve properties")

aperturedb/Status.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ def status(self):
2323

2424
return self.connector.get_last_response_str()
2525

26+
def get_schema(self, refresh=False):
27+
28+
query = [ {
29+
"GetSchema": {
30+
"type" : "entities",
31+
"refresh": refresh,
32+
}
33+
}]
34+
35+
res, blobs = self.connector.query(query)
36+
37+
schema = {}
38+
39+
try:
40+
schema = res[0]["GetSchema"]
41+
except:
42+
print("Cannot retrieve schema")
43+
print(self.connector.get_last_response_str())
44+
45+
return schema
46+
2647
def count_images(self, constraints={}):
2748

2849
q = [{

0 commit comments

Comments
 (0)