Example #1
0
    def _generateBatchFromIDs(self, imageIdxs, batchIdx):
        imagesID = [self.dataID[idx] for idx in imageIdxs]

        imageMeta = self.imagesMeta[imagesID[0]]
        imageMeta = cp.copy(imageMeta)

        [dataXI, dataXH,
         dataXO], _ = image.getXData(imageMeta, self.images_path, self.cfg,
                                     batchIdx)
        dataXW = image.getDataPairWiseStream(imageMeta, self.cfg)
        dataXW = np.expand_dims(dataXW, axis=0)
        y, _, _ = image.getYData(imagesID, self.imagesMeta, self.GTMeta,
                                 self.cfg)

        if dataXH.shape[1] > 32:
            dataXH = dataXH[:, :32, :]
            dataXO = dataXO[:, :32, :]
            dataXW = dataXW[:, :32, :, :, :]
            y = y[:, :32, :]

        X = [dataXI, dataXH, dataXO, dataXW]
        X = [X[i + 1] for i in range(len(X) - 1) if self.inputs[i]]
        if self.inputs[0] or self.inputs[1]:
            X = [dataXI] + X

        return X, y
Example #2
0
 def _generateBatchFromIDs(self, batchID):
     batchID = [self.dataID[idx] for idx in batchID]
     #        print(batchID)
     [dataXP, dataXB] = image.getX2Data(batchID, self.imagesMeta,
                                        self.images_path, self.cfg)
     dataXW = image.getDataPairWiseStream(batchID, self.imagesMeta,
                                          self.cfg)
     X = [dataXP, dataXB, dataXW]
     X = [X[i] for i in range(len(X)) if self.inputs[i]]
     y, _ = image.getYData(batchID, self.imagesMeta, self.GTMeta, self.cfg)
     return X, y
Example #3
0
    def __init__(self,
                 imagesMeta,
                 GTMeta,
                 cfg,
                 data_type='train',
                 do_meta=False):
        'Initialization'
        self.do_meta = do_meta
        self.data_type = data_type
        if data_type == 'train':
            g_cfg = cfg.train_cfg
        elif data_type == 'val':
            g_cfg = cfg.val_cfg
        else:
            g_cfg = cfg.test_cfg

        self.gen_type = g_cfg.type
        self.batch_size = g_cfg.batch_size
        self.nb_batches = g_cfg.nb_batches
        self.images_per_batch = g_cfg.images_per_batch
        self.nb_samples_per_image = int(self.batch_size /
                                        self.images_per_batch)

        self.shuffle = g_cfg.shuffle
        self.inputs = cfg.inputs

        cfg.img_out_reduction = (1, 1)

        self.data_path = cfg.data_path
        self.images_path = self.data_path + 'images/'
        self.images_path = self.images_path + 'test/' if self.data_type == 'test' else self.images_path + 'train/'
        self.nb_classes = cfg.nb_classes
        self.cfg = cfg

        self.dataID = list(imagesMeta.keys())
        self.dataID.sort()
        if self.shuffle:
            r.shuffle(self.dataID)

        self.imagesMeta = imagesMeta
        self.GTMeta = GTMeta
        gt_label, _, _ = image.getYData(self.dataID, self.imagesMeta,
                                        self.GTMeta, self.cfg)
        self.nb_images = len(self.dataID)
        self.nb_samples = gt_label.shape[1]
        if self.nb_batches is None:
            self.nb_batches = m.ceil(self.nb_samples / self.batch_size)
Example #4
0
    def _generateBatchFromIDs(self, batchID):
        batchID = [self.dataID[idx] for idx in batchID]
        #        print(batchID)
        imageMeta = self.imagesMeta[batchID[0]]
        imageMeta = cp.copy(imageMeta)

        [dataXP, dataXB], img = image.getX2Data(imageMeta, self.images_path,
                                                self.cfg)
        dataXW = image.getDataPairWiseStream(imageMeta, self.cfg)
        X = [dataXP, dataXB, dataXW]
        X = [X[i] for i in range(len(X)) if self.inputs[i]]
        y, _, _ = image.getYData(batchID, self.imagesMeta, self.GTMeta,
                                 self.cfg)
        y = y[0]

        if self.do_meta:
            return X, y, imageMeta, img

        return X, y
Example #5
0
 def getYData(self):
     gt_label, _, _ = image.getYData(self.dataID, self.imagesMeta,
                                     self.GTMeta, self.cfg, 32)
     gt_label = gt_label[0, :, :]
     return gt_label
Example #6
0
sys.path.append('../../classification/models/')
sys.path.append('../../shared/')

import utils
from model_trainer import model_trainer
from load_data import data
from generators import DataGenerator

import numpy as np
import metrics
import image

if False:
    # Load data
    print('Loading data...')
    data = data(method='normal')
    cfg = data.cfg

    genTest = DataGenerator(imagesMeta=data.testMeta,
                            GTMeta=data.testGTMeta,
                            cfg=cfg,
                            data_type='test')

    gt_label, _, _ = image.getYData(genTest.dataID, genTest.imagesMeta,
                                    genTest.GTMeta, genTest.cfg)

path = 'C:\\Users\\aag14/Documents/Skole/Speciale/results/HICO/hoi80/yhat1'
yhat = utils.load_obj(path)

evalHOI = metrics.EvalResults(None, genTest, yhat=yhat, y=gt_label[0])
print(evalHOI.mAP, evalHOI.F1)
Example #7
0
    trainer_th = model_trainer(model=model_th_all,
                               genTrain=genTrain,
                               genVal=None,
                               genTest=None,
                               task=cfg.task)
    trainer_th.compileModel(cfg)

if False:
    imageID = 'HICO_train2015_00000015.jpg'
    [dataXP_new,
     dataXB_new] = image.getX2Data([imageID], genTrain.imagesMeta,
                                   genTrain.images_path, genTrain.cfg)
    dataXW_new = image.getDataPairWiseStream([imageID], genTrain.imagesMeta,
                                             genTrain.cfg)
    y_new, _, _ = image.getYData([imageID], genTrain.imagesMeta,
                                 genTrain.GTMeta, genTrain.cfg)

    dataXP_new = dataXP_new[0]
    dataXB_new = dataXB_new[0]
    dataXW_new = dataXW_new[0]
    y_new = y_new[0]

#    trainer_th.trainModel(cfg)
#    print('Testing model on test...')
#    resTest = trainer_th.evaluateModel(genTest)
#    print("F1 (test!):", resTest.F1, "nb_zeros", resTest.nb_zeros)

j = 0
for i in range(1):
    X, y = next(trainIterator)