Skip to content

Commit f79b6b3

Browse files
committed
Add prediction and prediction image preprocessing settings, add torch serve client error handling, refine scss.
1 parent 289a3b0 commit f79b6b3

23 files changed

+1058
-518
lines changed

src/main/java/com/github/mfl28/boundingboxeditor/controller/Controller.java

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.github.mfl28.boundingboxeditor.model.io.results.*;
2828
import com.github.mfl28.boundingboxeditor.model.io.services.*;
2929
import com.github.mfl28.boundingboxeditor.ui.*;
30+
import com.github.mfl28.boundingboxeditor.ui.settings.InferenceSettingsView;
3031
import com.github.mfl28.boundingboxeditor.ui.settings.SettingsDialogView;
3132
import com.github.mfl28.boundingboxeditor.ui.statusevents.BoundingBoxPredictionSuccessfulEvent;
3233
import com.github.mfl28.boundingboxeditor.ui.statusevents.ImageAnnotationsImportingSuccessfulEvent;
@@ -41,6 +42,7 @@
4142
import javafx.beans.value.ObservableValue;
4243
import javafx.collections.ListChangeListener;
4344
import javafx.concurrent.WorkerStateEvent;
45+
import javafx.event.ActionEvent;
4446
import javafx.scene.Cursor;
4547
import javafx.scene.control.ButtonBar;
4648
import javafx.scene.control.ButtonType;
@@ -180,14 +182,33 @@ public Controller(final Stage mainStage) {
180182
public void onRegisterSettingsAction() {
181183
final SettingsDialogView settingsDialog = view.getSettingsDialog();
182184
settingsDialog.getInferenceSettings()
183-
.setDisplayedSettingsFromConfig(model.getBoundingBoxPredictorClientConfig());
184-
// TODO: update predictor config
185+
.setDisplayedSettingsFromPredictorClientConfig(model.getBoundingBoxPredictorClientConfig());
186+
settingsDialog.getInferenceSettings()
187+
.setDisplayedSettingsFromPredictorConfig(model.getBoundingBoxPredictorConfig());
188+
185189
settingsDialog.showAndWait();
186190
}
187191

188-
public void onRegisterSettingsApplyAction() {
192+
public void onRegisterSettingsApplyAction(ActionEvent event, ButtonType buttonType) {
193+
final InferenceSettingsView inferenceSettingsView = view.getSettingsDialog().getInferenceSettings();
194+
195+
if(buttonType.equals(ButtonType.OK)) {
196+
if(inferenceSettingsView.getInferenceEnabledControl().isSelected() &&
197+
inferenceSettingsView.getSelectedModelLabel().getText().equals("None")) {
198+
MainView.displayErrorAlert("Settings Application Error", "Please select a model or disable inference.");
199+
event.consume();
200+
return;
201+
}
202+
}
203+
189204
view.getSettingsDialog().getInferenceSettings()
190-
.applyDisplayedSettingsToConfig(model.getBoundingBoxPredictorClientConfig());
205+
.applyDisplayedSettingsToPredictorClientConfig(model.getBoundingBoxPredictorClientConfig());
206+
view.getSettingsDialog().getInferenceSettings()
207+
.applyDisplayedSettingsToPredictorConfig(model.getBoundingBoxPredictorConfig());
208+
209+
if(buttonType.equals(ButtonType.APPLY)) {
210+
event.consume();
211+
}
191212
}
192213

193214
/**
@@ -206,8 +227,6 @@ public void onRegisterOpenImageFolderAction() {
206227
public void onRegisterPerformCurrentImageBoundingBoxPredictionAction() {
207228
if(model.containsImageFiles()) {
208229
initiateBoundingBoxPrediction(model.getCurrentImageFile());
209-
} else {
210-
// TODO: Error handling
211230
}
212231
}
213232

@@ -286,7 +305,7 @@ public void onRegisterImportAnnotationsAction(ImageAnnotationLoadStrategy.Type l
286305
public void onRegisterModelNameFetchingAction() {
287306
modelNameFetchService.reset();
288307
final BoundingBoxPredictorClientConfig clientConfig = new BoundingBoxPredictorClientConfig();
289-
view.getSettingsDialog().getInferenceSettings().applyDisplayedSettingsToConfig(clientConfig);
308+
view.getSettingsDialog().getInferenceSettings().applyDisplayedSettingsToPredictorClientConfig(clientConfig);
290309
modelNameFetchService.setClientConfig(clientConfig);
291310
modelNameFetchService.restart();
292311
}
@@ -585,6 +604,13 @@ public Model getModel() {
585604
return model;
586605
}
587606

607+
public void onRegisterSettingsCancelCloseAction() {
608+
view.getSettingsDialog().getInferenceSettings()
609+
.setDisplayedSettingsFromPredictorClientConfig(model.getBoundingBoxPredictorClientConfig());
610+
view.getSettingsDialog().getInferenceSettings()
611+
.setDisplayedSettingsFromPredictorConfig(model.getBoundingBoxPredictorConfig());
612+
}
613+
588614
IoMetaData getIoMetaData() {
589615
return ioMetaData;
590616
}
@@ -633,7 +659,8 @@ private void onBoundingBoxPredictionSucceeded(WorkerStateEvent event) {
633659
final BoundingBoxPredictionResult predictionResult = boundingBoxPredictorService.getValue();
634660

635661
if(predictionResult.getNrSuccessfullyProcessedItems() != 0) {
636-
model.updateFromImageAnnotationData(predictionResult.getImageAnnotationData());
662+
model.updateFromImageAnnotationData(predictionResult.getImageAnnotationData(),
663+
predictionResult.getOperationType());
637664
view.getStatusBar().setStatusEvent(new BoundingBoxPredictionSuccessfulEvent(predictionResult));
638665
}
639666

@@ -651,8 +678,10 @@ private void onBoundingBoxPredictionSucceeded(WorkerStateEvent event) {
651678
}
652679

653680
if(!predictionResult.getErrorTableEntries().isEmpty()) {
681+
UiUtils.closeProgressDialog(view.getBoundingBoxPredictorProgressDialog());
654682
MainView.displayIOResultErrorInfoAlert(predictionResult);
655683
} else if(predictionResult.getNrSuccessfullyProcessedItems() == 0) {
684+
UiUtils.closeProgressDialog(view.getBoundingBoxPredictorProgressDialog());
656685
MainView.displayErrorAlert("Bounding Box Prediction Error",
657686
"Could not predict any bounding boxes.");
658687
}
@@ -724,7 +753,7 @@ private void onModelNameFetchingSucceeded(WorkerStateEvent workerStateEvent) {
724753
.ifPresent(s -> view.getSettingsDialog().getInferenceSettings().getSelectedModelLabel().setText(s));
725754

726755
} else {
727-
MainView.displayErrorAlert("Model Name Fetching Error", "The server did not report any models.");
756+
MainView.displayIOResultErrorInfoAlert(result);
728757
}
729758
}
730759

@@ -825,11 +854,11 @@ private void onValidFilesPresentHandler(boolean keepCategories) {
825854
}
826855

827856
private void onAnnotationImportSucceeded(WorkerStateEvent workerStateEvent) {
828-
ImageAnnotationImportResult loadResult = annotationImportService.getValue();
857+
ImageAnnotationImportResult importResult = annotationImportService.getValue();
829858

830-
if(loadResult.getNrSuccessfullyProcessedItems() != 0) {
831-
model.updateFromImageAnnotationData(loadResult.getImageAnnotationData());
832-
view.getStatusBar().setStatusEvent(new ImageAnnotationsImportingSuccessfulEvent(loadResult));
859+
if(importResult.getNrSuccessfullyProcessedItems() != 0) {
860+
model.updateFromImageAnnotationData(importResult.getImageAnnotationData(), importResult.getOperationType());
861+
view.getStatusBar().setStatusEvent(new ImageAnnotationsImportingSuccessfulEvent(importResult));
833862
}
834863

835864
updateViewFileExplorerFileInfoElements();
@@ -845,10 +874,10 @@ private void onAnnotationImportSucceeded(WorkerStateEvent workerStateEvent) {
845874
view.getObjectTree().refresh();
846875
}
847876

848-
if(!loadResult.getErrorTableEntries().isEmpty()) {
877+
if(!importResult.getErrorTableEntries().isEmpty()) {
849878
UiUtils.closeProgressDialog(view.getAnnotationImportProgressDialog());
850-
MainView.displayIOResultErrorInfoAlert(loadResult);
851-
} else if(loadResult.getNrSuccessfullyProcessedItems() == 0) {
879+
MainView.displayIOResultErrorInfoAlert(importResult);
880+
} else if(importResult.getNrSuccessfullyProcessedItems() == 0) {
852881
UiUtils.closeProgressDialog(view.getAnnotationImportProgressDialog());
853882
MainView.displayErrorAlert(ANNOTATION_IMPORT_ERROR_TITLE,
854883
ANNOTATION_IMPORT_ERROR_NO_VALID_FILES_CONTENT);
@@ -1106,6 +1135,9 @@ private void setUpModelListeners() {
11061135
});
11071136

11081137
view.getStatusBar().savedStatusProperty().bind(model.savedProperty());
1138+
1139+
view.getEditor().getEditorToolBar().getPredictButton()
1140+
.visibleProperty().bind(model.getBoundingBoxPredictorConfig().inferenceEnabledProperty());
11091141
}
11101142

11111143
private List<File> getImageFilesFromDirectory(File directory) throws IOException {

src/main/java/com/github/mfl28/boundingboxeditor/model/Model.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
package com.github.mfl28.boundingboxeditor.model;
2020

2121
import com.github.mfl28.boundingboxeditor.model.data.*;
22-
import com.github.mfl28.boundingboxeditor.model.io.BoundingBoxPredictorConfig;
2322
import com.github.mfl28.boundingboxeditor.model.io.BoundingBoxPredictorClientConfig;
23+
import com.github.mfl28.boundingboxeditor.model.io.BoundingBoxPredictorConfig;
24+
import com.github.mfl28.boundingboxeditor.model.io.results.IOResult;
2425
import javafx.beans.property.BooleanProperty;
2526
import javafx.beans.property.IntegerProperty;
2627
import javafx.beans.property.SimpleBooleanProperty;
@@ -184,7 +185,8 @@ public void updateBoundingShapeDataAtFileIndex(int fileIndex, List<BoundingShape
184185
*
185186
* @param imageAnnotations the new image-annotations
186187
*/
187-
public void updateImageAnnotations(Collection<ImageAnnotation> imageAnnotations) {
188+
public void updateImageAnnotations(Collection<ImageAnnotation> imageAnnotations,
189+
IOResult.OperationType operationType) {
188190
boolean noCurrentAnnotations = imageFileNameToAnnotation.isEmpty();
189191

190192
imageAnnotations.forEach(annotation -> {
@@ -198,7 +200,11 @@ public void updateImageAnnotations(Collection<ImageAnnotation> imageAnnotations)
198200
});
199201

200202
if(!imageAnnotations.isEmpty()) {
201-
saved.set(noCurrentAnnotations);
203+
if(operationType.equals(IOResult.OperationType.ANNOTATION_IMPORT)) {
204+
saved.set(noCurrentAnnotations);
205+
} else if(operationType.equals(IOResult.OperationType.BOUNDING_BOX_PREDICTION)) {
206+
saved.set(false);
207+
}
202208
}
203209
}
204210

@@ -296,13 +302,14 @@ public ImageAnnotationData createImageAnnotationData() {
296302
*
297303
* @param imageAnnotationData the image-annotation data
298304
*/
299-
public void updateFromImageAnnotationData(ImageAnnotationData imageAnnotationData) {
305+
public void updateFromImageAnnotationData(ImageAnnotationData imageAnnotationData,
306+
IOResult.OperationType operationType) {
300307
final Map<String, Integer> updatedCategoryNameToBoundingShapeCountMap =
301308
createMergedCategoryToBoundingShapeCountMap(
302309
imageAnnotationData.getCategoryNameToBoundingShapeCountMap());
303310
updateObjectCategoriesFromData(imageAnnotationData.getCategoryNameToCategoryMap());
304311
categoryToAssignedBoundingShapesCount.putAll(updatedCategoryNameToBoundingShapeCountMap);
305-
updateImageAnnotations(imageAnnotationData.getImageAnnotations());
312+
updateImageAnnotations(imageAnnotationData.getImageAnnotations(), operationType);
306313
}
307314

308315
/**

0 commit comments

Comments
 (0)