(self)
return iterator
Load a batch of training instances using the new tensorflow
        Dataset api.
Load a batch of training instances using the new tensorflow
        Dataset api.
Load a batch of training instances using the new tensorflow Dataset api .
def load_train_batch(self):
        """
        Load a batch of training instances using the new tensorflow
        Dataset api.
        """
        def _parse_train_img(img_path):
            with tf.device('/cpu:0'):
                img_buffer = tf.read_file(img_path)
                image_decoded = tf.image.decode_jpeg(img_buffer)
                tgt_image, src_image_stack = \
                    self.unpack_image_sequence(
                        image_decoded, self.img_height, self.img_width, self.num_source)
            return tgt_image, src_image_stack

        def _batch_preprocessing(stack_images, intrinsics, optional_data):
            intrinsics = tf.cast(intrinsics, tf.float32)
            image_all = tf.concat([stack_images[0], stack_images[1]], axis=3)

            if self.match_num == 0:  # otherwise matches coords are wrong
                image_all, intrinsics = self.data_augmentation(
                    image_all, intrinsics, self.img_height, self.img_width)
            tgt_image = image_all[:, :, :, :3]
            src_image_stack = image_all[:, :, :, 3:]
            intrinsics = self.get_multi_scale_intrinsics(intrinsics, self.num_scales)
            return tgt_image, src_image_stack, intrinsics, optional_data

        file_list = self.format_file_list(self.dataset_dir, 'train')
        self.steps_per_epoch = int(len(file_list['image_file_list'])//self.batch_size)

        input_image_names_ph = tf.placeholder(tf.string, shape=[None], name='input_image_names_ph')
        image_dataset = tf.data.Dataset.from_tensor_slices(
            input_image_names_ph).map(_parse_train_img)

        cam_intrinsics_ph = tf.placeholder(tf.float32, [None, 3, 3], name='cam_intrinsics_ph')
        intrinsics_dataset = tf.data.Dataset.from_tensor_slices(cam_intrinsics_ph)

        datasets = (image_dataset, intrinsics_dataset, intrinsics_dataset)
        if self.read_pose:
            poses_ph = tf.placeholder(tf.float32, [None, self.num_source+1, 6], name='poses_ph')
            pose_dataset = tf.data.Dataset.from_tensor_slices(poses_ph)
            datasets = (image_dataset, intrinsics_dataset, pose_dataset)
        if self.match_num > 0:
            matches_ph = tf.placeholder(tf.float32, [None, self.num_source, self.match_num, 4], name='matches_ph')
            match_dataset = tf.data.Dataset.from_tensor_slices(matches_ph)
            datasets = (image_dataset, intrinsics_dataset, match_dataset)

        all_dataset = tf.data.Dataset.zip(datasets)
        all_dataset = all_dataset.batch(self.batch_size).repeat().prefetch(self.batch_size*4)
        all_dataset = all_dataset.map(_batch_preprocessing)
        iterator = all_dataset.make_initializable_iterator()
        return iterator
def load_train_batch ( self ) : def _parse_train_img ( img_path ) : with tf . device ( '/cpu:0' ) : img_buffer = tf . read_file ( img_path ) image_decoded = tf . image . decode_jpeg ( img_buffer ) tgt_image , src_image_stack = self . unpack_image_sequence ( image_decoded , self . img_height , self . img_width , self . num_source ) return tgt_image , src_image_stack def _batch_preprocessing ( stack_images , intrinsics , optional_data ) : intrinsics = tf . cast ( intrinsics , tf . float32 ) image_all = tf . concat ( [ stack_images [ 0 ] , stack_images [ 1 ] ] , axis = 3 ) if self . match_num == 0 : # otherwise matches coords are wrong image_all , intrinsics = self . data_augmentation ( image_all , intrinsics , self . img_height , self . img_width ) tgt_image = image_all [ : , : , : , : 3 ] src_image_stack = image_all [ : , : , : , 3 : ] intrinsics = self . get_multi_scale_intrinsics ( intrinsics , self . num_scales ) return tgt_image , src_image_stack , intrinsics , optional_data file_list = self . format_file_list ( self . dataset_dir , 'train' ) self . steps_per_epoch = int ( len ( file_list [ 'image_file_list' ] ) // self . batch_size ) input_image_names_ph = tf . placeholder ( tf . string , shape = [ None ] , name = 'input_image_names_ph' ) image_dataset = tf . data . Dataset . from_tensor_slices ( input_image_names_ph ) . map ( _parse_train_img ) cam_intrinsics_ph = tf . placeholder ( tf . float32 , [ None , 3 , 3 ] , name = 'cam_intrinsics_ph' ) intrinsics_dataset = tf . data . Dataset . from_tensor_slices ( cam_intrinsics_ph ) datasets = ( image_dataset , intrinsics_dataset , intrinsics_dataset ) if self . read_pose : poses_ph = tf . placeholder ( tf . float32 , [ None , self . num_source + 1 , 6 ] , name = 'poses_ph' ) pose_dataset = tf . data . Dataset . from_tensor_slices ( poses_ph ) datasets = ( image_dataset , intrinsics_dataset , pose_dataset ) if self . match_num > 0 : matches_ph = tf . placeholder ( tf . float32 , [ None , self . num_source , self . match_num , 4 ] , name = 'matches_ph' ) match_dataset = tf . data . Dataset . from_tensor_slices ( matches_ph ) datasets = ( image_dataset , intrinsics_dataset , match_dataset ) all_dataset = tf . data . Dataset . zip ( datasets ) all_dataset = all_dataset . batch ( self . batch_size ) . repeat ( ) . prefetch ( self . batch_size * 4 ) all_dataset = all_dataset . map ( _batch_preprocessing ) iterator = all_dataset . make_initializable_iterator ( ) return iterator