Skip to content

Commit

Permalink
Merge pull request #19 from qupath/tf-and-online-prop
Browse files Browse the repository at this point in the history
Switch to domain named prop and fix tensorflow toString issue
  • Loading branch information
petebankhead authored May 1, 2024
2 parents e73df2f + 26bb25e commit b82abb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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 @@ -43,7 +43,7 @@ public class DjlExtension implements QuPathExtension, GitHubProject {

static {
// Prevent downloading engines automatically
System.setProperty("offline", "true");
System.setProperty("ai.djl.offline", "true");
// Opt out of tracking, see https://github.com/deepjavalibrary/djl/pull/2178/files
System.setProperty("OPT_OUT_TRACKING", "true");
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/qupath/ext/djl/DjlTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,20 @@ public static Engine getEngine(String name, boolean downloadIfNeeded) throws Ill
}

synchronized (lock) {
var offlineStatus = System.getProperty("offline");
var offlineStatus = System.getProperty("ai.djl.offline");
try {
if (downloadIfNeeded)
System.setProperty("offline", "false");
System.setProperty("ai.djl.offline", "false");
else
System.setProperty("offline", "true");

System.setProperty("ai.djl.offline", "true");
var engine = Engine.getEngine(name);
if (engine != null)
loadedEngines.add(name);
return engine;
} catch (Exception e) {
if (downloadIfNeeded)
if (downloadIfNeeded) {
logger.error("Unable to get engine " + name + ": " + e.getMessage(), e);
else {
} else {
var msg = e.getLocalizedMessage();
if (msg == null)
logger.warn("Unable to get engine {}", name);
Expand All @@ -268,7 +267,7 @@ public static Engine getEngine(String name, boolean downloadIfNeeded) throws Ill
}
return null;
} finally {
System.setProperty("offline", offlineStatus);
System.setProperty("ai.djl.offline", offlineStatus);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/qupath/ext/djl/DjlZoo.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ public static List<Artifact> listInstanceSegmentationModels() throws ModelNotFou
* @throws IOException
*/
public static Criteria<?, ?> buildCriteria(Artifact artifact, boolean allowDownload) throws ModelNotFoundException, MalformedModelException, IOException {
var before = System.getProperty("offline");
var before = System.getProperty("ai.djl.offline");
try {
if (allowDownload)
System.setProperty("offline", "false");
System.setProperty("ai.djl.offline", "false");


var application = artifact.getMetadata().getApplication();
Expand Down Expand Up @@ -300,7 +300,7 @@ public static List<Artifact> listInstanceSegmentationModels() throws ModelNotFou
}
return builder.build();
} finally {
System.setProperty("offline", before);
System.setProperty("ai.djl.offline", before);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/qupath/ext/djl/ui/DjlEngineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ private static void updateVersionFromStatus(EngineStatus status, String engineNa
try {
var engine = Engine.getEngine(engineName);
labelVersion.setText(engine.getVersion());
labelVersion.setTooltip(new Tooltip(engine.toString()));
// this is toString, but TF ends up trying to download again.
labelVersion.setTooltip(new Tooltip(engine.getEngineName() + ':' + engine.getVersion()));
return;
} catch (Exception e) {
logger.error("Error updating engine version: {}", e.getMessage(), e);
Expand Down

0 comments on commit b82abb3

Please sign in to comment.