-
Notifications
You must be signed in to change notification settings - Fork 115
/
image_manual.py
44 lines (41 loc) · 1.74 KB
/
image_manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import prodigy
from prodigy.components.loaders import Images
from prodigy.util import split_string
from typing import List, Optional
# Recipe decorator with argument annotations: (description, argument type,
# shortcut, type / converter function called on value before it's passed to
# the function). Descriptions are also shown when typing --help.
@prodigy.recipe(
"image.manual",
dataset=("The dataset to use", "positional", None, str),
source=("Path to a directory of images", "positional", None, str),
label=("One or more comma-separated labels", "option", "l", split_string),
exclude=("Names of datasets to exclude", "option", "e", split_string),
darken=("Darken image to make boxes stand out more", "flag", "D", bool),
)
def image_manual(
dataset: str,
source: str,
label: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
darken: bool = False,
):
"""
Manually annotate images by drawing rectangular bounding boxes or polygon
shapes on the image.
"""
# Load a stream of images from a directory and return a generator that
# yields a dictionary for each example in the data. All images are
# converted to base64-encoded data URIs.
stream = Images(source)
return {
"view_id": "image_manual", # Annotation interface to use
"dataset": dataset, # Name of dataset to save annotations
"stream": stream, # Incoming stream of examples
"exclude": exclude, # List of dataset names to exclude
"config": { # Additional config settings, mostly for app UI
"label": ", ".join(label) if label is not None else "all",
"labels": label, # Selectable label options,
"darken_image": 0.3 if darken else 0,
},
}