Esempio n. 1
0
    def __init__(self,
                 batch_size,
                 n_classes,
                 feature_dim,
                 feature_name,
                 is_training,
                 is_shuffle=True):
        """
        Initialization
        """

        self.batch_size = batch_size
        self.is_training = is_training
        self.n_classes = n_classes
        self.feature_dim = feature_dim
        self.feature_name = feature_name
        self.is_shuffle = is_shuffle
        self.dataset_name = 'charades'

        # load annotation
        root_path = '/content/drive/My Drive/Charades_timeception/Charades'
        annotation_path = '%s/video_annotation.pkl' % (root_path)
        if self.is_training:
            (video_names, y, _, _) = utils.pkl_load(annotation_path)
        else:
            (_, _, video_names, y) = utils.pkl_load(annotation_path)

        # in case of single label classification, debinarize the labels
        if config.cfg.MODEL.CLASSIFICATION_TYPE == 'sl':
            y = utils.debinarize_label(y)

        # in any case, make sure target is float
        y = y.astype(np.float32)

        # convert relative to root pathes

        feats_path = np.array([
            '%s/%s/%s.pkl' % (root_path, feature_name, p) for p in video_names
        ])

        n_samples = len(y)
        self.n_samples = n_samples
        self.n_batches = utils.calc_num_batches(n_samples, batch_size)
        self.feats_path = feats_path
        self.y = y

        # shuffle the data
        if self.is_shuffle:
            self.__shuffle()
Esempio n. 2
0
    def __init__(self,
                 batch_size,
                 n_classes,
                 feature_dim,
                 feature_name,
                 is_training,
                 is_shuffle=True):
        """
        Initialization
        """
        self.batch_size = batch_size
        self.is_training = is_training
        self.n_classes = n_classes
        self.feature_dim = feature_dim
        self.feature_name = feature_name
        self.is_shuffle = is_shuffle
        self.dataset_name = 'charades'

        # load annotation
        root_path = '/content/drive/My Drive/Charades_timeception/Charades'
        annotation_path = '%s/video_annotation.pkl' % (root_path)
        #/content/timeception/data/charades/annotation/video_annotation.pkl
        if self.is_training:
            (video_names, y, _, _) = utils.pkl_load(annotation_path)
        else:
            (_, _, video_names, y) = utils.pkl_load(annotation_path)

        # convert relative to root pathes
        feats_path = np.array([
            '%s/%s/%s.pkl' % (root_path, feature_name, p) for p in video_names
        ])

        n_samples = len(y)
        self.n_samples = n_samples
        self.n_batches = utils.calc_num_batches(n_samples, batch_size)
        self.feats_path = feats_path
        self.y = y

        # shuffle the data
        if self.is_shuffle:
            self.__shuffle()
Esempio n. 3
0
    def __getitem__(self, index):
        """
        Generate one batch of data
        """

        y = self.y[index]
        p = self.feats_path[index]
        x = utils.pkl_load(p)  # (T, H, W, C)

        # convert to channel last
        x = np.transpose(x, (3, 0, 1, 2))  # (T, H, W, C)

        return x, y
Esempio n. 4
0
    def __load_features(self, params):

        idx_video = params[0]
        feats_path = params[1]
        video_name = feats_path.split('/')[-1]

        try:
            # load feature from file
            feats = utils.pkl_load(feats_path)

            n_feats = len(feats)
            assert n_feats == self.__n_frames_per_video, 'Sorry, wrong number of frames, expected: %d, got: %d' % (
                self.__n_frames_per_video, n_feats)
            self.__batch_features[idx_video] = feats

        except Exception as exp:
            print('\nSorry, error in loading feature %s' % (feats_path))
            print(exp)
Esempio n. 5
0
    def __getitem__(self, index):
        """
        Generate one batch of data.
        """

        idx_start = index * self.batch_size
        idx_stop = (index + 1) * self.batch_size
        y = self.y[idx_start:idx_stop]
        feats_path = self.feats_path[idx_start:idx_stop]

        n_items = len(feats_path)
        x_shape = tuple([n_items] + list(self.feature_dim))
        x = np.zeros(x_shape, dtype=np.float32)

        # loop of feature pathes and load them
        for idx, p in enumerate(feats_path):
            x[idx] = utils.pkl_load(p)

        return x, y