Skip to content

Commit

Permalink
Fix download and use model-version path
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Dec 5, 2024
1 parent 81c7624 commit 8d0b418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/qupath/ext/instanseg/core/InstanSegModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean isDownloaded(Path localModelPath) {
// that doesn't match with the filename (although we'd prefer this didn't happen...)
if (path != null && model != null && isValidModel(path))
return true;
if (!Files.exists(localModelPath.resolve(name).resolve(version))) {
if (!Files.exists(localModelPath.resolve(getFolderName(name, version)))) {
// The model may have been deleted or renamed - we won't be able to load it
return false;
}
Expand All @@ -108,7 +108,7 @@ public void download(Path localModelPath) throws IOException {
var zipFile = downloadZipIfNeeded(
this.modelURL,
localModelPath,
name + "-" + version);
getFolderName(name, version));
this.path = unzipIfNeeded(zipFile);
this.model = BioimageIoSpec.parseModel(path.toFile());
this.version = model.getVersion();
Expand Down Expand Up @@ -297,7 +297,7 @@ private static boolean isDownloadedAlready(Path zipFile) {
private Path unzipIfNeeded(Path zipFile) throws IOException {
var zipSpec = BioimageIoSpec.parseModel(zipFile);
String version = zipSpec.getVersion();
var outdir = zipFile.resolveSibling(zipSpec.getName()).resolve(version);
var outdir = zipFile.resolveSibling(getFolderName(zipSpec.getName(), version));
if (!isUnpackedAlready(outdir)) {
try {
unzip(zipFile, outdir);
Expand All @@ -313,6 +313,10 @@ private Path unzipIfNeeded(Path zipFile) throws IOException {
return outdir;
}

private String getFolderName(String name, String version) {
return name + "-" + version;
}

private static boolean isUnpackedAlready(Path outdir) {
return Files.exists(outdir) && isValidModel(outdir);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "brightfield_nuclei",
"url": "https://github.com/instanseg/alanocallaghan/releases/download/v0.1.0/brightfield_nuclei.zip",
"url": "https://github.com/alanocallaghan/instanseg/releases/download/v0.1.0/brightfield_nuclei.zip",
"version": "0.1.0",
"license": "Apache-2.0"
},
Expand Down

0 comments on commit 8d0b418

Please sign in to comment.