Skip to content
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
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,3 @@ To generate a `requirements.txt` for usage outside of `pipenv`
```sh
pipenv lock -r > requirements.txt
```

## Publishing docs

```sh
./build-docs.sh
```
2 changes: 1 addition & 1 deletion labelbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"The Labelbox python package."

__version__ = '0.0.8'
__version__ = '1.0.0'
4 changes: 2 additions & 2 deletions labelbox/exporters/coco_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def add_label(
"coco_url": image_url,
"date_captured": None,
}
response = requests.get(image_url, stream=True, timeout=0.1)
response = requests.get(image_url, stream=True, timeout=1.0)
response.raw.decode_content = True
image['width'], image['height'] = Image.open(response.raw).size

Expand Down Expand Up @@ -127,7 +127,7 @@ def _append_polygons_as_annotations(coco, image, category_id, polygons):
for polygon in polygons:
segmentation = []
for x_val, y_val in polygon.exterior.coords:
segmentation.extend([x_val, image['height'] - y_val])
segmentation.extend([x_val, y_val])

annotation = {
"id": len(coco['annotations']) + 1,
Expand Down
19 changes: 8 additions & 11 deletions labelbox/exporters/voc_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def write_label( # pylint: disable-msg=too-many-arguments
images_output_dir: File path of directory to write images.
"""
# Download image and save it
response = requests.get(image_url, stream=True)
response = requests.get(image_url, stream=True, timeout=1.0)
response.raw.decode_content = True
image = Image.open(response.raw)
image_fqn = os.path.join(
Expand All @@ -99,12 +99,9 @@ def write_label( # pylint: disable-msg=too-many-arguments
for category_name, paths in labels.items():
if label_format == 'WKT':
xml_writer = _add_pascal_object_from_wkt(
xml_writer, img_height=height, wkt_data=paths,
label=category_name)
xml_writer, wkt_data=paths, label=category_name)
elif label_format == 'XY':
xml_writer = _add_pascal_object_from_xy(
xml_writer, img_height=height, polygons=paths,
label=category_name)
xml_writer = _add_pascal_object_from_xy(xml_writer, polygons=paths, label=category_name)
else:
exc = UnknownFormatError(label_format=label_format)
logging.exception(exc.message)
Expand All @@ -114,7 +111,7 @@ def write_label( # pylint: disable-msg=too-many-arguments
xml_writer.save(os.path.join(annotations_output_dir, '{}.xml'.format(label_id)))


def _add_pascal_object_from_wkt(xml_writer, img_height, wkt_data, label):
def _add_pascal_object_from_wkt(xml_writer, wkt_data, label):
polygons = []
if isinstance(wkt_data, list): # V3+
polygons = map(lambda x: wkt.loads(x['geometry']), wkt_data)
Expand All @@ -124,17 +121,17 @@ def _add_pascal_object_from_wkt(xml_writer, img_height, wkt_data, label):
for point in polygons:
xy_coords = []
for x_val, y_val in point.exterior.coords:
xy_coords.extend([x_val, img_height - y_val])
xy_coords.extend([x_val, y_val])
# remove last polygon if it is identical to first point
if xy_coords[-2:] == xy_coords[:2]:
xy_coords = xy_coords[:-2]
xml_writer.add_object(name=label, xy_coords=xy_coords)
return xml_writer


def _add_pascal_object_from_xy(xml_writer, img_height, polygons, label):
def _add_pascal_object_from_xy(xml_writer, polygons, label):
if not isinstance(polygons, list):
# polygons is not [{'geometry': [xy]}] nor [[xy]]
LOGGER.warning('polygons is not [{geometry: [xy]}] nor [[xy]], skipping')
return xml_writer
for polygon in polygons:
if 'geometry' in polygon: # V3
Expand All @@ -146,6 +143,6 @@ def _add_pascal_object_from_xy(xml_writer, img_height, polygons, label):

xy_coords = []
for point in polygon:
xy_coords.extend([point['x'], img_height - point['y']])
xy_coords.extend([point['x'], point['y']])
xml_writer.add_object(name=label, xy_coords=xy_coords)
return xml_writer