Handle case where classification images are deleted

This commit is contained in:
Nicolas Mowen 2025-11-10 05:51:03 -07:00
parent c0f1fa1f61
commit b8216d0536
3 changed files with 11 additions and 4 deletions

View File

@ -595,9 +595,13 @@ def get_classification_dataset(name: str):
"last_training_image_count": 0,
"current_image_count": current_image_count,
"new_images_count": current_image_count,
"dataset_changed": current_image_count > 0,
}
else:
last_training_count = metadata.get("last_training_image_count", 0)
# Dataset has changed if count is different (either added or deleted images)
dataset_changed = current_image_count != last_training_count
# Only show positive count for new images (ignore deletions in the count display)
new_images_count = max(0, current_image_count - last_training_count)
training_metadata = {
"has_trained": True,
@ -605,6 +609,7 @@ def get_classification_dataset(name: str):
"last_training_image_count": last_training_count,
"current_image_count": current_image_count,
"new_images_count": new_images_count,
"dataset_changed": dataset_changed,
}
return JSONResponse(

View File

@ -16,6 +16,7 @@
"tooltip": {
"trainingInProgress": "Model is currently training",
"noNewImages": "No new images to train. Classify more images in the dataset first.",
"noChanges": "No changes to the dataset since last training.",
"modelNotReady": "Model is not ready for training"
},
"toast": {

View File

@ -126,6 +126,7 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
last_training_image_count: number;
current_image_count: number;
new_images_count: number;
dataset_changed: boolean;
} | null;
}>(`classification/${model.name}/dataset`);
@ -445,7 +446,7 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
variant={modelState == "failed" ? "destructive" : "select"}
disabled={
(modelState != "complete" && modelState != "failed") ||
(trainingMetadata?.new_images_count ?? 0) === 0
!trainingMetadata?.dataset_changed
}
>
{modelState == "training" ? (
@ -466,14 +467,14 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
)}
</Button>
</TooltipTrigger>
{((trainingMetadata?.new_images_count ?? 0) === 0 ||
{(!trainingMetadata?.dataset_changed ||
(modelState != "complete" && modelState != "failed")) && (
<TooltipPortal>
<TooltipContent>
{modelState == "training"
? t("tooltip.trainingInProgress")
: trainingMetadata?.new_images_count === 0
? t("tooltip.noNewImages")
: !trainingMetadata?.dataset_changed
? t("tooltip.noChanges")
: t("tooltip.modelNotReady")}
</TooltipContent>
</TooltipPortal>