def get_classes(rootdir):
    classes = []
    filedirs = fcfiles.get_filedirs(rootdir)
    for filedir in filedirs:
        fdict = fcfiles.load_pickle(filedir)
        c = fdict['c']
        if not c in classes:
            classes.append(c)
    return classes
Ejemplo n.º 2
0
 def _delete_filedirs(self):
     if self.delete_all_previous_epochs_files:
         to_delete_filedirs = [
             f for f in files.get_filedirs(self.complete_save_roodir)
             if files.get_dict_from_filedir(f)['id'] == self.id
         ]
         if len(to_delete_filedirs) > 0:
             epochs_to_delete = [
                 int(files.get_dict_from_filedir(f)['epoch'])
                 for f in to_delete_filedirs
             ]
             prints.print_red(
                 f'> (id={self.id}) deleting previous epochs={epochs_to_delete} in={self.complete_save_roodir}'
             )
             files.delete_filedirs(to_delete_filedirs, verbose=0)
Ejemplo n.º 3
0
    def load_model(
        self,
        target_id: str = None,
        target_epoch: int = None,
    ):
        if target_id is None:
            target_id = self.id
        if not target_id == self.id:
            self.id = target_id

        filedirs = files.get_filedirs(self.complete_save_roodir,
                                      fext=C_.SAVE_FEXT)
        if len(filedirs) == 0:
            prints.print_red(
                f'*** no files in {self.complete_save_roodir} ***')
            raise Exception(f'*** no files in {self.complete_save_roodir} ***')
            return False

        if target_epoch is None:  # seach the last epoch with that id
            filedics = [
                files.get_dict_from_filedir(filedir) for filedir in filedirs
            ]
            epochs = [
                int(filedic['epoch']) for filedic in filedics
                if filedic['id'] == target_id
            ]
            if len(epochs) == 0:
                prints.print_red(
                    f'*** no files with id {target_id} in {self.complete_save_roodir} ***'
                )
                raise Exception(
                    f'*** no files with id {target_id} in {self.complete_save_roodir} ***'
                )
                return False

            epochs = sorted(epochs)
            target_epoch = epochs[-1]

        to_load_filedir = f'{self.complete_save_roodir}/id{C_.KEY_VALUE_SEP_CHAR}{target_id}{C_.KEY_KEY_SEP_CHAR}epoch{C_.KEY_VALUE_SEP_CHAR}{target_epoch}.{C_.SAVE_FEXT}'
        prints.print_blue(f'> loading model={to_load_filedir}')

        loaded_dic = torch.load(to_load_filedir, map_location=self.device)
        self.model.load_state_dict(loaded_dic['state_dict'])
        for lmonitor in self.lmonitors:
            #lmonitor.history_dict = loaded_dic['lmonitors'][lmonitor.name]
            pass

        return self.model
def get_band_names(rootdir):
    filedirs = fcfiles.get_filedirs(rootdir)
    filedir = filedirs[0]
    return fcfiles.load_pickle(filedir)['band_names']
def empty_roodir(rootdir):
    return len(fcfiles.get_filedirs(rootdir)) == 0
Ejemplo n.º 6
0
kfs = lcdataset.kfolds if main_args.kf == '.' else main_args.kf
kfs = [kfs] if isinstance(kfs, str) else kfs
setns = [str(setn) for setn in ['train', 'val']
         ] if main_args.setn == '.' else main_args.setn
setns = [setns] if isinstance(setns, str) else setns

new_lcdataset = lcdataset.copy()  # copy with all original lcsets
for setn in setns:
    for kf in kfs:
        lcset_name = f'{kf}@{setn}'
        lcset = new_lcdataset[lcset_name]
        synth_rootdir = f'../save/ssne/{main_args.method}/{cfilename}/{lcset_name}'
        print('synth_rootdir=', synth_rootdir)
        synth_lcset = lcset.copy({})  # copy
        filedirs = fcfiles.get_filedirs(synth_rootdir, fext='ssne')
        bar = ProgressBar(len(filedirs))

        for filedir in filedirs:
            d = fcfiles.load_pickle(filedir)
            lcobj_name = d['lcobj_name']
            bar(f'lcset_name={lcset_name} - lcobj_name={lcobj_name}')

            for k, new_lcobj in enumerate(d['new_lcobjs']):
                synth_lcset.set_lcobj(f'{lcobj_name}.{k+1}', new_lcobj)

        bar.done()
        synth_lcset.reset()
        new_lcset_name = f'{lcset_name}.{main_args.method}'
        new_lcdataset.set_lcset(new_lcset_name, synth_lcset)