Skip to content

Commit 58b521f

Browse files
committed
2 parents d67c2e6 + 819304c commit 58b521f

File tree

10 files changed

+1955
-20
lines changed

10 files changed

+1955
-20
lines changed

docs/source/superannotate.sdk.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ ________________________
333333
.. autofunction:: superannotate.df_to_annotations
334334
.. _ref_filter_annotation_instances:
335335
.. autofunction:: superannotate.filter_annotation_instances
336+
.. autofunction:: superannotate.filter_images_by_comments
336337

337338
----------
338339

docs/source/tutorial.sdk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Example of created DataFrame:
368368
Each row represents annotation information. One full annotation with multiple
369369
attribute groups can be grouped under :code:`instanceId` field.
370370

371-
A helper function :ref:`filter_annotation_instances <ref_filter_annotation_instances>` to annotation instances by their class or attribute from the DataFrame is available. E.g., to get annotations that have annotation class :code:`Human` and attribute :code:`"height" : "tall"` that are **not** of type :code:`polygon`:
371+
A helper function :ref:`filter_annotation_instances <ref_filter_annotation_instances>` is available to filter annotation instances by their class, attribute, type or error fields from the DataFrame. E.g., to get annotations that have annotation class :code:`Human` and attribute :code:`"height" : "tall"` that are **not** of type :code:`polygon`:
372372

373373
.. code-block:: python
374374

superannotate/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
image_path_to_annotation_paths, project_type_int_to_str,
2222
project_type_str_to_int, user_role_str_to_int
2323
)
24-
from .dataframe_filtering import filter_annotation_instances, filter_comments
24+
from .dataframe_filtering import (
25+
filter_annotation_instances, filter_images_by_comments
26+
)
2527
from .db.annotation_classes import (
2628
create_annotation_class, create_annotation_classes_from_classes_json,
2729
delete_annotation_class, download_annotation_classes_json,

superannotate/dataframe_filtering.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
11
import pandas as pd
22

33

4-
def filter_comments(annotations_df, resolved=False):
5-
"""Filter comments on resolve status
4+
def filter_images_by_comments(
5+
annotations_df,
6+
include_unresolved_comments=True,
7+
include_resolved_comments=False,
8+
include_without_comments=False
9+
):
10+
"""Filter images on comment resolve status and comment resolve status
611
712
:param annotations_df: pandas DataFrame of project annotations
813
:type annotations_df: pandas.DataFrame
9-
:param resolved: resolved criterion
10-
:type resolved: bool
11-
12-
:return: filtered DataFrame
13-
:rtype: pandas.DataFrame
14+
:param include_unresolved_comments: include images with unresolved state
15+
:type include_unresolved_comments: bool
16+
:param include_resolved_comments: include images with resolved state
17+
:type include_resolved_comments: bool
18+
:param include_resolved_comments: include images with resolved state
19+
:type include_resolved_comments: bool
20+
:param include_without_comments: include images without any comments
21+
:type include_without_comments: bool
22+
23+
:return: filtered image names
24+
:rtype: list of strs
1425
1526
"""
27+
images = set()
1628
df = annotations_df[annotations_df["type"] == "comment"]
17-
df = df[df["commentResolved"] == resolved]
18-
19-
return df
29+
if include_unresolved_comments:
30+
images.update(
31+
df[df["commentResolved"] == False]["imageName"].dropna().unique()
32+
)
33+
if include_resolved_comments:
34+
images.update(
35+
df[df["commentResolved"] == True]["imageName"].dropna().unique()
36+
)
37+
if include_without_comments:
38+
all_images = set(annotations_df["imageName"].dropna().unique())
39+
with_comments = set(df["imageName"].dropna().unique())
40+
images.update(all_images - with_comments)
41+
42+
return list(images)
2043

2144

2245
def filter_annotation_instances(annotations_df, include=None, exclude=None):
2346
"""Filter annotation instances from project annotations pandas DataFrame.
2447
25-
include and exclude rulses should be a list of rules of following type: [{"className": "<className>", "type" : "<bbox, polygon,...>", "attributes" : [{"name" : "<attribute_value>", "groupName" : "<attribute_group_name>"},...]},...]
48+
include and exclude rulses should be a list of rules of following type: [{"className": "<className>", "type" : "<bbox, polygon,...>", "error": <True or False>, "attributes" : [{"name" : "<attribute_value>", "groupName" : "<attribute_group_name>"},...]},...]
2649
2750
2851
:param annotations_df: pandas DataFrame of project annotations
@@ -52,6 +75,8 @@ def filter_annotation_instances(annotations_df, include=None, exclude=None):
5275
) & (df_new["attributeName"] == attribute["name"])]
5376
if "type" in include_rule:
5477
df_new = df_new[df_new["type"] == include_rule["type"]]
78+
if "error" in include_rule:
79+
df_new = df_new[df_new["error"] == include_rule["error"]]
5580
included_dfs.append(df_new)
5681

5782
df = pd.concat(included_dfs)
@@ -71,6 +96,8 @@ def filter_annotation_instances(annotations_df, include=None, exclude=None):
7196
(df_new["attributeName"] == attribute["name"])]
7297
if "type" in exclude_rule:
7398
df_new = df_new[df_new["type"] == exclude_rule["type"]]
99+
if "error" in exclude_rule:
100+
df_new = df_new[df_new["error"] == exclude_rule["error"]]
74101

75102
df = df.drop(df_new.index)
76103

superannotate/db/exports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def prepare_export(
141141
)
142142
res = response.json()
143143
logger.info(
144-
"Prepared export %s for project %s.", res['name'], project["name"]
144+
"Prepared export %s for project %s (ID %s).", res['name'], project["name"], project["id"]
145145
)
146146
return res["name"]
147147

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.1.3"
1+
__version__ = "2.1.4"

tests/sample_project_vector/example_image_1.jpg___objects.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
],
1212
"resolved": true
1313
},
14+
{
15+
"type": "comment",
16+
"x": 521.4069213867188,
17+
"y": 531.5987548828125,
18+
"comments": [
19+
{
20+
"text": "dd",
21+
"id": "hovnatan@superannotate.com"
22+
}
23+
],
24+
"resolved": false
25+
},
1426
{
1527
"type": "bbox",
1628
"classId": 55917,

0 commit comments

Comments
 (0)