Skip to content

Commit

Permalink
fix errors on efficientSAM installation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Sep 6, 2024
1 parent e84696c commit 9374f43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/main/java/ai/nets/samj/gui/SAMJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public void actionPerformed(ActionEvent e) {
netAdapter.setReturnOnlyBiggest(cmbROIs.getSelectedItem().equals(ONLY_BIGGEST));
} catch (Exception ex) {
display.notifyException(SAMJException.ENCODING, ex);
netAdapter = null;
}
SwingUtilities.invokeLater(() -> {
this.bnStart.setPressed(false);
Expand Down
40 changes: 13 additions & 27 deletions src/main/java/ai/nets/samj/install/EfficientSamEnvManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public class EfficientSamEnvManager extends SamEnvManagerAbstract {
"scikit-image", "pytorch=2.0.1", "torchvision=0.15.2", "cpuonly"});
else
INSTALL_CONDA_DEPS = Arrays.asList(new String[] {"libpng", "libjpeg-turbo",
"scikit-image", "pytorch=2.0.1", "torchvision=0.15.2", "cpuonly"});
"scikit-image", "pytorch=2.4.1", "torchvision=0.19.0", "cpuonly"});
}
/**
* Dependencies for every environment that need to be installed using PIP
*/
final public static List<String> INSTALL_PIP_DEPS;
static {
if (!PlatformDetection.getArch().equals(PlatformDetection.ARCH_ARM64) && !PlatformDetection.isUsingRosseta())
INSTALL_PIP_DEPS = Arrays.asList(new String[] {"mkl=2023.2.2", "appose"});
INSTALL_PIP_DEPS = Arrays.asList(new String[] {"mkl==2024.0.0", "appose"});
else
INSTALL_PIP_DEPS = Arrays.asList(new String[] {"appose"});
}
Expand Down Expand Up @@ -295,23 +295,20 @@ public void installSAMDeps(boolean force) throws IOException, InterruptedExcepti
}
ArrayList<String> pipInstall = new ArrayList<String>();
for (String ss : new String[] {"-m", "pip", "install"}) pipInstall.add(ss);
for (String ss : INSTALL_PIP_DEPS) pipInstall.add(ss);
try {
Mamba.runPythonIn(Paths.get(path, "envs", ESAM_ENV_NAME).toFile(), pipInstall.stream().toArray( String[]::new ));
} catch (IOException | InterruptedException e) {
thread.interrupt();
passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- FAILED PYTHON ENVIRONMENT CREATION WHEN INSTALLING PIP DEPENDENCIES");
throw e;
}
}
thread.interrupt();
passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- PYTHON ENVIRONMENT CREATED");
// TODO remove
installApposePackage(ESAM_ENV_NAME);
installEfficientSAMPackage(force);
}

/**
* Install the Python package to run EfficientSAM.
* Does not overwrite the package if it already exists.
* @throws IOException if there is any file creation related issue
* @throws InterruptedException if the package installation is interrupted
* @throws MambaInstallException if there is any error with the Mamba installation
*/
public void installEfficientSAMPackage() throws IOException, InterruptedException, MambaInstallException {
installEfficientSAMPackage(false);
installEfficientSAMPackage();
}

/**
Expand All @@ -322,23 +319,12 @@ public void installEfficientSAMPackage() throws IOException, InterruptedExceptio
* @throws InterruptedException if the package installation is interrupted
* @throws MambaInstallException if there is any error with the Mamba installation
*/
public void installEfficientSAMPackage(boolean force) throws IOException, InterruptedException, MambaInstallException {
if (checkEfficientSAMPackageInstalled() && !force)
private void installEfficientSAMPackage() throws IOException, InterruptedException, MambaInstallException {
if (checkEfficientSAMPackageInstalled())
return;
if (!checkMambaInstalled())
throw new IllegalArgumentException("Unable to EfficientSAM without first installing Mamba. ");
Thread thread = reportProgress(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- INSTALLING 'EFFICIENTSAM' PYTHON PACKAGE");
try {
mamba.create(ESAM_ENV_NAME, true);
} catch (MambaInstallException e) {
thread.interrupt();
passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- FAILED 'EFFICIENTSAM' PYTHON PACKAGE INSTALLATION");
throw new MambaInstallException("Unable to install EfficientSAM without first installing Mamba.");
} catch (IOException | InterruptedException | RuntimeException e) {
thread.interrupt();
passToConsumer(LocalDateTime.now().format(DATE_FORMAT).toString() + " -- FAILED 'EFFICIENTSAM' PYTHON PACKAGE INSTALLATION");
throw e;
}
String zipResourcePath = "EfficientSAM.zip";
String outputDirectory = mamba.getEnvsDir() + File.separator + ESAM_ENV_NAME;
try (
Expand Down

0 comments on commit 9374f43

Please sign in to comment.