generated from qupath/qupath-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from alanocallaghan/java-17
Support for QuPath 0.5 and local models
- Loading branch information
Showing
15 changed files
with
334 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/qupath/ext/wsinfer/models/WSInferModelLocal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2023 University of Edinburgh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package qupath.ext.wsinfer.models; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.ResourceBundle; | ||
|
||
public class WSInferModelLocal extends WSInferModel { | ||
|
||
private final File modelDirectory; | ||
private static final ResourceBundle resources = ResourceBundle.getBundle("qupath.ext.wsinfer.ui.strings"); | ||
|
||
/** | ||
* Try to create a WSInfer model from a user directory. | ||
* @param modelDirectory A user directory containing a | ||
* torchscript.pt file and a config.json file | ||
* @return A {@link WSInferModel} if the directory supplied is valid, | ||
* otherwise nothing. | ||
*/ | ||
public static WSInferModelLocal createInstance(File modelDirectory) throws IOException { | ||
return new WSInferModelLocal(modelDirectory); | ||
} | ||
|
||
private WSInferModelLocal(File modelDirectory) throws IOException { | ||
this.modelDirectory = modelDirectory; | ||
this.hfRepoId = modelDirectory.getName(); | ||
List<File> files = Arrays.asList(Objects.requireNonNull(modelDirectory.listFiles())); | ||
if (!files.contains(getCFFile())) { | ||
throw new IOException(resources.getString("error.localModel") + ": " + getCFFile().toString()); | ||
} | ||
if (!files.contains(getTSFile())) { | ||
throw new IOException(resources.getString("error.localModel") + ": " + getTSFile().toString()); | ||
} | ||
} | ||
|
||
@Override | ||
File getModelDirectory() { | ||
return this.modelDirectory; | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
return getTSFile().exists() && getConfiguration() != null; | ||
} | ||
|
||
@Override | ||
public synchronized void downloadModel() {} | ||
|
||
@Override | ||
public synchronized void removeCache() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.