Skip to content

Commit e9e52f3

Browse files
benhoffnmanovic
authored andcommitted
add in serializing check in auto annotation model runner (#770)
1 parent 695fc37 commit e9e52f3

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

utils/auto_annotation/README.md

+36-22
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,60 @@ A small command line program to test and run AutoAnnotation Scripts.
77
Change in to the root of the project directory and run
88

99
```shell
10-
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
11-
--xml /path/to/xml/file.xml \
12-
--bin /path/to/bin/file.bin \
13-
--json /path/to/json/mapping/mapping.json
10+
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
11+
--xml /path/to/xml/file.xml \
12+
--bin /path/to/bin/file.bin \
13+
--json /path/to/json/mapping/mapping.json
1414
```
1515

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

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

2020
```shell
21-
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
22-
--xml /path/to/xml/file.xml \
23-
--bin /path/to/bin/file.bin \
24-
--json /path/to/json/mapping/mapping.json \
25-
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg
21+
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
22+
--xml /path/to/xml/file.xml \
23+
--bin /path/to/bin/file.bin \
24+
--json /path/to/json/mapping/mapping.json \
25+
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg
2626
```
2727

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

3131
```shell
32-
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
33-
--xml /path/to/xml/file.xml \
34-
--bin /path/to/bin/file.bin \
35-
--json /path/to/json/mapping/mapping.json \
36-
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
37-
--show-images
32+
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
33+
--xml /path/to/xml/file.xml \
34+
--bin /path/to/bin/file.bin \
35+
--json /path/to/json/mapping/mapping.json \
36+
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
37+
--show-images
3838
```
3939

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

4343
```shell
4444
# Display each image in a window for 2 seconds
45-
$ python cvat/utils/auto_annotation/run_modely.py --py /path/to/python/interp.py \
46-
--xml /path/to/xml/file.xml \
47-
--bin /path/to/bin/file.bin \
48-
--json /path/to/json/mapping/mapping.json \
49-
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
50-
--show-images
51-
--show-image-delay 2000
45+
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
46+
--xml /path/to/xml/file.xml \
47+
--bin /path/to/bin/file.bin \
48+
--json /path/to/json/mapping/mapping.json \
49+
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
50+
--show-images \
51+
--show-image-delay 2000
52+
```
53+
54+
Visualization isn't always enough.
55+
The CVAT has a serialization step that can throw errors on model upload even after successful visualization.
56+
You must install the necessary packages installed, but then you can add the `--serialize` command to ensure that your
57+
results will serialize correctly.
58+
59+
```shell
60+
$ python cvat/utils/auto_annotation/run_model.py --py /path/to/python/interp.py \
61+
--xml /path/to/xml/file.xml \
62+
--bin /path/to/bin/file.bin \
63+
--json /path/to/json/mapping/mapping.json \
64+
--image-files /path/to/img.jpg /path2/to/img2.png /path/to/img3.jpg \
65+
--serialize
5266
```

utils/auto_annotation/run_model.py

+14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def _get_kwargs():
2828

2929
parser.add_argument('--show-images', action='store_true', help='Show the results of the annotation in a window')
3030
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')
31+
parser.add_argument('--serialize', default=False, action='store_true', help='Try to serialize the result')
3132

3233
return vars(parser.parse_args())
3334

@@ -103,6 +104,19 @@ def main():
103104
py_file,
104105
restricted=restricted)
105106

107+
if kwargs['serialize']:
108+
os.environ['DJANGO_SETTINGS_MODULE'] = 'cvat.settings.production'
109+
import django
110+
django.setup()
111+
112+
from cvat.apps.engine.serializers import LabeledDataSerializer
113+
114+
serializer = LabeledDataSerializer(data=results)
115+
116+
if not serializer.is_valid():
117+
logging.critical('Data unable to be serialized correctly!')
118+
serializer.is_valid(raise_exception=True)
119+
106120
logging.warning('Program didn\'t have any errors.')
107121
show_images = kwargs.get('show_images', False)
108122

0 commit comments

Comments
 (0)