wuhp commited on
Commit
11f1e85
·
verified ·
1 Parent(s): 2cc3e82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -115,7 +115,7 @@ _ROBO_URL_RX = re.compile(r"""
115
  |
116
  (?P<ws2>[A-Za-z0-9\-_]+)/(?P<proj2>[A-Za-z0-9\-_]+)(?:/(?:v)?(?P<ver2>\d+))?
117
  )$
118
- """, re.VERBOSE | re.IGNORECASE)
119
 
120
  def parse_roboflow_url(s: str):
121
  s = s.strip()
@@ -229,7 +229,6 @@ def yolo_to_coco(split_dir_images, split_dir_labels, class_names, out_json):
229
  y = max(0.0, (cy - bh / 2.0) * h)
230
  ww = max(1.0, bw * w)
231
  hh = max(1.0, bh * h)
232
- # clamp right/bottom to image bounds
233
  if x + ww > w:
234
  ww = max(1.0, w - x)
235
  if y + hh > h:
@@ -442,14 +441,24 @@ def _set_first_existing_key_deep(cfg: dict, keys: list, value):
442
 
443
  def _install_supervisely_logger_shim():
444
  """
445
- Creates a minimal shim so `from supervisely.nn.training import train_logger` works.
 
 
 
446
  """
447
- base = pathlib.Path(tempfile.gettempdir()) / "sly_shim" / "supervisely" / "nn"
448
- base.mkdir(parents=True, exist_ok=True)
449
- for p in [base.parent.parent, base.parent, base]:
450
- (p / "__init__.py").write_text("")
451
- (base / "training.py").write_text(textwrap.dedent("""
452
- # minimal shim for backward-compat with older Supervisely examples
 
 
 
 
 
 
 
453
  class _TrainLogger:
454
  def __init__(self): pass
455
  def reset(self): pass
@@ -458,7 +467,8 @@ def _install_supervisely_logger_shim():
458
  def log_image(self, *a, **k): pass
459
  train_logger = _TrainLogger()
460
  """))
461
- return str(base.parent.parent.parent) # .../sly_shim
 
462
 
463
  def _ensure_checkpoint(model_key: str, out_dir: str) -> str | None:
464
  """
 
115
  |
116
  (?P<ws2>[A-Za-z0-9\-_]+)/(?P<proj2>[A-Za-z0-9\-_]+)(?:/(?:v)?(?P<ver2>\d+))?
117
  )$
118
+ """, re.IGNORECASE | re.VERBOSE)
119
 
120
  def parse_roboflow_url(s: str):
121
  s = s.strip()
 
229
  y = max(0.0, (cy - bh / 2.0) * h)
230
  ww = max(1.0, bw * w)
231
  hh = max(1.0, bh * h)
 
232
  if x + ww > w:
233
  ww = max(1.0, w - x)
234
  if y + hh > h:
 
441
 
442
  def _install_supervisely_logger_shim():
443
  """
444
+ Create a *package* shim that shadows site-packages:
445
+ supervisely/nn/training/__init__.py -> exposes train_logger
446
+ Ensures 'from supervisely.nn.training import train_logger' works even if the
447
+ installed 'supervisely' no longer provides it.
448
  """
449
+ root = pathlib.Path(tempfile.gettempdir()) / "sly_shim_pkg"
450
+ pkg_training = root / "supervisely" / "nn" / "training"
451
+ pkg_training.mkdir(parents=True, exist_ok=True)
452
+
453
+ # Make each level a package
454
+ for p in [root / "supervisely", root / "supervisely" / "nn", pkg_training]:
455
+ init_file = p / "__init__.py"
456
+ if not init_file.exists():
457
+ init_file.write_text("")
458
+
459
+ # Our shim __init__.py provides train_logger
460
+ (pkg_training / "__init__.py").write_text(textwrap.dedent("""
461
+ # Minimal shim for backward-compat with older RT-DETRv2 training code.
462
  class _TrainLogger:
463
  def __init__(self): pass
464
  def reset(self): pass
 
467
  def log_image(self, *a, **k): pass
468
  train_logger = _TrainLogger()
469
  """))
470
+ # Return path to prepend to PYTHONPATH
471
+ return str(root)
472
 
473
  def _ensure_checkpoint(model_key: str, out_dir: str) -> str | None:
474
  """