ibsocr1 commited on
Commit
4aeb35e
·
verified ·
1 Parent(s): 69e874a

Upload 5 files

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -416,9 +416,20 @@ def start_training(epochs, batch_size, learning_rate):
416
  ZeroGPU: starting it from a normal Python background thread can bypass the
417
  GPU allocation context, making the button appear to do nothing.
418
  """
 
419
  if _training["running"]:
420
  return json.dumps(_training, indent=2)
421
- # Basic validation before requesting GPU time.
 
 
 
 
 
 
 
 
 
 
422
  annotated = sum(bool(x.get("annotations")) for x in load_dataset()["images"])
423
  if annotated < 1:
424
  _training = {"running": False, "message": "training failed", "error": "Annotate at least 1 image before training."}
 
416
  ZeroGPU: starting it from a normal Python background thread can bypass the
417
  GPU allocation context, making the button appear to do nothing.
418
  """
419
+ global _training
420
  if _training["running"]:
421
  return json.dumps(_training, indent=2)
422
+ # Validate parameters before requesting GPU time.
423
+ try:
424
+ epochs = max(1, int(epochs))
425
+ batch_size = max(1, int(batch_size))
426
+ learning_rate = float(learning_rate)
427
+ if learning_rate <= 0:
428
+ raise ValueError("Learning rate must be greater than 0.")
429
+ except Exception as e:
430
+ _training = {"running": False, "message": "training failed", "error": f"Invalid training settings: {e}"}
431
+ return json.dumps(_training, indent=2)
432
+
433
  annotated = sum(bool(x.get("annotations")) for x in load_dataset()["images"])
434
  if annotated < 1:
435
  _training = {"running": False, "message": "training failed", "error": "Annotate at least 1 image before training."}