Пример #1
0
def compute_flow_and_disp(save_path, data_path, model_path_disp,
                          model_path_flow):
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    file_list = sorted(os.listdir(data_path + 'image_2'))

    for i in range(len(file_list)):
        import netdef_slim as nd
        img_t0_L = data_path + 'image_2/' + file_list[i]
        img_t0_R = data_path + 'image_3/' + file_list[i]

        dispnet_controller = nd.load_module(model_path_disp +
                                            'controller.py').Controller()
        data = dispnet_controller.net_actions(net_dir=model_path_disp).eval(
            img_t0_L, img_t0_R)
        disp = data['disp.L'][0, 0, :, :]
        writeFloat(save_path + file_list[i] + '.disp.L.float3', disp)

        flownet_controller = nd.load_module(model_path_flow +
                                            'controller.py').Controller()
        if i < len(file_list) - 1:
            img_t1_L = data_path + 'image_2/' + file_list[i + 1]
            flow_fwd = flownet_controller.net_actions(
                net_dir=model_path_flow).eval(img_t0_L, img_t1_L)
            for key, value in flow_fwd.items():
                if 'flow' in key:
                    writeFlow(save_path + file_list[i] + '.' + key + '.flo',
                              value[0, :, :, :].transpose(1, 2, 0))
                else:
                    writeFloat(
                        save_path + file_list[i] + '.' + key + '.float3',
                        value[0, :, :, :].transpose(1, 2, 0))

            flow_bwd = flownet_controller.net_actions(
                net_dir=model_path_flow).eval(img_t1_L, img_t0_L)
            for key, value in flow_bwd.items():
                if 'flow' in key:
                    writeFlow(
                        save_path + file_list[i] + '.' +
                        key.replace('fwd', 'bwd') + '.flo',
                        value[0, :, :, :].transpose(1, 2, 0))
                else:
                    writeFloat(
                        save_path + file_list[i] + '.' +
                        key.replace('fwd', 'bwd') + '.float3',
                        value[0, :, :, :].transpose(1, 2, 0))
Пример #2
0
    def __init__(self, path=None, gpu_id=0, quiet=False):
        if path is None:
            path = self.base_path

        self._gpu_id = gpu_id
        self._path = path
        self._quiet = quiet

        parts = list(os.path.normpath(self._path).split('/'))
        self._name = parts[-1]

        self._train_dir = self.path('training')
        self._scratch_dir = 'scratch/%s' % uuid.uuid4()
        self._scratch_log_file = self._scratch_dir + '/log.txt'

        self._net_config_file = self.path('config.py')

        os.environ['NETDEF_QUIET'] = str(quiet)
        nd.set_quiet(quiet)
        nd.load_module(self._net_config_file)
Пример #3
0
    def __init__(self):
        c = nd.load_module(
            '/home/netdef/netdef_models/DispNet3/css/controller.py'
        ).Controller()
        self.disp_net = c.net_actions(net_dir=c.base_path)
        self.bridge = CvBridge()

        self.images_queue = []
        self.disparity_image_publisher = rospy.Publisher('/nn/debug', Image)
        self.disparity_publisher = rospy.Publisher('/nn/depth', DisparityImage)
        self.right_camera_info_subscriber = rospy.Subscriber(
            '/camera/infra2/camera_info', CameraInfo,
            self.on_camera_info_received)
        self.right_camera_info_publisher = rospy.Publisher(
            '/camera/infra2/modified_camera_info', CameraInfo)
Пример #4
0
    def __init__(self, net_dir, save_snapshots=True, save_summaries=True):
        self._check_evo_manager_init()
        self.net = nd.load_module(os.path.join(net_dir, 'net.py'))
        self.net_dir = net_dir

        height = 480
        width = 640

        tf.reset_default_graph()
        last_evo, current_evo = nd.evo_manager.get_status()
        self.env = self.net.get_env()
        print('Evolution: ' + last_evo.path())

        self.eval_out = self.env.make_eval_graph(
            width=width,
            height=height,
        )

        self.session = self._create_session()
        self.trainer = SimpleTrainer(session=self.session,
                                     train_dir=last_evo.path())
        self.session.run(tf.global_variables_initializer())

        ignore_vars = []
        if len(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                                 scope="copy")) > 0:
            ignore_vars = [
                tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                                  scope="copy")[0]
            ]
        state = last_evo.last_state()
        self.trainer.load_checkpoint(state.path(), ignore_vars=ignore_vars)

        placeholders = tf.get_collection('placeholders')
        self.img0 = placeholders[0]
        self.img1 = placeholders[1]
Пример #5
0
 def __init__(self, path=None, net_actions=NetActions):
     if path is not None:
         self.base_path = path
     nd.load_module(os.path.join(self.base_path, 'config.py'))
     self.net_actions = net_actions
Пример #6
0
 def __init__(self, net_dir, save_snapshots=True, save_summaries=True):
     self._check_evo_manager_init()
     self.net = nd.load_module(os.path.join(net_dir, 'net.py'))
     self.net_dir = net_dir
Пример #7
0
im = cv2.imread(im_paths[0])# HxWxC
im_h, im_w, im_c = im.shape
x0,y0,w,h = youtube_to_rec(labels[0],im_h,im_w)
init_rbox = [x0,y0,w,h]
#[cx, cy], [w, h] = rect_2_cxy_wh(init_rbox)
#target_pos, target_sz = np.array([cx, cy]), np.array([w, h])
#state = SiamRPN_init(im, target_pos, target_sz, net)

# tracker init
#target_pos, target_sz = np.array([cx, cy]), np.array([w, h])
cv2.rectangle(im, (x0,y0), (x0+w, y0+h), (0, 255, 0), 2)

warped_images = []


c = nd.load_module('/home/jianingq/netdef_models/FlowNetH/Pred-Merged-SS/controller.py').Controller()

for i in range(0,2):
    c_net = c.net_actions(net_dir='/home/jianingq/netdef_models/FlowNetH/Pred-Merged-SS')
    im1 = im_paths[i]
    im2 = im_paths[i+1]
    if i == 0:
        eval_out, session = c_net.init_eval(im2, im1)
    out = c_net.simple_eval(eval_out, session, im2, im1)

    for k,v in out.items():
        if(k =='flow[0][1].fwd'):
            flow_data.append(v[0,:,:,:].transpose(1,2,0))
        elif(k == 'iul_entropy[0][1].fwd'):
            entropy_data.append(v[0,:,:,:].transpose(1,2,0))
        if(k == 'iul_scale[0][1].fwd'):