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, "last_training_image_count": 0,
"current_image_count": current_image_count, "current_image_count": current_image_count,
"new_images_count": current_image_count, "new_images_count": current_image_count,
"dataset_changed": current_image_count > 0,
} }
else: else:
last_training_count = metadata.get("last_training_image_count", 0) 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) new_images_count = max(0, current_image_count - last_training_count)
training_metadata = { training_metadata = {
"has_trained": True, "has_trained": True,
@ -605,6 +609,7 @@ def get_classification_dataset(name: str):
"last_training_image_count": last_training_count, "last_training_image_count": last_training_count,
"current_image_count": current_image_count, "current_image_count": current_image_count,
"new_images_count": new_images_count, "new_images_count": new_images_count,
"dataset_changed": dataset_changed,
} }
return JSONResponse( return JSONResponse(

View File

@ -16,6 +16,7 @@
"tooltip": { "tooltip": {
"trainingInProgress": "Model is currently training", "trainingInProgress": "Model is currently training",
"noNewImages": "No new images to train. Classify more images in the dataset first.", "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" "modelNotReady": "Model is not ready for training"
}, },
"toast": { "toast": {

View File

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