From 6b418fff22d616ac6f164b3f48e9b47b6e2590e9 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Thu, 16 Jun 2022 14:52:23 +0200 Subject: [PATCH 1/2] adapt to all types of source field in the rdf.yaml --- src/main/java/deepimagej/DeepImageJ.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/deepimagej/DeepImageJ.java b/src/main/java/deepimagej/DeepImageJ.java index 1f8027d9..42230ee7 100755 --- a/src/main/java/deepimagej/DeepImageJ.java +++ b/src/main/java/deepimagej/DeepImageJ.java @@ -446,6 +446,8 @@ public boolean findZippedBiozooModel(File modelFolder) throws IOException { modelName = modelName.substring(modelName.indexOf("/") + 1); } else if (checkURL(modelName)) { modelName = new File(modelName).getName(); + } else { + modelName = new File(modelName).getName(); } String auxModelName = "tensorflow_saved_model_bundle.zip"; boolean auxPresent = false; @@ -454,7 +456,8 @@ public boolean findZippedBiozooModel(File modelFolder) throws IOException { if (file.equals(modelName) && !this.presentYaml) { tfName = modelName; return true; - } else if (file.equals(modelName) && FileTools.createSHA256(modelFolder.getPath() + File.separator + file).equals(params.tfSha256)) { + } else if (file.equals(modelName) ) {//&& FileTools.createSHA256(modelFolder.getPath() + File.separator + file).equals(params.tfSha256)) { + String sha = FileTools.createSHA256(modelFolder.getPath() + File.separator + file); tfName = modelName; return true; } else if (file.equals(modelName)) { @@ -497,6 +500,8 @@ public boolean findPytorchModel(File modelFolder) { modelName = modelName.substring(modelName.indexOf("/") + 1); } else if (checkURL(modelName)) { modelName = new File(modelName).getName(); + } else { + modelName = new File(modelName).getName(); } String auxModelName = "pytorch_script.pt"; String auxModelName2 = "weights-torchscript.pt"; From 278fbf02334b148e9d858391dabd09c2a8522085 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Thu, 16 Jun 2022 17:40:18 +0200 Subject: [PATCH 2/2] correct errors installing and unzipping private models --- src/main/java/deepimagej/InstallerDialog.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/deepimagej/InstallerDialog.java b/src/main/java/deepimagej/InstallerDialog.java index 5c4ca427..58518b2f 100755 --- a/src/main/java/deepimagej/InstallerDialog.java +++ b/src/main/java/deepimagej/InstallerDialog.java @@ -424,10 +424,23 @@ private void installModelBioimageio() { @Override public void run() { install.setEnabled(false); - if (downloadURLs.size() == 1 && new File(downloadURLs.get(0)).isFile()) { + if (tab.getSelectedIndex() == 0 && downloadURLs != null) { + downloadModelFromInternet(); + } else if (tab.getSelectedIndex() == 0 && downloadURLs == null) { + IJ.error("This model does not have links to download."); + } + if (tab.getSelectedIndex() == 1 && rbZIP.isSelected() && new File(txtZIP.getText()).isFile()) { + downloadURLs = new ArrayList(); + downloadURLs.add(txtZIP.getText()); copyFromPath(); - } else { + } else if (tab.getSelectedIndex() == 1 && rbURL.isSelected() && Model.checkURL(txtURL.getText())) { + downloadURLs = new ArrayList(); + downloadURLs.add(txtURL.getText()); downloadModelFromInternet(); + } else if (tab.getSelectedIndex() == 1 && rbURL.isSelected() && !Model.checkURL(txtURL.getText())) { + IJ.error("Introduced String does not correspond to a valid URL"); + } else if (tab.getSelectedIndex() == 1 && rbZIP.isSelected() && !(new File(txtZIP.getText()).isFile())) { + IJ.error("Introduced String does not correspond to a valid local file."); } stopped = true; @@ -454,7 +467,7 @@ public void copyFromPath() { File destFile = new File(modelsDir + File.separator + fileName); progressScreen.setFileName(modelsDir + File.separator + fileName); progressScreen.setmodelName(fileName); - progressScreen.setFileSize(webFileSize); + progressScreen.setFileSize(originalModel.length()); progressScreen.buildScreen(); progressScreen.setVisible(true); FileTools.copyFile(originalModel, destFile); @@ -550,7 +563,12 @@ public void downloadSingleFileModelFromInternet(String url) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("ddMMYYYY_HHmmss"); String dateString = sdf.format(cal.getTime()); - fileName = model.name + "_" + dateString + ".zip"; + String modelName; + if (model == null || model.name == null) + modelName = "model"; + else + modelName = model.name; + fileName = modelName + "_" + dateString + ".zip"; URL website = new URL(url); webFileSize = getFileSize(website); rbc = Channels.newChannel(website.openStream());