Ejemplo n.º 1
0
    def set_system_experiment(self, experiment_name, eval_infer=False, copy_from=False, pseudo_copy_from=False, resume_train=False, summary=False):
        if(summary):
            self.set_system_select_experiment(experiment_name);
            print_summary(self.system_dict["fname_relative"]);

        else:
            self.system_dict["experiment_dir"] = self.system_dict["project_dir"] + experiment_name + "/";
            self.system_dict["experiment_dir_relative"] = self.system_dict["project_dir_relative"] + experiment_name + "/";
            if(not os.path.isdir(self.system_dict["experiment_dir"])):
                self.system_dict["local"]["experiments_list"].append(experiment_name);
                self.system_dict["local"]["num_experiments"] += 1;
            create_dir(self.system_dict["experiment_dir"]);
            self.set_system_select_experiment(experiment_name);
            
            if(eval_infer):
                self.set_system_state_eval_infer();
            elif(resume_train):
                self.set_system_state_resume_train();
            elif(copy_from):
                self.set_system_delete_create_dir();
                self.set_system_state_copy_from(copy_from);
            elif(pseudo_copy_from):
                self.set_system_delete_create_dir();
                self.set_system_state_pseudo_copy_from(pseudo_copy_from);
            else: 
                self.set_system_delete_create_dir();
                save(self.system_dict);
Ejemplo n.º 2
0
    def Visualize_Kernels(self, store_images_if_notebook=False):
        '''
        Visualize kernel weights of model

        Args:
            store_images_if_notebook (bool): If the images need to be stored instead of IPython widget 
                                             while using notebook. Not applicable for other environments.
        Returns:
            IPython widget displaying kernel weights if used inside a notebook.
            Else stores the maps in the visualization directory. 
        '''
        is_notebook = isnotebook()

        visualizer = CNNVisualizer(self.system_dict["local"]["model"],
                                   is_notebook)

        if (not is_notebook) or (store_images_if_notebook):
            self.custom_print(
                "The images will be stored in the visualization directory of the experiment"
            )

            from system.common import create_dir
            create_dir(self.system_dict["visualization"]["base"])
            create_dir(self.system_dict["visualization"]["kernels_dir"])

            visualizer.visualize_kernels(
                self.system_dict["visualization"]["kernels_dir"])

        else:
            visualizer.visualize_kernels()
Ejemplo n.º 3
0
 def set_system_project(self, project_name):
     self.system_dict["project_dir"] = self.system_dict["master_systems_dir"] + project_name + "/";
     self.system_dict["project_dir_relative"] = self.system_dict["master_systems_dir_relative"] + project_name + "/";
     if(not os.path.isdir(self.system_dict["project_dir"])):
         self.system_dict["local"]["projects_list"].append(project_name);
         self.system_dict["local"]["num_projects"] += 1;
     create_dir(self.system_dict["project_dir"]);
     self.set_system_select_project(project_name);
Ejemplo n.º 4
0
    def set_system_experiment(self,
                              experiment_name,
                              eval_infer=False,
                              copy_from=False,
                              pseudo_copy_from=False,
                              resume_train=False,
                              summary=False):
        '''
        Create Experiment or load it in different states

        Args:
            experiment_name (str): Unique name to experiment
            eval_infer (bool): If set as True, model is loaded in evaluation mode
            resume_train (bool): If set as True, model is loaded from last checkpoint
            copy_from (list): [project, experiment] to copy from
            pseudo_copy_from (list): For creating sub-experiments while in hyper-parametric analysis state
            summary (list): Dummy variable

        Returns:
            None
        '''
        if (summary):
            self.set_system_select_experiment(experiment_name)
            print_summary(self.system_dict["fname_relative"])

        else:
            self.system_dict["experiment_dir"] = self.system_dict[
                "project_dir"] + experiment_name + "/"
            self.system_dict["experiment_dir_relative"] = self.system_dict[
                "project_dir_relative"] + experiment_name + "/"
            if (not os.path.isdir(self.system_dict["experiment_dir"])):
                self.system_dict["local"]["experiments_list"].append(
                    experiment_name)
                self.system_dict["local"]["num_experiments"] += 1
            create_dir(self.system_dict["experiment_dir"])
            self.set_system_select_experiment(experiment_name)

            if (eval_infer):
                self.set_system_state_eval_infer()
            elif (resume_train):
                self.set_system_state_resume_train()
            elif (copy_from):
                self.set_system_delete_create_dir()
                self.set_system_state_copy_from(copy_from)
            elif (pseudo_copy_from):
                self.set_system_delete_create_dir()
                self.set_system_state_pseudo_copy_from(pseudo_copy_from)
            else:
                self.set_system_delete_create_dir()
                save(self.system_dict)
Ejemplo n.º 5
0
    def set_system_comparison(self, comparison_name):
        '''
        Create comparison experiment

        Args:
            comparison_name (str): Unique name to comparison experiment

        Returns:
            None
        '''
        create_dir(self.system_dict["master_comparison_dir"] +
                   comparison_name + "/")
        self.system_dict["comparison_name"] = comparison_name
        self.system_dict["comparison_dir"] = self.system_dict[
            "master_comparison_dir"] + comparison_name + "/"
Ejemplo n.º 6
0
    def set_system_project(self, project_name):
        '''
        Create Project

        Args:
            project_name (str): Unique name to project

        Returns:
            None
        '''
        self.system_dict["project_dir"] = self.system_dict[
            "master_systems_dir"] + project_name + "/"
        self.system_dict["project_dir_relative"] = self.system_dict[
            "master_systems_dir_relative"] + project_name + "/"
        if (not os.path.isdir(self.system_dict["project_dir"])):
            self.system_dict["local"]["projects_list"].append(project_name)
            self.system_dict["local"]["num_projects"] += 1
        create_dir(self.system_dict["project_dir"])
        self.set_system_select_project(project_name)
Ejemplo n.º 7
0
    def __init__(self, verbose=1):
        self.system_dict = get_base_system_dict();
        self.system_dict["verbose"] = verbose;
        self.system_dict["cwd"] = os.getcwd() + "/";
        self.system_dict["master_systems_dir"] = self.system_dict["cwd"] + "workspace/";
        self.system_dict["master_systems_dir_relative"] = "workspace/";

        create_dir(self.system_dict["master_systems_dir_relative"]);

        self.system_dict["master_comparison_dir"] = self.system_dict["cwd"] + "workspace/comparison/";
        self.system_dict["master_comparison_dir_relative"] = "workspace/comparison/";
        
        create_dir(self.system_dict["master_comparison_dir_relative"]);
            
        self.system_dict["local"]["projects_list"] = os.listdir(self.system_dict["master_comparison_dir"]);
        self.system_dict["local"]["num_projects"] = len(self.system_dict["local"]["projects_list"]);
        self.system_dict["local"]["experiments_list"] = [];
        self.system_dict["local"]["num_experiments"] = 0;
        self.system_dict["origin"] = ["New", "New"];
Ejemplo n.º 8
0
    def set_system_delete_create_dir(self):
        '''
        Function to remove old directories and create new at the same place

        Args:
            None

        Returns:
            None
        '''
        delete_dir(self.system_dict["output_dir_relative"])
        create_dir(self.system_dict["output_dir_relative"])
        create_dir(self.system_dict["model_dir_relative"])
        create_dir(self.system_dict["log_dir_relative"])
Ejemplo n.º 9
0
    def Visualize_Feature_Maps(self,
                               image_path,
                               store_images_if_notebook=False):
        '''
        Visualize feature maps generated by model on an image

        Args:
            image_path (str): Path to the image
            store_images_if_notebook (bool): If the images need to be stored instead of IPython widget 
                                             while using notebook. Not applicable for other environments.
        
        Returns:
            IPython widget displaying feature maps if used inside a notebook.
            Else stores the maps in the visualization directory.  
        '''
        is_notebook = isnotebook()

        visualizer = CNNVisualizer(self.system_dict["local"]["model"],
                                   is_notebook)

        if (self.system_dict["model"]["params"]["use_gpu"]):
            device = torch.device(
                'cuda' if torch.cuda.is_available() else 'cpu')
        else:
            device = torch.device('cpu')

        if (not is_notebook) or (store_images_if_notebook):
            self.custom_print(
                "The images will be stored in the visualization directory of the experiment"
            )

            from system.common import create_dir
            create_dir(self.system_dict["visualization"]["base"])
            create_dir(self.system_dict["visualization"]["feature_maps_dir"])
            img_name = "".join(image_path.split("/")[-1].split(".")[0:-1])
            img_dir = self.system_dict["visualization"][
                "feature_maps_dir"] + img_name + '/'
            create_dir(img_dir)

            visualizer.visualize_feature_maps(image_path,
                                              device=device,
                                              store_path=img_dir)

        else:
            visualizer.visualize_feature_maps(image_path, device=device)
Ejemplo n.º 10
0
 def set_system_comparison(self, comparison_name):
     create_dir(self.system_dict["master_comparison_dir"] + comparison_name + "/");
     self.system_dict["comparison_name"] = comparison_name;
     self.system_dict["comparison_dir"] = self.system_dict["master_comparison_dir"] + comparison_name + "/";
Ejemplo n.º 11
0
 def set_system_delete_create_dir(self):
     delete_dir(self.system_dict["output_dir_relative"]);
     create_dir(self.system_dict["output_dir_relative"]);
     create_dir(self.system_dict["model_dir_relative"]);
     create_dir(self.system_dict["log_dir_relative"]);