Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download models #54

Merged
merged 19 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
shadow libs.qupath.fxtras
shadow libs.bioimageio.spec
shadow libs.deepJavaLibrary
shadow libs.commonmark

implementation 'io.github.qupath:qupath-extension-djl:0.3.0'

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/qupath/ext/instanseg/core/DetectionMeasurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private DetectionMeasurer(Collection<ObjectMeasurements.Compartments> compartmen
Collection<ObjectMeasurements.ShapeFeatures> shapeFeatures,
double downsample) {
this.shapeFeatures = shapeFeatures;
this.downsample = downsample;
this.compartments = compartments;
this.measurements = measurements;
this.downsample = downsample;
}

/**
Expand Down Expand Up @@ -93,15 +93,15 @@ public static class Builder {
.filter(m -> m != ObjectMeasurements.Measurements.VARIANCE) // Skip variance - we have standard deviation
.toList();
private Collection<ObjectMeasurements.ShapeFeatures> shapeFeatures = Arrays.asList(ObjectMeasurements.ShapeFeatures.values());
private double pixelSize;
private double downsample;

/**
* Set the pixel size that measurements should be made at.
* @param pixelSize The pixel size that detections/annotations/etc were made at.
* @return A modified builder.
* Set the desired downsample.
* @param downsample
* @return
*/
public Builder pixelSize(double pixelSize) {
this.pixelSize = pixelSize;
public Builder downsample(double downsample) {
this.downsample = downsample;
return this;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public Builder shapeFeatures(Collection<ObjectMeasurements.ShapeFeatures> shapeF
* @return An immutable detection measurer.
*/
public DetectionMeasurer build() {
return new DetectionMeasurer(compartments, measurements, shapeFeatures, pixelSize);
return new DetectionMeasurer(compartments, measurements, shapeFeatures, downsample);
}
}
}
19 changes: 7 additions & 12 deletions src/main/java/qupath/ext/instanseg/core/InstanSeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -126,7 +127,7 @@ public static Builder builder() {
public void makeMeasurements(ImageData<BufferedImage> imageData, Collection<? extends PathObject> detections) {
double downsample = model.getPreferredDownsample(imageData.getServer().getPixelCalibration());
DetectionMeasurer.builder()
.pixelSize(downsample)
.downsample(downsample)
.build()
.makeMeasurements(imageData, detections);
}
Expand All @@ -135,8 +136,11 @@ private InstanSegResults runInstanSeg(Collection<? extends PathObject> pathObjec

long startTime = System.currentTimeMillis();

Path modelPath;
modelPath = model.getPath().resolve("instanseg.pt");
Optional<Path> oModelPath = model.getPath();
if (!oModelPath.isPresent()) {
return new InstanSegResults(0, 0, 0, 0, 0);
}
Path modelPath = oModelPath.get().resolve("instanseg.pt");
int nPredictors = 1; // todo: change me?

// Optionally pad images so that every tile has the required size.
Expand Down Expand Up @@ -506,15 +510,6 @@ public Builder modelPath(String path) throws IOException {
return modelPath(Path.of(path));
}

/**
* Set the specific model to be used
* @param name The name of a built-in model
* @return A modified builder
*/
public Builder modelName(String name) {
return model(InstanSegModel.fromName(name));
}

/**
* Set the device to be used
* @param deviceName The name of the device to be used (eg, "gpu", "mps").
Expand Down
Loading
Loading