예제 #1
0
파일: test_model2.py 프로젝트: shgold/sh
    def set_configuration(self):
        # Check training variables
        with tf.name_scope("train_var"):
            all_vars = tf.trainable_variables()

            enc_var = [v for v in all_vars if 'Encoder' in v.op.name or 'encoder' in v.op.name]
            print(cyan('================== ENCODER ==================='))
            slim.model_analyzer.analyze_vars(enc_var, print_info=True)

            d_var = [v for v in all_vars if 'Depth' in v.op.name or 'depth' in v.op.name]
            print(cyan('================ DEPTH branch ================'))
            slim.model_analyzer.analyze_vars(d_var, print_info=True)

            p_var = [v for v in all_vars if 'Pixel' in v.op.name or 'pixel' in v.op.name]
            print(cyan('================ PIXEL branch ================'))
            slim.model_analyzer.analyze_vars(p_var, print_info=True)

            m_var = [v for v in all_vars if 'Mask' in v.op.name or 'mask' in v.op.name]
            print(cyan('================ MASK branch ================='))
            slim.model_analyzer.analyze_vars(m_var, print_info=True)

            self.train_summary_op = tf.summary.merge_all(key='train')

            # Set up the saver
            self.saver = tf.train.Saver(max_to_keep=100)
            self.pretrain_saver = tf.train.Saver(var_list=all_vars, max_to_keep=1)
            self.pretrain_saver_enc = tf.train.Saver(var_list=enc_var, max_to_keep=1)
            self.pretrain_saver_d = tf.train.Saver(var_list=d_var, max_to_keep=1)
            self.pretrain_saver_p = tf.train.Saver(var_list=p_var, max_to_keep=1)
            self.pretrain_saver_m = tf.train.Saver(var_list=m_var, max_to_keep=1)

        # Set up training session
        with tf.name_scope('train_session_config'):
            self.summary_writer = tf.summary.FileWriter(self.checkpoint_dir)

            self.supervisor = tf.train.Supervisor(logdir=self.checkpoint_dir, is_chief=True, saver=None, summary_op=None,
                                                  summary_writer=self.summary_writer, save_summaries_secs=300,
                                                  save_model_secs=600, global_step=self.global_step)

            session_config = tf.ConfigProto(allow_soft_placement=True, gpu_options=tf.GPUOptions(allow_growth=True),
                                            device_count={'GPU':1})
            self.session = self.supervisor.prepare_or_wait_for_session(config=session_config)

        # Reload the checkpoint if exist
        with tf.name_scope('train_checkpoint'):
            if self.continue_train:
                if self.checkpoint_dir is not None:
                    # checkpoint = tf.train.latest_checkpoint(checkpoint_dir)
                    print(yellow('Restoring latest checkpoint path: {}'.format(self.checkpoint_dir)))
                    self.pretrain_saver.restore(self.session, self.checkpoint_dir)
def put_images_pairs_in_folder(pair_list, dest_folder, set_count):
    list_num_total = len(pair_list)

    for i, pair in enumerate(pair_list):
        temp_folder = os.path.join(dest_folder,
                                   'set_ori{}'.format(i + set_count))
        if not os.path.exists(temp_folder):
            os.makedirs(temp_folder)
        print('Moving {}th pair out of {} pairs'.format(i, list_num_total))

        try:
            move(pair[0][0], temp_folder)  # D5 jpg
            move(pair[0][1], temp_folder)  # D5 cv2
            move(pair[1][0], temp_folder)  # p20 jpg
            move(pair[1][1], temp_folder)  # p20 dng
            move_folders(pair[2], temp_folder)  # zed folders
        except:
            print(yellow('File does not exists '))
            pass

    print(magenta('Finishing moving images in pairs'))
        print(
            red('[Error] Select at least one device to run: --p20 / --zed / --d5'
                ))
        exit(-1)

    print(cyan('============== Selected Devices ================'))
    print(cyan('{}'.format(processes)))
    print(cyan('==================== Guide ====================='))
    print(cyan('Mouse LEFT click to record videos.'))
    print(cyan('Mouse RIGHT click to exit the program.'))

    make_dir_if_not_exists(__ZED_IMG_PATH__)
    make_dir_if_not_exists(__P20_IMG_PATH__)
    make_dir_if_not_exists(__D5_IMG_PATH__)

    # Create logger
    img_logger = logutils.create_logger(__VID_LOGGING_FILE__)

    # Kill the process which blocks the camera connection
    canon.killGphoto2Process()

    print(
        yellow('Make sure that all the devices are on and at the right mode!'))

    # Collect events until released
    with Listener(on_click=on_click_run) as listener:
        listener.join()

    # Alarm that this program is closed.
    beep(3)
    print('Done!')
예제 #4
0
import os
import cv2
from utils.print_utils import yellow, red

__BASE_DIR__ = '/media/dc2019/My Book/VID/VQM_data'
__TEST_DIR__ = os.path.join(__BASE_DIR__, 'zed/test')
__VALID_DIR__ = os.path.join(__BASE_DIR__, 'zed/validation')

sets = os.listdir(__TEST_DIR__)

for set in sets:
    set_dir = os.path.join(__TEST_DIR__, set)
    print(yellow(set_dir))
    frames = os.listdir(set_dir)
    for frame in frames:
        print(os.path.join(set_dir, frame))
        try:
            img = cv2.imread(os.path.join(set_dir, frame))
        except:
            print(red(os.path.join(set_dir, frame)))

print('Done!')
 def print_helpping_messages(self):
     print(yellow('n: go to next folder \ p: go to previous folder'))
     print(yellow('s: move items into a saving folder'))
     print(yellow('h: move items into a hold folder'))
     print(yellow('d: move items into a deleting folder'))