easyannotate 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data_factory/__init__.py +82 -0
  2. data_factory/__main__.py +6 -0
  3. data_factory/annotate/__init__.py +15 -0
  4. data_factory/annotate/attach.py +398 -0
  5. data_factory/annotate/demo.py +161 -0
  6. data_factory/annotate/images.py +443 -0
  7. data_factory/annotate/labels.py +399 -0
  8. data_factory/annotate/loop.py +359 -0
  9. data_factory/annotate/projects.py +207 -0
  10. data_factory/annotate/review.py +471 -0
  11. data_factory/annotate/schema.sql +171 -0
  12. data_factory/annotate/shapes.py +488 -0
  13. data_factory/annotate/store.py +292 -0
  14. data_factory/annotate/tools/__init__.py +39 -0
  15. data_factory/annotate/tools/fake.py +170 -0
  16. data_factory/annotate/tools/install.py +254 -0
  17. data_factory/annotate/tools/local.py +389 -0
  18. data_factory/annotate/tools/postprocess.py +175 -0
  19. data_factory/annotate/tools/protocol.py +238 -0
  20. data_factory/annotate/tools/registry.py +196 -0
  21. data_factory/annotate/tools/results.py +83 -0
  22. data_factory/annotate/tools/serve.py +106 -0
  23. data_factory/cli/__init__.py +21 -0
  24. data_factory/cli/main.py +837 -0
  25. data_factory/cli/menu.py +173 -0
  26. data_factory/cli/render.py +158 -0
  27. data_factory/core/__init__.py +11 -0
  28. data_factory/core/annotations/__init__.py +5 -0
  29. data_factory/core/annotations/coco.py +394 -0
  30. data_factory/core/annotations/csvfmt.py +174 -0
  31. data_factory/core/annotations/dota.py +98 -0
  32. data_factory/core/annotations/formats.py +626 -0
  33. data_factory/core/annotations/labelme.py +153 -0
  34. data_factory/core/annotations/model.py +334 -0
  35. data_factory/core/annotations/voc.py +231 -0
  36. data_factory/core/annotations/yolo.py +283 -0
  37. data_factory/core/bktree.py +89 -0
  38. data_factory/core/fs.py +245 -0
  39. data_factory/core/imaging.py +626 -0
  40. data_factory/core/ops/__init__.py +44 -0
  41. data_factory/core/ops/analyze.py +383 -0
  42. data_factory/core/ops/annotate_export.py +326 -0
  43. data_factory/core/ops/audit.py +274 -0
  44. data_factory/core/ops/augment.py +454 -0
  45. data_factory/core/ops/collect.py +241 -0
  46. data_factory/core/ops/combine.py +582 -0
  47. data_factory/core/ops/convert.py +212 -0
  48. data_factory/core/ops/dataset.py +246 -0
  49. data_factory/core/ops/dedup.py +235 -0
  50. data_factory/core/ops/export.py +168 -0
  51. data_factory/core/ops/image.py +407 -0
  52. data_factory/core/ops/labels.py +215 -0
  53. data_factory/core/ops/pairing.py +133 -0
  54. data_factory/core/ops/rename.py +154 -0
  55. data_factory/core/ops/report.py +323 -0
  56. data_factory/core/ops/visualize.py +164 -0
  57. data_factory/core/pairs.py +144 -0
  58. data_factory/core/parallel.py +191 -0
  59. data_factory/core/provenance.py +136 -0
  60. data_factory/core/registry.py +339 -0
  61. data_factory/core/stats.py +403 -0
  62. data_factory/core/types.py +148 -0
  63. data_factory/core/writer.py +194 -0
  64. data_factory/desktop.py +207 -0
  65. data_factory/hardware.py +243 -0
  66. data_factory/pipeline.py +192 -0
  67. data_factory/py.typed +0 -0
  68. data_factory/service/__init__.py +26 -0
  69. data_factory/service/app.py +483 -0
  70. data_factory/service/binding.py +174 -0
  71. data_factory/service/deps.py +133 -0
  72. data_factory/service/jobs.py +177 -0
  73. data_factory/service/limits.py +71 -0
  74. data_factory/service/routers/__init__.py +11 -0
  75. data_factory/service/routers/annotate.py +582 -0
  76. data_factory/service/routers/local.py +464 -0
  77. data_factory/service/routers/media.py +154 -0
  78. data_factory/service/routers/predictions.py +116 -0
  79. data_factory/service/routers/promote.py +182 -0
  80. data_factory/service/routers/tools.py +308 -0
  81. data_factory/service/static/annotate/api.js +246 -0
  82. data_factory/service/static/annotate/app.js +1696 -0
  83. data_factory/service/static/annotate/assist.js +106 -0
  84. data_factory/service/static/annotate/filmstrip.js +286 -0
  85. data_factory/service/static/annotate/hit.js +146 -0
  86. data_factory/service/static/annotate/labels.js +197 -0
  87. data_factory/service/static/annotate/render.js +286 -0
  88. data_factory/service/static/annotate/scene.js +277 -0
  89. data_factory/service/static/annotate/shapelist.js +72 -0
  90. data_factory/service/static/annotate/tools/box.js +96 -0
  91. data_factory/service/static/annotate/tools/line.js +96 -0
  92. data_factory/service/static/annotate/tools/obb.js +88 -0
  93. data_factory/service/static/annotate/tools/point.js +49 -0
  94. data_factory/service/static/annotate/tools/polygon.js +110 -0
  95. data_factory/service/static/annotate/tools/select.js +227 -0
  96. data_factory/service/static/annotate/undo.js +176 -0
  97. data_factory/service/static/annotate/viewport.js +156 -0
  98. data_factory/service/static/annotate.html +390 -0
  99. data_factory/service/static/index.html +632 -0
  100. data_factory/service/workspace.py +244 -0
  101. easyannotate/__init__.py +64 -0
  102. easyannotate/__main__.py +5 -0
  103. easyannotate/project.py +181 -0
  104. easyannotate/py.typed +0 -0
  105. easyannotate-0.4.0.dist-info/METADATA +767 -0
  106. easyannotate-0.4.0.dist-info/RECORD +109 -0
  107. easyannotate-0.4.0.dist-info/WHEEL +4 -0
  108. easyannotate-0.4.0.dist-info/entry_points.txt +4 -0
  109. easyannotate-0.4.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,173 @@
1
+ """The interactive menu shown when Data Factory is run with no arguments.
2
+
3
+ Built from the same registry the CLI uses, so it can never drift out of sync
4
+ with the available operations. It exists because the tool it replaces was a
5
+ folder of scripts you edited before running -- typing a path at a prompt is a
6
+ strictly better version of that, and it is what someone new to the tool can
7
+ actually use.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Any, TextIO
13
+
14
+ from ..core import registry
15
+ from ..core.registry import Operation, ParamError
16
+ from ..core.types import Cancelled, Context
17
+ from . import render
18
+
19
+ BANNER = r"""
20
+ ____ _ _____ _
21
+ | _ \ __ _| |_ __ _ | ___|_ _ __| |_ ___ _ __ _ _
22
+ | | | |/ _` | __/ _` || |_ / _` |/ _| __/ _ \| '__| | | |
23
+ | |_| | (_| | || (_| || _| (_| | (_| || (_) | | | |_| |
24
+ |____/ \__,_|\__\__,_||_| \__,_|\___|\__\___/|_| \__, |
25
+ |___/
26
+ """
27
+
28
+
29
+ def run_menu(out: TextIO, err: TextIO) -> int:
30
+ style = render.Style(render._supports_colour(out))
31
+ out.write(style.cyan(BANNER))
32
+ out.write(" Dataset preparation for computer vision.\n")
33
+ out.write(style.dim(" Every step previews before it changes anything.\n"))
34
+
35
+ while True:
36
+ operations = registry.all_operations()
37
+ _print_menu(operations, out, style)
38
+ choice = _prompt("\n Choose an operation (or q to quit): ", out)
39
+ if choice is None or choice.lower() in ("q", "quit", "exit"):
40
+ out.write("\n Bye.\n\n")
41
+ return 0
42
+ if not choice.strip():
43
+ continue
44
+
45
+ operation = _resolve(choice.strip(), operations)
46
+ if operation is None:
47
+ out.write(style.yellow(f" No operation matches {choice!r}.\n"))
48
+ continue
49
+
50
+ try:
51
+ _run_interactive(operation, out, err, style)
52
+ except (KeyboardInterrupt, EOFError):
53
+ out.write("\n Cancelled, back to the menu.\n")
54
+
55
+
56
+ def _print_menu(operations: list[Operation], out: TextIO, style: render.Style) -> None:
57
+ out.write("\n")
58
+ current = ""
59
+ for number, operation in enumerate(operations, start=1):
60
+ if operation.category != current:
61
+ current = operation.category
62
+ out.write(style.bold(f"\n {current.upper()}\n"))
63
+ marker = style.yellow("!") if operation.destructive else " "
64
+ out.write(f" {number:>2}) {marker} {style.cyan(operation.name):<30} {operation.summary[:60]}\n")
65
+
66
+
67
+ def _resolve(choice: str, operations: list[Operation]) -> Operation | None:
68
+ if choice.isdigit():
69
+ index = int(choice) - 1
70
+ return operations[index] if 0 <= index < len(operations) else None
71
+ for operation in operations:
72
+ if operation.name == choice:
73
+ return operation
74
+ matches = [o for o in operations if choice in o.name]
75
+ return matches[0] if len(matches) == 1 else None
76
+
77
+
78
+ def _run_interactive(
79
+ operation: Operation, out: TextIO, err: TextIO, style: render.Style
80
+ ) -> None:
81
+ out.write(f"\n{style.bold(operation.title)} -- {operation.summary}\n")
82
+ if operation.notes:
83
+ out.write(style.dim("\n" + operation.notes + "\n"))
84
+ out.write(style.dim("\n Press Enter to accept the default shown in brackets.\n\n"))
85
+
86
+ supplied: dict[str, Any] = {}
87
+ for param in operation.params:
88
+ value = _ask_param(param, out, style)
89
+ if value is None:
90
+ out.write(" Cancelled.\n")
91
+ return
92
+ if value != "":
93
+ supplied[param.name] = value
94
+
95
+ try:
96
+ bound = operation.bind(supplied)
97
+ except ParamError as exc:
98
+ out.write(style.red(f"\n {exc}\n"))
99
+ return
100
+
101
+ # Destructive work previews first, always. Seeing the plan before agreeing
102
+ # to it is the whole safety story of this tool.
103
+ if operation.destructive_for(bound):
104
+ out.write(style.yellow("\n Previewing (nothing will be changed yet)...\n"))
105
+ preview = operation.run(supplied, Context(dry_run=True))
106
+ render.render_result(preview, out)
107
+ if not preview.ok:
108
+ return
109
+ answer = _prompt(" Apply these changes for real? [y/N] ", out)
110
+ if answer is None or answer.strip().lower() not in ("y", "yes"):
111
+ out.write(" Left untouched.\n")
112
+ return
113
+
114
+ try:
115
+ result = operation.run(supplied, Context(dry_run=False))
116
+ except Cancelled:
117
+ out.write("\n Cancelled.\n")
118
+ return
119
+ except (RuntimeError, OSError) as exc:
120
+ out.write(style.red(f"\n error: {exc}\n"))
121
+ return
122
+
123
+ render.render_result(result, out)
124
+ _show_equivalent_command(operation, supplied, out, style)
125
+
126
+
127
+ def _ask_param(param: registry.Param, out: TextIO, style: render.Style) -> Any:
128
+ """Prompt until the value is acceptable, or the user gives up."""
129
+ label = param.name.replace("_", " ")
130
+ hint = f" [{param.default}]" if param.default is not None else ""
131
+ if param.required:
132
+ hint = style.red(" (required)")
133
+ if param.choices:
134
+ hint += style.dim(f" {{{'|'.join(param.choices)}}}")
135
+
136
+ while True:
137
+ out.write(style.dim(f" {param.help}\n"))
138
+ raw = _prompt(f" {label}{hint}: ", out)
139
+ if raw is None:
140
+ return None
141
+ raw = raw.strip()
142
+ if not raw:
143
+ if param.required:
144
+ out.write(style.yellow(" This one is required.\n"))
145
+ continue
146
+ return ""
147
+ try:
148
+ param.coerce(raw)
149
+ except (ParamError, ValueError) as exc:
150
+ out.write(style.yellow(f" {exc}\n"))
151
+ continue
152
+ return raw
153
+
154
+
155
+ def _show_equivalent_command(
156
+ operation: Operation, supplied: dict[str, Any], out: TextIO, style: render.Style
157
+ ) -> None:
158
+ """Teach the CLI form, so the menu is a ramp rather than a dead end."""
159
+ parts = ["datafactory", operation.name]
160
+ for name, value in supplied.items():
161
+ flag = "--" + name.replace("_", "-")
162
+ text = str(value)
163
+ parts.append(flag if text.lower() == "true" else f'{flag} "{text}"')
164
+ out.write(style.dim(f" Same thing from a script:\n {' '.join(parts)}\n\n"))
165
+
166
+
167
+ def _prompt(message: str, out: TextIO) -> str | None:
168
+ out.write(message)
169
+ out.flush()
170
+ try:
171
+ return input()
172
+ except (EOFError, KeyboardInterrupt):
173
+ return None
@@ -0,0 +1,158 @@
1
+ """Turning an OpResult into terminal output.
2
+
3
+ All presentation lives here. The core returns data; this module is the only
4
+ place that decides how it looks, which is what keeps a web front-end free to
5
+ render the same result completely differently.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import sys
12
+ from typing import Any, TextIO
13
+
14
+ from ..core.registry import Operation
15
+ from ..core.types import OpResult
16
+
17
+ BULLET = "-"
18
+ RULE = "=" * 66
19
+
20
+
21
+ def _supports_colour(stream: TextIO) -> bool:
22
+ return hasattr(stream, "isatty") and stream.isatty() and sys.platform != "emscripten"
23
+
24
+
25
+ class Style:
26
+ """ANSI codes, disabled when the output is redirected."""
27
+
28
+ def __init__(self, enabled: bool) -> None:
29
+ self.enabled = enabled
30
+
31
+ def _wrap(self, text: str, code: str) -> str:
32
+ return f"\033[{code}m{text}\033[0m" if self.enabled else text
33
+
34
+ def bold(self, text: str) -> str:
35
+ return self._wrap(text, "1")
36
+
37
+ def dim(self, text: str) -> str:
38
+ return self._wrap(text, "2")
39
+
40
+ def red(self, text: str) -> str:
41
+ return self._wrap(text, "31")
42
+
43
+ def yellow(self, text: str) -> str:
44
+ return self._wrap(text, "33")
45
+
46
+ def green(self, text: str) -> str:
47
+ return self._wrap(text, "32")
48
+
49
+ def cyan(self, text: str) -> str:
50
+ return self._wrap(text, "36")
51
+
52
+
53
+ def render_result(
54
+ result: OpResult,
55
+ stream: TextIO,
56
+ *,
57
+ as_json: bool = False,
58
+ show_actions: int = 12,
59
+ verbose: bool = False,
60
+ ) -> None:
61
+ if as_json:
62
+ json.dump(result.as_dict(include_actions=verbose), stream, indent=2)
63
+ stream.write("\n")
64
+ return
65
+
66
+ style = Style(_supports_colour(stream))
67
+ header = style.bold(result.op)
68
+ if result.dry_run:
69
+ header += style.yellow(" [dry run - nothing was changed]")
70
+ stream.write(f"\n{header}\n{RULE}\n")
71
+
72
+ if result.counts:
73
+ width = max(len(k) for k in result.counts)
74
+ stream.writelines(f" {key.replace('_', ' '):<{width}} {value:>9,}\n" for key, value in result.counts.items())
75
+
76
+ _render_data(result.data, stream, style)
77
+
78
+ stream.writelines(style.yellow(f" ! {warning}\n") for warning in result.warnings)
79
+ stream.writelines(style.red(f" x {error}\n") for error in result.errors)
80
+
81
+ if result.actions and show_actions:
82
+ shown = result.actions if verbose else result.actions[:show_actions]
83
+ stream.write(style.dim(f"\n actions ({len(result.actions)} total):\n"))
84
+ for action in shown:
85
+ target = f" -> {action.dst}" if action.dst else ""
86
+ stream.write(style.dim(f" {action.action.value:<7} {action.src.name}{target}\n"))
87
+ if len(result.actions) > len(shown):
88
+ stream.write(style.dim(f" ... {len(result.actions) - len(shown)} more (use --verbose)\n"))
89
+
90
+ verdict = style.green("done") if result.ok else style.red("failed")
91
+ stream.write(f"\n {verdict}\n\n")
92
+
93
+
94
+ def _render_data(data: dict[str, Any], stream: TextIO, style: Style) -> None:
95
+ """Show the handful of data keys that are worth reading in a terminal."""
96
+ issues = data.get("issues")
97
+ if issues:
98
+ stream.write(style.bold("\n findings\n"))
99
+ for issue in issues:
100
+ severity = issue.get("severity", "")
101
+ colour = {
102
+ "high": style.red,
103
+ "medium": style.yellow,
104
+ "low": style.dim,
105
+ }.get(severity, style.green)
106
+ stream.write(f" {colour(severity.upper() or 'OK'):<6} {issue['issue']}\n")
107
+ if issue.get("fix"):
108
+ stream.write(style.dim(f" fix: {issue['fix']}\n"))
109
+
110
+ for key in ("per_label", "per_category", "per_split_labels", "case_variants", "case_collisions"):
111
+ section = data.get(key)
112
+ if not section:
113
+ continue
114
+ stream.write(style.bold(f"\n {key.replace('_', ' ')}\n"))
115
+ for name, value in section.items():
116
+ if isinstance(value, dict):
117
+ inner = ", ".join(f"{k}={v}" for k, v in value.items())
118
+ stream.write(f" {name}: {inner}\n")
119
+ elif isinstance(value, list):
120
+ stream.write(f" {name}: {' / '.join(map(str, value))}\n")
121
+ else:
122
+ stream.write(f" {name:<24} {value:>8,}\n")
123
+
124
+ for key in ("output", "quarantine", "target"):
125
+ if data.get(key):
126
+ stream.write(f"\n {key}: {style.cyan(str(data[key]))}\n")
127
+
128
+
129
+ def render_operation_list(operations: list[Operation], stream: TextIO) -> None:
130
+ style = Style(_supports_colour(stream))
131
+ current = ""
132
+ for op in operations:
133
+ if op.category != current:
134
+ current = op.category
135
+ stream.write(style.bold(f"\n{current}\n"))
136
+ marker = style.yellow(" ! ") if op.destructive else " "
137
+ stream.write(f"{marker}{style.cyan(op.name):<32} {op.summary}\n")
138
+ stream.write(style.dim("\n ! writes or removes files. Add --dry-run to preview any of them.\n\n"))
139
+
140
+
141
+ def render_operation_help(op: Operation, stream: TextIO) -> None:
142
+ style = Style(_supports_colour(stream))
143
+ stream.write(f"\n{style.bold(op.name)} -- {op.title}\n{RULE}\n{op.summary}\n")
144
+ if op.destructive:
145
+ stream.write(style.yellow("\nThis operation writes or removes files. Preview it with --dry-run.\n"))
146
+ if op.notes:
147
+ stream.write(f"\n{op.notes}\n")
148
+
149
+ stream.write(style.bold("\nparameters\n"))
150
+ for param in op.params:
151
+ flag = "--" + param.name.replace("_", "-")
152
+ tag = style.red("required") if param.required else style.dim(f"default: {param.default!r}")
153
+ stream.write(f" {style.cyan(flag):<34} {param.help}\n")
154
+ detail = f" {param.kind}, {tag}"
155
+ if param.choices:
156
+ detail += style.dim(f", one of: {', '.join(param.choices)}")
157
+ stream.write(detail + "\n")
158
+ stream.write("\n")
@@ -0,0 +1,11 @@
1
+ """Pure logic for Data Factory.
2
+
3
+ Nothing here prints, parses argv, or exits. Operations take parameters and a
4
+ :class:`~data_factory.core.types.Context` and return an
5
+ :class:`~data_factory.core.types.OpResult`. That contract is what lets the same
6
+ code serve the CLI, a YAML pipeline, and an HTTP endpoint unchanged.
7
+ """
8
+
9
+ from .types import Action, Cancelled, Context, FileAction, OpResult
10
+
11
+ __all__ = ["Action", "Cancelled", "Context", "FileAction", "OpResult"]
@@ -0,0 +1,5 @@
1
+ """Annotation formats: a neutral model, plus readers and writers around it."""
2
+
3
+ from .model import Annotation, AnnotationError, Point, Shape
4
+
5
+ __all__ = ["Annotation", "AnnotationError", "Point", "Shape"]