def save_selected_activations(self): if not self.input: self.log_window(title='Error!', Msg='Please indicate a input image') else: save_act_path = file_dialog( title='choose a folder to save the images', type='/').openFolderDialog() selected_idx = self.actList.selectionModel().selectedIndexes() for idx in selected_idx: layer_name = self.actList.item(idx.row()).text() rlt = np.squeeze(self.activations[layer_name]) if rlt.ndim == 3: for i in range(rlt.shape[-1]): check_N_mkdir(save_act_path + layer_name.replace('/', '_')) Image.fromarray( rlt[:, :, i]).save(save_act_path + layer_name.replace('/', '_') + '/{}.tif'.format(i)) elif rlt.ndim == 2: check_N_mkdir(save_act_path + layer_name.replace('/', '_')) Image.fromarray( rlt[:, :]).save(save_act_path + layer_name.replace('/', '_') + '/act.tif') else: logger.debug( 'got an unexpected ndim of the activations: {}'.format( rlt.ndim))
def ckptFileDialog(self): tmp = file_dialog(title='choose .meta file').openFileNameDialog() if tmp: self.ckptPathLine.setText(tmp) self.set_ckpt()
def set_log_dir(self): log_dir_dial = file_dialog(title='select a folder to save the model', type='/') self.log_dir = log_dir_dial.openFolderDialog() self.log_dir_line.setText(self.log_dir)
def activation_plugin(self): # os.environ["CUDA_VISIBLE_DEVICES"] = "-1" #note: here might have conflict if there's an ongoing training with GPU import tensorflow as tf # get ckpt file dialog = file_dialog( title='select ckpts (*.meta) to retrieve activations', type='.meta') ckpt_paths = dialog.openFileNamesDialog() logger.debug('ckpt_paths: {}'.format(ckpt_paths)) if ckpt_paths is not None and (not not ckpt_paths): # get input path dialog = file_dialog( title='select folder which contains datas for analyses') data_folder = dialog.openFolderDialog() logger.debug('data_folder: {}'.format(data_folder)) if data_folder is not None and (not not data_folder): if len(ckpt_paths) != 0: # restore from ckpt the nodes tf.reset_default_graph() logger.debug(ckpt_paths[0]) _ = tf.train.import_meta_graph( ckpt_paths[0], clear_devices=True, ) # get arguments graph = tf.get_default_graph().as_graph_def() nodes = print_nodes_name(graph) steps = [ re.search('step(\d+)', ck_pth).group(1) for ck_pth in ckpt_paths ] # retrive nodes of activations options = [] for node in nodes: tmp = re.search( '(^[a-zA-Z]+\d*\/).*(leaky|relu|sigmoid|tanh|logits\/identity|up\d+\/Reshape\_4|concat)$', node) if tmp is not None: tmp = tmp.string if 'identity' in tmp: iden = tmp else: options.append(tmp) # open nodes list dialog nodes_list = node_list_logic(options=options) nodes_list.exec() if nodes_list.result() == 1: acts = nodes_list.return_nodes() if iden: acts.append(iden) types = nodes_list.return_analysis_types() if len(types) == 0: types = ['activation'] terminal = [ 'python', os.path.join(parentDir, 'main_analytic.py'), '-ckpt', *ckpt_paths, '-step', *steps, '-type', *types, '-node', *acts, '-dir', data_folder, ] logger.debug(terminal) proc = subprocess.Popen(terminal) proc.wait()
def selectckpt(self): ckpt_dialog = file_dialog(title='select a checkpoint file .meta', type='.meta') ckpt_path = ckpt_dialog.openFileNameDialog() self.ckpt_path = ckpt_path self.ckptLine.setText(self.ckpt_path)
def set_tst_dir(self): tst_dir_dial = file_dialog( title='select a folder where includes the testing dataset', type='/') self.tst_dir = tst_dir_dial.openFolderDialog() self.test_dir_line.setText(self.tst_dir)
def chooseFolder(self): self.dir = file_dialog(title='choose a folder to save the plot/legend/data', type='/').openFolderDialog() if not os.path.isdir(self.dir): logger.error('cannot find training files in this folder')
def selectRaw(self): self.raw_folder = file_dialog( title='choose a folder where contains the raw tomogram .tif' ).openFolderDialog() self.rawLine.setText(self.raw_folder)
def save_diff(self): if self.diff[self.current_page] is not None: save_path = file_dialog(title='select a place to save the difference image', type='/').openFolderDialog() if save_path is not None: Image.fromarray(self.diff[self.current_page]).save(save_path+'/diff.tif')
def saveResult(self): save_path = file_dialog(title='choose a folder to save the plot|legend|data', type='/').openFolderDialog() self.pd_df.to_csv(os.path.join(save_path, 'data.csv'), index=False) self.MPLwidget.canvas1.figure.savefig(os.path.join(save_path, 'plot.png')) Image.fromarray(np.asarray(self.fig2)).save(os.path.join(save_path, 'legend.png'))
def choose_save_path(self): folder_path = file_dialog(title='select folder to save curves .csv', type='/').openFolderDialog() self.save_path_box.setText(folder_path)
def selectTstPath(self): tstPath_dialog = file_dialog( title='select testing data included directory', type='.meta') tstPath = tstPath_dialog.openFolderDialog() self.tstPath = tstPath self.tstPathLine.setText(self.tstPath)
def selectValPath(self): valPath_dialog = file_dialog( title='select validation data included directory', type='.meta') valPath = valPath_dialog.openFolderDialog() self.valPath = valPath self.valPathLine.setText(self.valPath)
def inputFileDialog(self): tmp = file_dialog(title='choose .tif for input', type='.tif').openFileNameDialog() if tmp: self.inputPathLine.setText(tmp) self.set_input()
def set_grad_path(self): grad_dial = file_dialog(title='select a training that you want to view its gradients', type='/') self.path = grad_dial.openFolderDialog() if self.path: self.lineEdit.setText(self.path) self.extract_gradient()
def selectMeta(self): self.meta_path = file_dialog(title='choose .meta file', type='.meta').openFileNameDialog() self.metaLine.setText(self.meta_path)
def set_val_dir(self): val_dir_dial = file_dialog( title='select a folder where includes the validation dataset', type='/') self.val_dir = val_dir_dial.openFolderDialog() self.val_dir_line.setText(self.val_dir)
def selectPred(self): self.pred_folder = file_dialog( title='choose a folder to put the segmentation').openFolderDialog( ) self.predLine.setText(self.pred_folder)
def selectWherePath(self): wherePath_dialog = file_dialog( title='select a directory to save your models', type='.meta') wherePath = wherePath_dialog.openFolderDialog() self.wherePath = wherePath self.whereToSave.setText(self.wherePath)