Skip to content
Snippets Groups Projects
Select Git revision
  • 7554de269e5d5a3e42a2cfccf7948fc6d09baa80
  • master default protected
  • v1.0.0
3 results

DeepLearningVersionSelector.java

Blame
  • DeepLearningVersionSelector.java 9.41 KiB
    package plugins.danyfel80.deeplearningdownloader;
    
    import java.awt.event.WindowListener;
    import java.util.List;
    import java.util.Map;
    import java.util.function.Function;
    import java.util.stream.Collectors;
    
    
    import icy.gui.dialog.MessageDialog;
    import icy.main.Icy;
    import icy.plugin.PluginLauncher;
    import icy.plugin.PluginLoader;
    import icy.preferences.XMLPreferences;
    import icy.util.StringUtil;
    import io.bioimage.modelrunner.system.PlatformDetection;
    import io.bioimage.modelrunner.utils.Constants;
    import io.bioimage.modelrunner.versionmanagement.AvailableDeepLearningVersions;
    import io.bioimage.modelrunner.versionmanagement.DeepLearningVersion;
    import plugins.adufour.blocks.lang.Block;
    import plugins.adufour.blocks.util.VarList;
    import plugins.adufour.ezplug.EzPlug;
    import plugins.adufour.ezplug.EzStoppable;
    import plugins.adufour.ezplug.EzVarText;
    import plugins.adufour.vars.lang.VarBoolean;
    import plugins.adufour.vars.lang.VarString;
    
    /**
     * This plugin allows users to select the TensorFlow version to load in memory.
     * Just select one of the available versions and click the "play" button to load the library.
     * Please keep in mind that only one version of TensorFlow can be loaded per Icy
     * execution. An Exception will be thrown if a TensorFlow version tries to loaded after another version has already been loaded.
     * 
     * @author Daniel Felipe Gonzalez Obando and Carlos Garcia Lopez de Haro
     */
    public class DeepLearningVersionSelector extends EzPlug implements EzStoppable, Block
    {
        private EzVarText varInVersion;
        private final static Map<String, DeepLearningVersion> versions;
        static
        {
            versions = getDisplayMapWithoutPythonRepeated();
        }
        
        /**
         * Create map to display the available Deep Learning versions for naive users.
         * only the DL framework, python version and whether is GPU or CPU
         * @return map to let naive users select the wanted DL version
         */
        private static Map<String, DeepLearningVersion> getDisplayMapWithoutPythonRepeated() {
        	List<DeepLearningVersion> allVersions = AvailableDeepLearningVersions.loadCompatibleOnly().getVersions();
        	List<DeepLearningVersion> vList = AvailableDeepLearningVersions.removeRepeatedPythonVersions(allVersions);
    	    Map<String, DeepLearningVersion> map = vList.stream()
    		        .collect(Collectors.toMap(
    		                v -> v.getEngine() + "-" + v.getPythonVersion()
    		                + (v.getCPU() ? "-" + DeepLearningVersion.cpuKey : "")
    		                + (v.getGPU() ? "-" + DeepLearningVersion.gpuKey : ""),
    		                Function.identity()));
    	    return map;
        }
    
        /**
         * Main routine launching this plugin.
         * 
         * @param args
         */
        public static void main(String[] args)
        {
            Icy.main(args);
            PluginLauncher.start(PluginLoader.getPlugin(DeepLearningVersionSelector.class.getName()));