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.
- data_factory/__init__.py +82 -0
- data_factory/__main__.py +6 -0
- data_factory/annotate/__init__.py +15 -0
- data_factory/annotate/attach.py +398 -0
- data_factory/annotate/demo.py +161 -0
- data_factory/annotate/images.py +443 -0
- data_factory/annotate/labels.py +399 -0
- data_factory/annotate/loop.py +359 -0
- data_factory/annotate/projects.py +207 -0
- data_factory/annotate/review.py +471 -0
- data_factory/annotate/schema.sql +171 -0
- data_factory/annotate/shapes.py +488 -0
- data_factory/annotate/store.py +292 -0
- data_factory/annotate/tools/__init__.py +39 -0
- data_factory/annotate/tools/fake.py +170 -0
- data_factory/annotate/tools/install.py +254 -0
- data_factory/annotate/tools/local.py +389 -0
- data_factory/annotate/tools/postprocess.py +175 -0
- data_factory/annotate/tools/protocol.py +238 -0
- data_factory/annotate/tools/registry.py +196 -0
- data_factory/annotate/tools/results.py +83 -0
- data_factory/annotate/tools/serve.py +106 -0
- data_factory/cli/__init__.py +21 -0
- data_factory/cli/main.py +837 -0
- data_factory/cli/menu.py +173 -0
- data_factory/cli/render.py +158 -0
- data_factory/core/__init__.py +11 -0
- data_factory/core/annotations/__init__.py +5 -0
- data_factory/core/annotations/coco.py +394 -0
- data_factory/core/annotations/csvfmt.py +174 -0
- data_factory/core/annotations/dota.py +98 -0
- data_factory/core/annotations/formats.py +626 -0
- data_factory/core/annotations/labelme.py +153 -0
- data_factory/core/annotations/model.py +334 -0
- data_factory/core/annotations/voc.py +231 -0
- data_factory/core/annotations/yolo.py +283 -0
- data_factory/core/bktree.py +89 -0
- data_factory/core/fs.py +245 -0
- data_factory/core/imaging.py +626 -0
- data_factory/core/ops/__init__.py +44 -0
- data_factory/core/ops/analyze.py +383 -0
- data_factory/core/ops/annotate_export.py +326 -0
- data_factory/core/ops/audit.py +274 -0
- data_factory/core/ops/augment.py +454 -0
- data_factory/core/ops/collect.py +241 -0
- data_factory/core/ops/combine.py +582 -0
- data_factory/core/ops/convert.py +212 -0
- data_factory/core/ops/dataset.py +246 -0
- data_factory/core/ops/dedup.py +235 -0
- data_factory/core/ops/export.py +168 -0
- data_factory/core/ops/image.py +407 -0
- data_factory/core/ops/labels.py +215 -0
- data_factory/core/ops/pairing.py +133 -0
- data_factory/core/ops/rename.py +154 -0
- data_factory/core/ops/report.py +323 -0
- data_factory/core/ops/visualize.py +164 -0
- data_factory/core/pairs.py +144 -0
- data_factory/core/parallel.py +191 -0
- data_factory/core/provenance.py +136 -0
- data_factory/core/registry.py +339 -0
- data_factory/core/stats.py +403 -0
- data_factory/core/types.py +148 -0
- data_factory/core/writer.py +194 -0
- data_factory/desktop.py +207 -0
- data_factory/hardware.py +243 -0
- data_factory/pipeline.py +192 -0
- data_factory/py.typed +0 -0
- data_factory/service/__init__.py +26 -0
- data_factory/service/app.py +483 -0
- data_factory/service/binding.py +174 -0
- data_factory/service/deps.py +133 -0
- data_factory/service/jobs.py +177 -0
- data_factory/service/limits.py +71 -0
- data_factory/service/routers/__init__.py +11 -0
- data_factory/service/routers/annotate.py +582 -0
- data_factory/service/routers/local.py +464 -0
- data_factory/service/routers/media.py +154 -0
- data_factory/service/routers/predictions.py +116 -0
- data_factory/service/routers/promote.py +182 -0
- data_factory/service/routers/tools.py +308 -0
- data_factory/service/static/annotate/api.js +246 -0
- data_factory/service/static/annotate/app.js +1696 -0
- data_factory/service/static/annotate/assist.js +106 -0
- data_factory/service/static/annotate/filmstrip.js +286 -0
- data_factory/service/static/annotate/hit.js +146 -0
- data_factory/service/static/annotate/labels.js +197 -0
- data_factory/service/static/annotate/render.js +286 -0
- data_factory/service/static/annotate/scene.js +277 -0
- data_factory/service/static/annotate/shapelist.js +72 -0
- data_factory/service/static/annotate/tools/box.js +96 -0
- data_factory/service/static/annotate/tools/line.js +96 -0
- data_factory/service/static/annotate/tools/obb.js +88 -0
- data_factory/service/static/annotate/tools/point.js +49 -0
- data_factory/service/static/annotate/tools/polygon.js +110 -0
- data_factory/service/static/annotate/tools/select.js +227 -0
- data_factory/service/static/annotate/undo.js +176 -0
- data_factory/service/static/annotate/viewport.js +156 -0
- data_factory/service/static/annotate.html +390 -0
- data_factory/service/static/index.html +632 -0
- data_factory/service/workspace.py +244 -0
- easyannotate/__init__.py +64 -0
- easyannotate/__main__.py +5 -0
- easyannotate/project.py +181 -0
- easyannotate/py.typed +0 -0
- easyannotate-0.4.0.dist-info/METADATA +767 -0
- easyannotate-0.4.0.dist-info/RECORD +109 -0
- easyannotate-0.4.0.dist-info/WHEEL +4 -0
- easyannotate-0.4.0.dist-info/entry_points.txt +4 -0
- easyannotate-0.4.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""The sidecar side of the protocol: read requests, write exactly one reply.
|
|
2
|
+
|
|
3
|
+
A tool author writes a handler object and calls :func:`serve`. Everything about
|
|
4
|
+
framing, correlation ids and error replies is handled here, so a tool cannot
|
|
5
|
+
get the part wrong that hangs the editor.
|
|
6
|
+
|
|
7
|
+
The single rule this module exists to guarantee:
|
|
8
|
+
|
|
9
|
+
**every request produces exactly one reply, including when the handler
|
|
10
|
+
raises, and including when the handler raises something that is not an
|
|
11
|
+
Exception.**
|
|
12
|
+
|
|
13
|
+
The legacy SAM worker broke that rule -- it caught, printed, and looped -- and
|
|
14
|
+
the UI blocked forever on a read that would never return.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import sys
|
|
21
|
+
import traceback
|
|
22
|
+
from typing import Any, BinaryIO, Protocol
|
|
23
|
+
|
|
24
|
+
from .protocol import ToolError, decode_message, encode_message, fail, ok
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Handler(Protocol):
|
|
28
|
+
"""What a tool implements. Every method may raise; none may hang."""
|
|
29
|
+
|
|
30
|
+
def describe(self) -> list[dict[str, Any]]: ...
|
|
31
|
+
def health(self, params: dict[str, Any]) -> dict[str, Any]: ...
|
|
32
|
+
def prepare(self, params: dict[str, Any]) -> Any: ...
|
|
33
|
+
def invoke(self, params: dict[str, Any]) -> Any: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def serve(handler: Handler, stdin: BinaryIO | None = None, stdout: BinaryIO | None = None) -> int:
|
|
37
|
+
"""Run the request loop until stdin closes. Returns a process exit code."""
|
|
38
|
+
source = stdin if stdin is not None else sys.stdin.buffer
|
|
39
|
+
sink = stdout if stdout is not None else _private_stdout()
|
|
40
|
+
|
|
41
|
+
for line in source:
|
|
42
|
+
if not line.strip():
|
|
43
|
+
continue
|
|
44
|
+
|
|
45
|
+
# Parsing is inside its own guard because a malformed frame has no id
|
|
46
|
+
# to reply against -- there is no one to answer, so we log and move on
|
|
47
|
+
# rather than dying and taking the healthy calls with us.
|
|
48
|
+
try:
|
|
49
|
+
payload = decode_message(line)
|
|
50
|
+
except ToolError as exc:
|
|
51
|
+
print(f"[tool] dropping unparseable frame: {exc}", file=sys.stderr, flush=True)
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
message_id = payload.get("id")
|
|
55
|
+
if not isinstance(message_id, int):
|
|
56
|
+
print("[tool] dropping frame with no id", file=sys.stderr, flush=True)
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
result = _dispatch(handler, str(payload.get("method") or ""), payload.get("params") or {})
|
|
61
|
+
reply = ok(message_id, result)
|
|
62
|
+
except BaseException as exc: # noqa: BLE001 -- the whole point is to always reply
|
|
63
|
+
# BaseException, not Exception: a handler raising KeyboardInterrupt
|
|
64
|
+
# or a bare SystemExit must still produce a reply, or the caller
|
|
65
|
+
# waits for a message that is never coming.
|
|
66
|
+
traceback.print_exc()
|
|
67
|
+
reply = fail(message_id, exc if isinstance(exc, Exception) else ToolError(str(exc)))
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
sink.write(encode_message(reply))
|
|
71
|
+
sink.flush()
|
|
72
|
+
except (BrokenPipeError, OSError):
|
|
73
|
+
# The parent is gone; nothing useful is left to do.
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _private_stdout() -> BinaryIO:
|
|
80
|
+
"""Keep the real stdout for replies alone; everything else goes to stderr.
|
|
81
|
+
|
|
82
|
+
Libraries print. Ultralytics writes its download progress bar -- 13 KB of
|
|
83
|
+
carriage returns and no newline -- to stdout, and the next reply was
|
|
84
|
+
glued to the end of it and lost: on a first text prompt the editor said
|
|
85
|
+
"the tool exited". Measured, then fixed here for every library at once:
|
|
86
|
+
Python-level prints and C-level writes to fd 1 both land on stderr,
|
|
87
|
+
which the parent keeps as the tool's log.
|
|
88
|
+
"""
|
|
89
|
+
sys.stdout.flush()
|
|
90
|
+
replies = os.fdopen(os.dup(sys.stdout.fileno()), "wb")
|
|
91
|
+
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
|
|
92
|
+
sys.stdout = sys.stderr
|
|
93
|
+
return replies
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _dispatch(handler: Handler, method: str, params: dict[str, Any]) -> Any:
|
|
97
|
+
if method == "describe":
|
|
98
|
+
return handler.describe()
|
|
99
|
+
if method == "health":
|
|
100
|
+
return handler.health(params)
|
|
101
|
+
if method == "prepare":
|
|
102
|
+
handler.prepare(params)
|
|
103
|
+
return {"prepared": params.get("image_id")}
|
|
104
|
+
if method == "invoke":
|
|
105
|
+
return handler.invoke(params)
|
|
106
|
+
raise ToolError(f"unknown method {method!r}", code="unknown_method")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Terminal front-end: argparse commands, the interactive menu, and rendering.
|
|
2
|
+
|
|
3
|
+
``main`` is exposed lazily. Importing it eagerly would make
|
|
4
|
+
``python -m data_factory.cli.main`` load the module twice and warn about it.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
__all__ = ["build_parser", "main"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def __getattr__(name: str) -> Any:
|
|
15
|
+
if name in __all__:
|
|
16
|
+
# import_module, not `from . import main`: that asks this package for
|
|
17
|
+
# an attribute "main" first -- which is this function again, forever.
|
|
18
|
+
import importlib
|
|
19
|
+
|
|
20
|
+
return getattr(importlib.import_module(f"{__name__}.main"), name)
|
|
21
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|