Update app.py
Browse files
app.py
CHANGED
|
@@ -467,7 +467,9 @@ def _install_workspace_shim_v3(cwd_for_train: str, module_default: str = "rtdetr
|
|
| 467 |
The shim ensures kwargs['cfg'] is a dict, then guarantees cfg['_pymodule'] is a *module object*.
|
| 468 |
"""
|
| 469 |
sc_path = os.path.join(cwd_for_train, "sitecustomize.py")
|
| 470 |
-
|
|
|
|
|
|
|
| 471 |
import os, importlib, types
|
| 472 |
try:
|
| 473 |
mod_default = os.environ.get("RTDETR_PYMODULE", "{module_default}") or "{module_default}"
|
|
@@ -503,15 +505,17 @@ def _install_workspace_shim_v3(cwd_for_train: str, module_default: str = "rtdetr
|
|
| 503 |
def create(name, **kwargs):
|
| 504 |
cfg = kwargs.get("cfg")
|
| 505 |
if not isinstance(cfg, dict):
|
| 506 |
-
cfg = {} if cfg is None else dict(cfg)
|
| 507 |
kwargs["cfg"] = cfg
|
| 508 |
_ensure_pymodule_object(cfg)
|
| 509 |
return _orig_create(name, **kwargs)
|
| 510 |
|
| 511 |
ws_mod.create = create
|
| 512 |
except Exception:
|
|
|
|
| 513 |
pass
|
| 514 |
-
""")
|
|
|
|
| 515 |
with open(sc_path, "w", encoding="utf-8") as f:
|
| 516 |
f.write(code)
|
| 517 |
return sc_path
|
|
|
|
| 467 |
The shim ensures kwargs['cfg'] is a dict, then guarantees cfg['_pymodule'] is a *module object*.
|
| 468 |
"""
|
| 469 |
sc_path = os.path.join(cwd_for_train, "sitecustomize.py")
|
| 470 |
+
|
| 471 |
+
# NOTE: Not an f-string. Escape literal braces with {{ }} and only format {module_default}.
|
| 472 |
+
code = textwrap.dedent("""\
|
| 473 |
import os, importlib, types
|
| 474 |
try:
|
| 475 |
mod_default = os.environ.get("RTDETR_PYMODULE", "{module_default}") or "{module_default}"
|
|
|
|
| 505 |
def create(name, **kwargs):
|
| 506 |
cfg = kwargs.get("cfg")
|
| 507 |
if not isinstance(cfg, dict):
|
| 508 |
+
cfg = {{}} if cfg is None else dict(cfg)
|
| 509 |
kwargs["cfg"] = cfg
|
| 510 |
_ensure_pymodule_object(cfg)
|
| 511 |
return _orig_create(name, **kwargs)
|
| 512 |
|
| 513 |
ws_mod.create = create
|
| 514 |
except Exception:
|
| 515 |
+
# never block training if shim fails
|
| 516 |
pass
|
| 517 |
+
""").format(module_default=module_default)
|
| 518 |
+
|
| 519 |
with open(sc_path, "w", encoding="utf-8") as f:
|
| 520 |
f.write(code)
|
| 521 |
return sc_path
|