Skip to content

Commit 4f6c9ed

Browse files
committed
UX refinements
1 parent 6dc829a commit 4f6c9ed

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

src/main/java/qupath/ext/xgboost/XGBoostTrainer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import qupath.lib.objects.PathObject;
99
import qupath.lib.projects.ProjectImageEntry;
1010
import qupath.lib.objects.PathObjectTools;
11+
import java.util.Objects;
1112

1213

1314
import java.awt.image.BufferedImage;
@@ -105,7 +106,15 @@ public static void train(
105106
List<PathObject> validDets = new ArrayList<>(detClass.keySet());
106107

107108
if (validDets.isEmpty()) {
108-
log.accept(" " + entry.getImageName() + ": 0 training objects found");
109+
long annoCount = hierarchy.getAnnotationObjects().stream()
110+
.filter(a -> a.getPathClass() != null && classNames.contains(a.getPathClass().toString()))
111+
.count();
112+
long detCount = hierarchy.getDetectionObjects().size();
113+
long conflicts = detClass.values().stream().filter(Objects::isNull).count();
114+
log.accept(" " + entry.getImageName() + ": 0 training objects found"
115+
+ " (matching annotations: " + annoCount
116+
+ ", detections: " + detCount
117+
+ ", conflicts discarded: " + conflicts + ")");
109118
continue;
110119
}
111120

@@ -175,9 +184,10 @@ record FeatureScore(String name, double score, int idx) {}
175184
String.format(" %-50s %.0f", fs.name(), fs.score())));
176185

177186
// ── 6. Select top-N features ────────────────────────────────────────────
178-
List<FeatureScore> selected = (topNFeatures > 0 && topNFeatures < nFeatures)
187+
List<FeatureScore> selected = (topNFeatures > 0 && topNFeatures < ranked.size())
179188
? ranked.subList(0, topNFeatures)
180189
: ranked;
190+
181191
int[] selIdx = selected.stream().mapToInt(FeatureScore::idx).toArray();
182192
log.accept("\nUsing " + selIdx.length + " features for final model.");
183193

src/main/java/qupath/ext/xgboost/ui/InferController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ private void runInference() {
272272
});
273273
}
274274
@Override protected void succeeded() {
275-
Platform.runLater(() -> runButton.setDisable(false));
275+
Platform.runLater(() -> {
276+
runButton.setDisable(false);
277+
qupath.refreshProject();
278+
});
276279
}
277280
};
278281
new Thread(task, "xgboost-infer") {{ setDaemon(true); }}.start();

src/main/java/qupath/ext/xgboost/ui/TrainController.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import qupath.lib.objects.PathObjectTools;
2121
import qupath.lib.objects.classes.PathClass;
2222
import qupath.lib.projects.ProjectImageEntry;
23+
import qupath.lib.gui.dialogs.ProjectDialogs;
24+
import qupath.fx.dialogs.Dialogs;
2325

2426
import java.awt.image.BufferedImage;
2527
import java.io.File;
@@ -491,6 +493,25 @@ private void runTraining() {
491493
float subsample = subsampleSpinner.getValue().floatValue();
492494
int topN = topNSpinner.getValue();
493495

496+
// Warn if any selected entry is currently open (may have unsaved changes)
497+
List<ProjectImageEntry<BufferedImage>> openAndSelected = selectedEntries.stream()
498+
.filter(ProjectDialogs.getCurrentImages(qupath)::contains)
499+
.collect(Collectors.toList());
500+
501+
if (!openAndSelected.isEmpty()) {
502+
String names = openAndSelected.stream()
503+
.map(ProjectImageEntry::getImageName)
504+
.collect(Collectors.joining("\n "));
505+
var result = Dialogs.builder()
506+
.title("Unsaved changes?")
507+
.content(new Label("The following images are open in a viewer and may have unsaved changes:\n\n "
508+
+ names + "\n\nSave them first (Ctrl+S) to include the latest annotations.\nContinue anyway?"))
509+
.buttons(ButtonType.YES, ButtonType.NO)
510+
.showAndWait()
511+
.orElse(ButtonType.NO);
512+
if (result != ButtonType.YES) return;
513+
}
514+
494515
logArea.clear();
495516
trainButton.setDisable(true);
496517

0 commit comments

Comments
 (0)