Skip to content

Conversation

@owencjones
Copy link
Contributor

Dataloop importer was not handling the 'segment' type in dataloop formats. Have added support for it with simple polygons - it doesn't appear to include complex polygons - and have written a test suite for the whole importer.

Also took the opportunity to:

  • Add a .python-version set at 3.9 for pyenv users to use in development
  • Add a setup.cfg with flake8 settings
  • Add some testing, linting, and formatting tools to the setup.pt that developers can install with.

@linear
Copy link

linear bot commented Nov 28, 2022

IO-496 Request: Add support for importing polygons in Dataloop format

Product Request Form submission from @Rafal Zadlowski

Is this a V1 or V2 issue, or both?
Both

​What is your request?
Add support for importing polygons in Dataloop format.
According to dataloop.py, we only support importing bounding boxes ("type"="box") and tags ("type"="class"). Our customer, Activ Surgical has been getting an error message when uploading polygons ("type"="segment").
ValueError: Unknown supported annotation type: segment
Example file attached in the thread.

if annotation_type not in ["box", "class"]:

​What are the acceptance criteria?
Customer can import polygon annotations ("type"="segment") in Dataloop format.

​Which product area is this request is applicable to (specify a team if known)?
Unsure

How important is this request?
Urgent - already causing financial or customer loss, immediate action

Do you have any deadline for this request (if deadline applicable, specify why)?
left blank

Any additional info / Specify why Urgent or High:
So far didn't find a workaround, but still exploring it. This basically blocks the other work our customer is setting up besides the video annotations, so it is rather urgent.

@owencjones owencjones changed the title IO-496 IO-496: Request: Add support for importing polygons in Dataloop format Nov 28, 2022
.python-version Outdated
@@ -0,0 +1 @@
3.9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 3.9 as 3.10 and 3.11 both have issues compiling the [ml] options in pip install. Opening tickets to address this.

annotations: List[dt.Annotation] = list(filter(None, map(_parse_annotation, data["annotations"])))
annotation_classes: Set[dt.AnnotationClass] = set([annotation.annotation_class for annotation in annotations])
return dt.AnnotationFile(
path, _remove_leading_slash(data["filename"]), annotation_classes, annotations, remote_path="/"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just formatting change, done automatically by Black

content = f.read()
# from https://www.py4u.net/discuss/139845
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1)
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1) # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevents mypy complaining about this - rather than refactor type, when we have to replace setup.py in the coming months anyway.

self.DATALOOP_MOCK_DATA = _fd.read()
_fd.close()

def assertApproximatelyEqualNumber(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd, but prevents issues with floating point numbers being off by .0000000000001 etc.

@owencjones owencjones marked this pull request as ready for review November 28, 2022 14:50
with patch("darwin.importer.formats.dataloop.dt.make_polygon") as make_polygon_mock:
pa(self.parsed_json["annotations"][2]) # 2 is a segment type

if "kwargs" in make_polygon_mock.call_args:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MagicMock and Mock before version 3.8 don't support testing kwargs, so testing this would be difficult, but this feature switch will mean we still test against 3.8 and 3.9 in both Windows and Ubuntu, which I think is plenty for a simple dict comprehension.

@owencjones owencjones requested a review from rslota November 28, 2022 16:56
setup.cfg Outdated
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 160 No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end-of-line 🙏

@owencjones owencjones merged commit ff6e0cf into master Dec 5, 2022
@owencjones owencjones deleted the IO-496 branch December 5, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants