Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/qupath/ext/wsinfer/WSInfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ public static void runInference(ImageData<BufferedImage> imageData, WSInferModel
}
}

boolean applySoftmax = true;
Translator translator = buildTranslator(wsiModel, pipeline, applySoftmax);
Translator translator = buildTranslator(wsiModel, pipeline);
Criteria<Image, Classifications> criteria = buildCriteria(wsiModel, translator, device);
List<String> classNames = wsiModel.getConfiguration().getClassNames();
long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -308,13 +307,13 @@ private static boolean isMPS(Device device) {
}


private static Translator<Image, Classifications> buildTranslator(WSInferModel wsiModel, Pipeline pipeline, boolean applySoftmax) {
private static Translator<Image, Classifications> buildTranslator(WSInferModel wsiModel, Pipeline pipeline) {
// We should use ImageClassificationTranslator.builder() in the future if this is updated to work with MPS
// (See javadocs for MpsSupport.WSInferClassificationTranslator for details)
// ImageClassificationTranslator.Builder builder = ImageClassificationTranslator.builder()
return MpsSupport.WSInferClassificationTranslator.builder()
.optSynset(wsiModel.getConfiguration().getClassNames())
.optApplySoftmax(applySoftmax)
.optApplySoftmax(wsiModel.getConfiguration().isApplySoftmax())
.setPipeline(pipeline)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class WSInferModelConfiguration {
@SerializedName("spacing_um_px")
private double spacingUmPx;

@SerializedName("apply_softmax")
private boolean applySoftmax = true;

private List<WSInferTransform> transform;

/**
Expand Down Expand Up @@ -78,4 +81,12 @@ public double getPatchSizePixels() {
public double getSpacingMicronPerPixel() {
return spacingUmPx;
}

/**
* Whether to apply softmax to model output
* @return
*/
public boolean isApplySoftmax() {
return applySoftmax;
}
}