Skip to content

Commit

Permalink
Merge pull request #8 from petebankhead/dev
Browse files Browse the repository at this point in the history
Initial update for v0.5.0
  • Loading branch information
petebankhead authored Nov 13, 2023
2 parents 2fcdacb + 73179ab commit c32cdae
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 54 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
uses: gradle/wrapper-validation-action@v1
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
with:
arguments: build
- uses: actions/upload-artifact@v3
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
uses: gradle/wrapper-validation-action@v1
- name: Publish snapshot
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
with:
arguments: publish -P release=true
env:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
uses: gradle/wrapper-validation-action@v1
- name: Publish snapshot
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
Expand Down
25 changes: 13 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
plugins {
id 'java-library'
id 'maven-publish'
// To manage included native libraries
alias(libs.plugins.javacpp)
// Need to use this instead (without version) if running as a QuPath subproject
// id 'org.bytedeco.gradle-javacpp-platform'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.openjfx.javafxplugin' version '0.1.0'
// Version in settings.gradle
id 'org.bytedeco.gradle-javacpp-platform'
}

ext.moduleName = 'qupath.extension.djl'
ext.qupathVersion = gradle.ext.qupathVersion

description = 'QuPath extension to use Deep Java Library'
version = "0.2.0"
version = "0.3.0-SNAPSHOT"
group = 'io.github.qupath'

def djlVersion = libs.versions.deepJavaLibrary.get()

Expand All @@ -33,11 +34,12 @@ repositories {


dependencies {
implementation "io.github.qupath:qupath-gui-fx:${qupathVersion}"

shadow "io.github.qupath:qupath-gui-fx:${qupathVersion}"
shadow libs.qupath.fxtras

// These are included in QuPath distributions
implementation libs.bundles.logging
implementation libs.snakeyaml
shadow libs.bundles.logging
shadow libs.snakeyaml

implementation "ai.djl:api:$djlVersion"

Expand All @@ -61,11 +63,11 @@ tasks.register("copyDependencies", Copy) {
}

/*
* Ensure Java 11 compatibility
* Ensure Java 17 compatibility
*/
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
languageVersion = JavaLanguageVersion.of(17)
}
if (project.properties['sources'])
withSourcesJar()
Expand Down Expand Up @@ -134,7 +136,6 @@ publishing {

publications {
mavenJava(MavenPublication) {
groupId = 'io.github.qupath'
from components.java

pom {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
8 changes: 7 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
pluginManagement {
plugins {
id 'org.bytedeco.gradle-javacpp-platform' version '1.5.9'
}
}

rootProject.name = 'qupath-extension-djl'

gradle.ext.qupathVersion = "0.4.0"
gradle.ext.qupathVersion = "0.5.0-SNAPSHOT"

dependencyResolutionManagement {

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/qupath/ext/djl/DjlDnnModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ private void ensureInitialized() {
}

if (this.outputs == null || this.outputs.isEmpty()) {
var description = model.describeOutput();
if (description != null && !description.isEmpty())
outputs = description.stream().collect(Collectors.toMap(p -> p.getKey(), p -> DjlTools.convertShape(p.getValue())));
else
try {
var description = model.describeOutput();
if (description != null && !description.isEmpty())
outputs = description.stream().collect(Collectors.toMap(p -> p.getKey(), p -> DjlTools.convertShape(p.getValue())));
} catch (Exception e) {
logger.debug(e.getMessage(), e);
}
if (this.outputs == null || this.outputs.isEmpty())
outputs = Map.of(DnnModel.DEFAULT_OUTPUT_NAME, DnnShape.UNKNOWN_SHAPE);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/qupath/ext/djl/DjlDnnModelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ private static String estimateEngine(URI uri) {
if (Engine.hasEngine(DjlTools.ENGINE_PYTORCH))
return DjlTools.ENGINE_PYTORCH;
}

if (urlString.endsWith(".tflite")) {
if (Engine.hasEngine(DjlTools.ENGINE_TFLITE))
return DjlTools.ENGINE_TFLITE;
}

var path = GeneralTools.toPath(uri);
if (path != null) {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/qupath/ext/djl/DjlEngineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

Expand Down Expand Up @@ -51,11 +52,12 @@
import javafx.scene.shape.Circle;
import javafx.stage.Modality;
import javafx.stage.Stage;
import qupath.fx.dialogs.Dialogs;
import qupath.fx.utils.GridPaneUtils;
import qupath.lib.common.GeneralTools;
import qupath.lib.common.ThreadTools;
import qupath.lib.gui.QuPathGUI;
import qupath.lib.gui.dialogs.Dialogs;
import qupath.lib.gui.tools.GuiTools;
import qupath.lib.gui.tools.PaneTools;

/**
* Command to display Deep Java Library engines.
Expand All @@ -70,7 +72,7 @@ public class DjlEngineCommand {

private QuPathGUI qupath;

private static enum EngineStatus {
private enum EngineStatus {
UNAVAILABLE, UNKNOWN, PENDING, AVAILABLE, FAILED
}

Expand Down Expand Up @@ -115,23 +117,23 @@ private void init() {
"Download Deep Java Library engines for inference."
);
label.setWrapText(true);
PaneTools.addGridRow(pane, row++, 0, null, label, label);
GridPaneUtils.addGridRow(pane, row++, 0, null, label, label);
var label2 = new Label(
"These will be stored in the local directories shown."
);
label2.setWrapText(true);
PaneTools.addGridRow(pane, row++, 0, null, label2, label2);
GridPaneUtils.addGridRow(pane, row++, 0, null, label2, label2);

var label3 = new Label(
"Please check the original engine's website for any licensing information.\n"
);
label3.setWrapText(true);
PaneTools.addGridRow(pane, row++, 0, null, label3, label3);
GridPaneUtils.addGridRow(pane, row++, 0, null, label3, label3);

for (var name : Engine.getAllEngines()) {
var separator = new Separator(Orientation.HORIZONTAL);
PaneTools.addGridRow(pane, row++, 0, null, separator, separator);
PaneTools.setToExpandGridPaneWidth(separator);
GridPaneUtils.addGridRow(pane, row++, 0, null, separator, separator);
GridPaneUtils.setToExpandGridPaneWidth(separator);

var status = available.computeIfAbsent(name, n -> new SimpleObjectProperty<>(EngineStatus.UNKNOWN));

Expand All @@ -140,7 +142,7 @@ private void init() {
String tooltip = "Engine: " + name;
var labelName = new Label(name);
labelName.setStyle("-fx-font-weight: bold;");
PaneTools.addGridRow(pane, row++, 0, tooltip, labelName, labelName);
GridPaneUtils.addGridRow(pane, row++, 0, tooltip, labelName, labelName);

var labelPath = new Label(path.toString());
var btnDownload = new Button("Download");
Expand Down Expand Up @@ -223,10 +225,10 @@ private void init() {
else
logger.debug("Cannot open {} - directory does not exist", path);
});
PaneTools.addGridRow(pane, row++, 0, null, labelPathLabel, labelPath);
PaneTools.addGridRow(pane, row++, 0, null, btnDownload, btnDownload);
GridPaneUtils.addGridRow(pane, row++, 0, null, labelPathLabel, labelPath);
GridPaneUtils.addGridRow(pane, row++, 0, null, btnDownload, btnDownload);

PaneTools.setToExpandGridPaneWidth(labelName, labelPath, btnDownload);
GridPaneUtils.setToExpandGridPaneWidth(labelName, labelPath, btnDownload);

// Update the engine status quietly
checkEngineStatus(name, status, -1, true);
Expand All @@ -248,12 +250,12 @@ private void showDialog() {

private void checkEngineStatus(String name, ObjectProperty<EngineStatus> status, long timeoutMillis, boolean doQuietly) {
// Request the engine in a background thread, triggering download if necessary
var pool = qupath.createSingleThreadExecutor(this);
var pool = Executors.newSingleThreadExecutor(ThreadTools.createThreadFactory("djl-engine-request", true));
updateStatus(status, EngineStatus.PENDING);
var future = pool.submit((Callable<Boolean>)() -> checkEngineAvailability(name, status, doQuietly));
if (timeoutMillis <= 0)
return;

pool.shutdown();
try {
// Wait until the timeout - engine might already be available & return quickly
var result = future.get(timeoutMillis, TimeUnit.MILLISECONDS);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/qupath/ext/djl/DjlExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public GitHubRepo getRepository() {

@Override
public Version getQuPathVersion() {
return Version.parse("0.4.0-SNAPSHOT");
return Version.parse("0.5.0-SNAPSHOT");
}


Expand Down

0 comments on commit c32cdae

Please sign in to comment.