jeyanthangj2004 commited on
Commit
e839198
·
verified ·
1 Parent(s): e0f6328

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -217,12 +217,11 @@ model = YOLO(str(model_yaml))
217
  TRAINING_STATUS = "Starting Training... (Check Logs for details)"
218
  print("Starting Training...")
219
 
220
- # Define callback to update status
221
  def on_train_epoch_end(trainer):
222
  global TRAINING_STATUS
223
  current_epoch = trainer.epoch + 1
224
  total_epochs = trainer.epochs
225
- # Try to get mAP if available, otherwise just epoch
226
  try:
227
  metrics = trainer.metrics
228
  map50 = metrics.get("metrics/mAP50(B)", 0)
@@ -230,7 +229,18 @@ def on_train_epoch_end(trainer):
230
  except:
231
  TRAINING_STATUS = f"Training in progress...<br>Epoch: {current_epoch}/{total_epochs}"
232
 
 
 
 
 
 
 
 
 
 
 
233
  model.add_callback("on_train_epoch_end", on_train_epoch_end)
 
234
 
235
  # Train 200 epochs, CPU only
236
  results = model.train(
 
217
  TRAINING_STATUS = "Starting Training... (Check Logs for details)"
218
  print("Starting Training...")
219
 
220
+ # Define callbacks to update status
221
  def on_train_epoch_end(trainer):
222
  global TRAINING_STATUS
223
  current_epoch = trainer.epoch + 1
224
  total_epochs = trainer.epochs
 
225
  try:
226
  metrics = trainer.metrics
227
  map50 = metrics.get("metrics/mAP50(B)", 0)
 
229
  except:
230
  TRAINING_STATUS = f"Training in progress...<br>Epoch: {current_epoch}/{total_epochs}"
231
 
232
+ def on_train_batch_end(trainer):
233
+ global TRAINING_STATUS
234
+ # Update status every 5 batches to avoid over-refreshing
235
+ if hasattr(trainer, 'pbar') and trainer.pbar and trainer.pbar.n % 5 == 0:
236
+ current_epoch = trainer.epoch + 1
237
+ total_epochs = trainer.epochs
238
+ current_batch = trainer.pbar.n
239
+ total_batch = trainer.pbar.total or "?"
240
+ TRAINING_STATUS = f"<b>Training Running...</b><br>Epoch: {current_epoch}/{total_epochs}<br>Batch: {current_batch}/{total_batch}<br><i>(CPU training is slow, please wait)</i>"
241
+
242
  model.add_callback("on_train_epoch_end", on_train_epoch_end)
243
+ model.add_callback("on_train_batch_end", on_train_batch_end)
244
 
245
  # Train 200 epochs, CPU only
246
  results = model.train(