Ejemplo n.º 1
0
    def summarize_dirs(self):
        """
        Get the best and worst epochs of all given folders as a dict.

        Returns
        -------
        minima : dict
            Keys : Name of folder.
            Values : [Epoch, metric] of where the metric is lowest.
        maxima : dict
            As above, but for where the metric is highest.

        """
        minima, maxima = {}, {}
        for folder_no, folder in enumerate(self.folders):
            hist = HistoryHandler(folder)
            smry_met_name = self._full_metrics[folder_no]
            try:
                max_line = hist.get_best_epoch_info(metric=smry_met_name,
                                                    mini=False)
                min_line = hist.get_best_epoch_info(metric=smry_met_name,
                                                    mini=True)
            except OSError as e:
                warnings.warn(str(e))
                continue

            minima[folder] = [min_line["Epoch"], min_line[smry_met_name]]
            maxima[folder] = [max_line["Epoch"], max_line[smry_met_name]]
        return minima, maxima
Ejemplo n.º 2
0
    def __init__(self,
                 output_folder,
                 list_file=None,
                 config_file=None,
                 tf_log_level=None,
                 discover_tomls=True):
        """
        Set the attributes of the Configuration object.

        Instead of using a config_file, the attributes of orga.cfg can
        also be changed directly, e.g. by calling orga.cfg.batchsize.

        Parameters
        ----------
        output_folder : str
            Name of the folder of this model in which everything will be saved,
            e.g., the summary.txt log file is located in here.
            Will be used to load saved files or to save new ones.
        list_file : str, optional
            Path to a toml list file with pathes to all the h5 files that should
            be used for training and validation.
            Will be used to extract samples and labels.
            Default: Look for a file called 'list.toml' in the given output_folder.
        config_file : str, optional
            Path to a toml config file with settings that are used instead of
            the default ones.
            Default: Look for a file called 'config.toml' in the given output_folder.
        tf_log_level : int/str
            Sets the TensorFlow CPP_MIN_LOG_LEVEL environment variable.
            0 = all messages are logged (default behavior).
            1 = INFO messages are not printed.
            2 = INFO and WARNING messages are not printed.
            3 = INFO, WARNING, and ERROR messages are not printed.
        discover_tomls : bool
            If False, do not try to look for toml files in the given
            output_folder if list_file or config_file is None [Default: True].

        """
        if tf_log_level is not None:
            os.environ['TF_CPP_MIN_LOG_LEVEL'] = str(tf_log_level)

        if discover_tomls and list_file is None:
            list_file = orcanet.misc.find_file(output_folder, "list.toml")
        if discover_tomls and config_file is None:
            config_file = orcanet.misc.find_file(output_folder, "config.toml")

        self.cfg = Configuration(output_folder, list_file, config_file)
        self.io = IOHandler(self.cfg)
        self.history = HistoryHandler(output_folder)

        self.xs_mean = None
        self._auto_label_modifier = None
        self._stored_model = None
        self._strategy = None
Ejemplo n.º 3
0
    def _summarize_folder(self, folder_no):
        label = self.labels[folder_no]
        folder = self.folders[folder_no]

        hist = HistoryHandler(folder)
        val_data, min_stat, max_stat = None, None, None
        # read data from summary file
        try:
            smry_met_name = self._full_metrics[folder_no]
            max_line = hist.get_best_epoch_info(metric=smry_met_name,
                                                mini=False)
            min_line = hist.get_best_epoch_info(metric=smry_met_name,
                                                mini=True)
            min_stat = [min_line[smry_met_name], label, min_line["Epoch"]]
            max_stat = [max_line[smry_met_name], label, max_line["Epoch"]]

            summary_data = hist.get_summary_data()
            val_data = [
                summary_data["Epoch"],
                summary_data[self._full_metrics[folder_no]]
            ]
        except OSError:
            if self.verbose:
                print(f"Warning: No summary file found for {folder}")

        except ValueError as e:
            if self.verbose:
                print(f"Error reading summary file {hist.summary_file} ({e})")

        # read data from training files
        full_train_data = hist.get_train_data()
        train_data = [
            full_train_data["Batch_float"],
            full_train_data[self._metric_names[folder_no]]
        ]

        if not self.noplot:
            if len(self.labels) == 1:
                train_label, val_label = "training", "validation"
            elif val_data is None:
                train_label, val_label = label, None
            else:
                train_label, val_label = None, label

            self._tvp.plot_curves(train_data=train_data,
                                  val_data=val_data,
                                  train_label=train_label,
                                  val_label=val_label,
                                  smooth_sigma=self.smooth,
                                  tlw=0.5 * self.width,
                                  vlw=0.5 * self.width,
                                  vms=3 * self.width**0.5)
        return min_stat, max_stat
Ejemplo n.º 4
0
    def setUp(self):
        self.output_folder = os.path.join(os.path.dirname(__file__), "data",
                                          "dummy_model")
        self.history = HistoryHandler(self.output_folder)

        self.summary_filename_2 = "summary_2.txt"