Update app.py
Browse files
app.py
CHANGED
|
@@ -407,13 +407,13 @@ class VideoTagger:
|
|
| 407 |
frame_interval = max(int(frame_interval), 1)
|
| 408 |
is_first_load = self.model is None
|
| 409 |
|
| 410 |
-
if progress:
|
| 411 |
progress(0.0, desc="Loading model..." if is_first_load else "Opening video...")
|
| 412 |
|
| 413 |
# Lazy-load model & labels once per process
|
| 414 |
self._load_model_if_needed()
|
| 415 |
|
| 416 |
-
if progress and is_first_load:
|
| 417 |
progress(0.0, desc="Model loaded. Opening video...")
|
| 418 |
|
| 419 |
cap = cv2.VideoCapture(video_path)
|
|
@@ -451,7 +451,7 @@ class VideoTagger:
|
|
| 451 |
current_batch_size = min(self.batch_size, remaining_frames)
|
| 452 |
|
| 453 |
# While we are still building the batch, keep percent based on *completed* frames only
|
| 454 |
-
if progress:
|
| 455 |
pct = processed_frames / sampled_frames
|
| 456 |
progress(
|
| 457 |
pct,
|
|
@@ -463,7 +463,7 @@ class VideoTagger:
|
|
| 463 |
|
| 464 |
# If batch is full, run inference
|
| 465 |
if len(batch_tensors) >= self.batch_size:
|
| 466 |
-
if progress:
|
| 467 |
beg = processed_frames + 1
|
| 468 |
end = processed_frames + len(batch_tensors)
|
| 469 |
pct = processed_frames / sampled_frames # still only count completed frames
|
|
@@ -488,7 +488,7 @@ class VideoTagger:
|
|
| 488 |
if current_batch < total_batches:
|
| 489 |
current_batch += 1
|
| 490 |
|
| 491 |
-
if progress:
|
| 492 |
pct = processed_frames / sampled_frames
|
| 493 |
progress(
|
| 494 |
pct,
|
|
@@ -505,7 +505,7 @@ class VideoTagger:
|
|
| 505 |
|
| 506 |
# Process any leftover frames in the final partial batch
|
| 507 |
if batch_tensors:
|
| 508 |
-
if progress:
|
| 509 |
beg = processed_frames + 1
|
| 510 |
end = processed_frames + len(batch_tensors)
|
| 511 |
pct = processed_frames / sampled_frames # still only completed frames
|
|
@@ -526,7 +526,7 @@ class VideoTagger:
|
|
| 526 |
)
|
| 527 |
processed_frames += done
|
| 528 |
|
| 529 |
-
if progress:
|
| 530 |
pct = processed_frames / sampled_frames
|
| 531 |
progress(
|
| 532 |
pct,
|
|
@@ -536,7 +536,7 @@ class VideoTagger:
|
|
| 536 |
),
|
| 537 |
)
|
| 538 |
|
| 539 |
-
if progress:
|
| 540 |
progress(1.0, desc="Finalizing tags...")
|
| 541 |
|
| 542 |
# Merge & finalize tags
|
|
|
|
| 407 |
frame_interval = max(int(frame_interval), 1)
|
| 408 |
is_first_load = self.model is None
|
| 409 |
|
| 410 |
+
if progress is not None:
|
| 411 |
progress(0.0, desc="Loading model..." if is_first_load else "Opening video...")
|
| 412 |
|
| 413 |
# Lazy-load model & labels once per process
|
| 414 |
self._load_model_if_needed()
|
| 415 |
|
| 416 |
+
if progress is not None and is_first_load:
|
| 417 |
progress(0.0, desc="Model loaded. Opening video...")
|
| 418 |
|
| 419 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
| 451 |
current_batch_size = min(self.batch_size, remaining_frames)
|
| 452 |
|
| 453 |
# While we are still building the batch, keep percent based on *completed* frames only
|
| 454 |
+
if progress is not None:
|
| 455 |
pct = processed_frames / sampled_frames
|
| 456 |
progress(
|
| 457 |
pct,
|
|
|
|
| 463 |
|
| 464 |
# If batch is full, run inference
|
| 465 |
if len(batch_tensors) >= self.batch_size:
|
| 466 |
+
if progress is not None:
|
| 467 |
beg = processed_frames + 1
|
| 468 |
end = processed_frames + len(batch_tensors)
|
| 469 |
pct = processed_frames / sampled_frames # still only count completed frames
|
|
|
|
| 488 |
if current_batch < total_batches:
|
| 489 |
current_batch += 1
|
| 490 |
|
| 491 |
+
if progress is not None:
|
| 492 |
pct = processed_frames / sampled_frames
|
| 493 |
progress(
|
| 494 |
pct,
|
|
|
|
| 505 |
|
| 506 |
# Process any leftover frames in the final partial batch
|
| 507 |
if batch_tensors:
|
| 508 |
+
if progress is not None:
|
| 509 |
beg = processed_frames + 1
|
| 510 |
end = processed_frames + len(batch_tensors)
|
| 511 |
pct = processed_frames / sampled_frames # still only completed frames
|
|
|
|
| 526 |
)
|
| 527 |
processed_frames += done
|
| 528 |
|
| 529 |
+
if progress is not None:
|
| 530 |
pct = processed_frames / sampled_frames
|
| 531 |
progress(
|
| 532 |
pct,
|
|
|
|
| 536 |
),
|
| 537 |
)
|
| 538 |
|
| 539 |
+
if progress is not None:
|
| 540 |
progress(1.0, desc="Finalizing tags...")
|
| 541 |
|
| 542 |
# Merge & finalize tags
|