Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add in serializing check in auto annotation model runner #770

Merged
merged 1 commit into from
Oct 15, 2019
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
58 changes: 36 additions & 22 deletions utils/auto_annotation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,60 @@ A small command line program to test and run AutoAnnotation Scripts.
Change in to the root of the project directory and run

```shell
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json
```

Some programs need to run unrestricted or as an administer. Use the `--unrestriced` flag to simulate.

You can pass image files in to fully simulate your findings. Images are passed in as a list

```shell
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg
```

Additionally, it's sometimes useful to visualize your images.
Use the `--show-images` flag to have each image with the annotations pop up.

```shell
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
--show-images
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
--show-images
```

There's a command that let's you scan quickly by setting the length of time (in milliseconds) to display each image.
Use the `--show-image-delay` flag and set the appropriate time.

```shell
# Display each image in a window for 2 seconds
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
--show-images
--show-image-delay 2000
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
--show-images \
--show-image-delay 2000
```

Visualization isn't always enough.
The CVAT has a serialization step that can throw errors on model upload even after successful visualization.
You must install the necessary packages installed, but then you can add the `--serialize` command to ensure that your
results will serialize correctly.

```shell
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
--xml /path/to/xml/file.xml \
--bin /path/to/bin/file.bin \
--json /path/to/json/mapping/mapping.json \
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
--serialize
```
14 changes: 14 additions & 0 deletions utils/auto_annotation/run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def _get_kwargs():

parser.add_argument('--show-images', action='store_true', help='Show the results of the annotation in a window')
parser.add_argument('--show-image-delay', default=0, type=int, help='Displays the images for a set duration in milliseconds, default is until a key is pressed')
parser.add_argument('--serialize', default=False, action='store_true', help='Try to serialize the result')

return vars(parser.parse_args())

Expand Down Expand Up @@ -103,6 +104,19 @@ def main():
py_file,
restricted=restricted)

if kwargs['serialize']:
os.environ['DJANGO_SETTINGS_MODULE'] = 'cvat.settings.production'
import django
django.setup()

from cvat.apps.engine.serializers import LabeledDataSerializer

serializer = LabeledDataSerializer(data=results)

if not serializer.is_valid():
logging.critical('Data unable to be serialized correctly!')
serializer.is_valid(raise_exception=True)

logging.warning('Program didn\'t have any errors.')
show_images = kwargs.get('show_images', False)

Expand Down