Skip to content

Commit

Permalink
remove nickname as it is no loner supported
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Sep 30, 2024
1 parent 994ee30 commit 40cc5c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import io.bioimage.modelrunner.bioimageio.BioimageioRepo;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptor;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptorFactory;
import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException;
import io.bioimage.modelrunner.bioimageio.download.DownloadModel;
import io.bioimage.modelrunner.engine.installation.FileDownloader;
Expand Down Expand Up @@ -551,8 +552,6 @@ private void setUpStardistModelFromBioimageio() throws IOException, InterruptedE
model = br.downloadByName(model, nModelParentPath);
} else if (br.selectByID(model) != null) {
model = br.downloadModelByID(model, nModelParentPath);
} else if (br.selectByNickname(model) != null) {
model = br.downloadByNickame(model, nModelParentPath);
}
File folder = new File(model);
String fineTuned = folder.getParent() + File.separator + "finetuned_" + folder.getName();
Expand Down Expand Up @@ -597,7 +596,7 @@ private void setUpConfigs() throws IOException, ModelSpecsException {
@SuppressWarnings("unchecked")
private void setUpConfigsBioimageio() throws IOException, ModelSpecsException {
String rdfDir = new File(model).getParent();
ModelDescriptor descriptor = ModelDescriptor.readFromLocalFile(rdfDir + File.separator + Constants.RDF_FNAME, false);
ModelDescriptor descriptor = ModelDescriptorFactory.readFromLocalFile(rdfDir + File.separator + Constants.RDF_FNAME);
Object stardistInfo = descriptor.getConfig().getSpecMap().get(StardistInferJdllOp.STARDIST_FIELD_KEY);

if (stardistInfo == null || !(stardistInfo instanceof Map)) {
Expand Down Expand Up @@ -629,7 +628,7 @@ private void setUpConfigsBioimageio() throws IOException, ModelSpecsException {

private void setUpKerasWeights() throws IOException, ModelSpecsException {
String rdfYamlFN = this.model + File.separator + Constants.RDF_FNAME;
ModelDescriptor descriptor = ModelDescriptor.readFromLocalFile(rdfYamlFN, false);
ModelDescriptor descriptor = ModelDescriptorFactory.readFromLocalFile(rdfYamlFN);
String stardistWeights = this.model + File.separator + StardistInferJdllOp.STARDIST_FIELD_KEY;
stardistWeights += File.separator + STARDIST_WEIGHTS_FILE;
String stardistWeightsParent = this.model + File.separator + STARDIST_WEIGHTS_FILE;
Expand Down Expand Up @@ -795,9 +794,9 @@ private void findNChannels() throws Exception {
this.nChannelsModel = 3;
}
String rdfFileName = new File(model).getParentFile() + File.separator + Constants.RDF_FNAME;
ModelDescriptor descriptor = ModelDescriptor.readFromLocalFile(rdfFileName, false);
ModelDescriptor descriptor = ModelDescriptorFactory.readFromLocalFile(rdfFileName);
int cInd = descriptor.getInputTensors().get(0).getAxesOrder().indexOf("c");
nChannelsModel = descriptor.getInputTensors().get(0).getShape().getTileMinimumSize()[cInd];
nChannelsModel = descriptor.getInputTensors().get(0).getMinTileSizeArr()[cInd];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import io.bioimage.modelrunner.bioimageio.BioimageioRepo;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptor;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptorFactory;
import io.bioimage.modelrunner.runmode.RunMode;
import io.bioimage.modelrunner.tensor.Tensor;
import io.bioimage.modelrunner.utils.Constants;
Expand Down Expand Up @@ -243,7 +244,7 @@ public static boolean isModelFileStardist(String modelFile) {
if (new File(modelFile).getName().equals(Constants.RDF_FNAME) == false)
return false;
try {
ModelDescriptor descriptor = ModelDescriptor.readFromLocalFile(modelFile, false);
ModelDescriptor descriptor = ModelDescriptorFactory.readFromLocalFile(modelFile);
return descriptor.getConfig().getSpecMap().keySet().contains(STARDIST_FIELD_KEY);
} catch (Exception e) {
return false;
Expand All @@ -264,8 +265,6 @@ public static boolean isModelNameStardist(String modelName) {
return br.selectByName(modelName).getConfig().getSpecMap().keySet().contains(STARDIST_FIELD_KEY);
} else if (br.selectByID(modelName) != null) {
return br.selectByID(modelName).getConfig().getSpecMap().keySet().contains(STARDIST_FIELD_KEY);
} else if (br.selectByNickname(modelName) != null) {
return br.selectByNickname(modelName).getConfig().getSpecMap().keySet().contains(STARDIST_FIELD_KEY);
}
return false;
}
Expand All @@ -283,19 +282,6 @@ public static List<String> fetchStarDistModelNamesFromBioImage() {
return stardistModels;
}

/**
* Returns a list containing all the model nicknames that corresponds to
* StarDist models existing in the Bioimage.io online repository.
* @return list of StarDist model nicknames from the Bioimage.io repository
*/
public static List<String> fetchStarDistModelNicknamesFromBioImage() {
BioimageioRepo br = BioimageioRepo.connect();
List<String> stardistModels = br.listAllModels(false).values().stream()
.filter(md -> md.getConfig().getSpecMap().keySet().contains(STARDIST_FIELD_KEY))
.map(md -> md.getNickname()).collect(Collectors.toList());
return stardistModels;
}

/**
* Returns a list containing all the model IDs that corresponds to
* StarDist models existing in the Bioimage.io online repository.
Expand Down

0 comments on commit 40cc5c3

Please sign in to comment.