Skip to content

Commit

Permalink
Merge branch 'fix_bool_attributes'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alek-dr committed Nov 27, 2023
2 parents ab596e9 + 2b2da04 commit 5395331
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pascal_voc"
version = "2.1.5"
version = "2.1.7"
authors = [
{ name="Alexander Barmin", email="barmin1@mail.ru" },
]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Pillow>=10.0.0
transliterate>=1.10.2
typing_extensions>=4.1.0
xmlobj==1.2.0
xmlobj==1.2.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pascal_voc",
version="2.1.6",
version="2.1.7",
author="Alexander Barmin",
author_email="barmin1@mail.ru",
description="Tool to work with annotation formats",
Expand Down
239 changes: 237 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{"attr_name": "flickrid", "attr_val": "Fried Camels", "dtype": str},
{
"attr_name": "name",
"attr_val": "Jinky the Fruit Ba",
"attr_val": "Jinky the Fruit Bat",
"dtype": str,
},
],
Expand Down Expand Up @@ -80,7 +80,7 @@
"n_objects": 9,
"attributes": [
{"attr_name": "folder", "attr_val": "VOC2007", "dtype": str},
{"attr_name": "filename", "attr_val": "000001.jpg", "dtype": str},
{"attr_name": "filename", "attr_val": "000103.jpg", "dtype": str},
{
"attr_name": "source",
"attr_val": [
Expand Down Expand Up @@ -310,6 +310,241 @@
},
},
},
{
"file": "test_data/valid_annotations/bool_attributes.xml",
"n_objects": 6,
"attributes": [
{"attr_name": "folder", "attr_val": "test_attr", "dtype": str},
{"attr_name": "filename", "attr_val": "frame.jpg", "dtype": str},
{
"attr_name": "source",
"attr_val": [
{
"attr_name": "database",
"attr_val": "Unknown",
"dtype": str,
},
{
"attr_name": "annotation",
"attr_val": "Unknown",
"dtype": str,
},
{"attr_name": "image", "attr_val": "Unknown", "dtype": str},
],
},
{
"attr_name": "size",
"attr_val": [
{"attr_name": "width", "attr_val": 1920, "dtype": int},
{"attr_name": "height", "attr_val": 1080, "dtype": int},
# {"attr_name": "depth", "attr_val": None, "dtype": int},
],
},
{"attr_name": "segmented", "attr_val": 0, "dtype": int},
],
"objects": [
{
"name": "handheld_scanner",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 743.53,
"ymin": 99.46,
"xmax": 797.5,
"ymax": 207.56,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
]
],
},
{
"name": "products",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 740.99,
"ymin": 385.75,
"xmax": 821.4,
"ymax": 456.3,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "products", "dtype": str},
{"attr_name": "value", "attr_val": True, "dtype": bool},
],
[
{
"attr_name": "name",
"attr_val": "empty_transparent_packet",
"dtype": str,
},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{
"attr_name": "name",
"attr_val": "filled_transparent_packet",
"dtype": str,
},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
],
],
},
{
"name": "client_things",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 826.8,
"ymin": 383.97,
"xmax": 892.9,
"ymax": 495.1,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "bags", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "wallets", "dtype": str},
{"attr_name": "value", "attr_val": True, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "plastic_card", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "phones", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "clients_food", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "other_things", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "shop_receipt", "dtype": str},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
],
],
},
{
"name": "hands",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 799.88,
"ymin": 392.4,
"xmax": 875.13,
"ymax": 547.38,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
]
],
},
{
"name": "products",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 701.29,
"ymin": 373.46,
"xmax": 755.1,
"ymax": 426.7,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "products", "dtype": str},
{"attr_name": "value", "attr_val": True, "dtype": bool},
],
[
{
"attr_name": "name",
"attr_val": "empty_transparent_packet",
"dtype": str,
},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{
"attr_name": "name",
"attr_val": "filled_transparent_packet",
"dtype": str,
},
{"attr_name": "value", "attr_val": False, "dtype": bool},
],
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
],
],
},
{
"name": "person",
"truncated": 0,
"difficult": 0,
"occluded": 0,
"bndbox": {
"xmin": 629.63,
"ymin": 396.7,
"xmax": 1200.0,
"ymax": 923.66,
},
"attributes": [
[
{"attr_name": "name", "attr_val": "rotation", "dtype": str},
{"attr_name": "value", "attr_val": 0.0, "dtype": float},
],
[
{"attr_name": "name", "attr_val": "track_id", "dtype": str},
{"attr_name": "value", "attr_val": 0, "dtype": int},
],
[
{"attr_name": "name", "attr_val": "keyframe", "dtype": str},
{"attr_name": "value", "attr_val": True, "dtype": bool},
],
],
},
],
"obj_info": {
"names": [
"handheld_scanner",
"products",
"client_things",
"hands",
"person",
],
"count": {
"handheld_scanner": 1,
"products": 2,
"client_things": 1,
"hands": 1,
"person": 1,
},
},
},
]

invalid_annotations = [
Expand Down
20 changes: 16 additions & 4 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def check_attributes(obj, attr_params):
check_attributes(getattr(obj, attr_name), item)
else:
attr_type = attr_params.get("dtype")
assert attr_params.get("attr_val") == getattr(obj, attr_name)
assert isinstance(getattr(obj, attr_name), attr_type)


Expand All @@ -25,13 +26,24 @@ def has_object(ann: PascalAnnotation, target_object: dict) -> bool:
attr_val = getattr(obj, k)
if k == "bndbox":
if (
v["xmin"] != attr_val.xmin
or v["xmax"] != attr_val.xmax
or v["ymin"] != attr_val.ymin
or v["ymax"] != attr_val.ymax
v["xmin"] != attr_val.xmin
or v["xmax"] != attr_val.xmax
or v["ymin"] != attr_val.ymin
or v["ymax"] != attr_val.ymax
):
match = False
break
elif k == "attributes":
attr_val = getattr(obj, k)
attributes = getattr(attr_val, "attribute")
if isinstance(attributes, list) and len(attributes) == len(v):
for a, item in zip(attributes, v):
for t in item:
check_attributes(a, t)
else:
for attr in v:
for item in attr:
check_attributes(attributes, item)
else:
if attr_val != v:
match = False
Expand Down
Loading

0 comments on commit 5395331

Please sign in to comment.