def runtrain(args):
    #config = LSTMIMG_LapConfig(load=True)
    config = LSTMIMG_GPUConfig(load=True, args=args)

    trainReader = LSTMIMGProcessor(config.trainAnnotFile,
                                   config.rawQnTrain,
                                   config.trainImgFile,
                                   config,
                                   is_training=True)

    valReader = LSTMIMGProcessor(config.valAnnotFile,
                                 config.rawQnValTestFile,
                                 config.valImgFile,
                                 config,
                                 is_training=False)

    #dumReader = DummyReader(config)

    model = LSTMIMGmodel(config)
    model.construct()
    model.train(trainReader, valReader, config.logFile)
    #model.train(dumReader, dumReader)
    model.destruct()

    return config
Exemplo n.º 2
0
def validateInternalTestSet(args, restoreModel=None, restoreModelPath=None):
    from vqaTools.vqaInternal import VQA
    from vqaTools.vqaEval import VQAEval

    #config = LSTMIMG_LapConfig(load=True, args)
    config = LSTMIMG_GPUConfig(load=True, args=args)

    if restoreModel is None:
        restoreModel = config.restoreModel
        restoreModelPath = config.restoreModelPath

    print('Running Validation Test on Model')
    valTestReader = LSTMIMGProcessor(config.testAnnotFile,
                                     config.rawQnValTestFile,
                                     config.testImgFile,
                                     config,
                                     is_training=False)

    model = LSTMIMGmodel(config)

    model.loadTrainedModel(restoreModel, restoreModelPath)
    predFile = '{}PredsLSTMEverything.csv'.format(restoreModelPath)
    results, strictAcc = model.runPredict(valTestReader, predFile)
    model.destruct()
    valTestReader.destruct()
    print('predictions made')

    vqa = VQA(config.testAnnotFileUnresolved, config.originalValQns)
    vqaRes = vqa.loadRes(results, config.originalValQns)
    vqaEval = VQAEval(vqa, vqaRes, n=2)
    vqaEval.evaluate()
    print('Writing to file..')
    writeToFile(vqaEval, restoreModelPath, vqa, vqaRes, strictAcc)
Exemplo n.º 3
0
def runMetricsForInternalTestSet(args, restoreModel, restoreModelPath):
    #config = LSTMIMG_LapConfig(load=True, args)
    config = LSTMIMG_GPUConfig(load=True, args=args)

    print('Running Validation Test on Model')
    valTestReader = LSTMIMGProcessor(config.testAnnotFile,
                                     config.rawQnValTestFile,
                                     config.testImgFile,
                                     config,
                                     is_training=False)
    model = LSTMIMGmodel(config)
    model.loadTrainedModel(restoreModel, restoreModelPath)
    lab, pred, classToAnsMap = model.runEvaluationMetrics(valTestReader)
    model.destruct()
    valTestReader.destruct()

    #run metrics & get stats
    listOfStats = runMetrics(lab, pred, classToAnsMap, restoreModelPath)

    #save to pickle
    data = {}
    data['labels'] = lab
    data['preds'] = pred
    data['classToAnsMap'] = classToAnsMap
    dateID = restoreModelPath.split('/')[-2]
    saveToPickle(data, 'labpreds{}.pkl'.format(dateID))
    print('predictions made')

    return listOfStats
Exemplo n.º 4
0
def loadOfficialTest(args, restoreModel=None, restoreModelPath=None):
    config = LSTMIMG_GPUConfig(load=True, args=args)

    testReader = TestProcessor(qnFile=config.testOfficialDevQns,
                               imgFile=config.testOfficialImgFeatures,
                               config=config)

    model = LSTMIMGmodel(config)
    if restoreModel is None:
        model.loadTrainedModel(config.restoreModel, config.restoreModelPath)
    else:
        model.loadTrainedModel(restoreModel, restoreModelPath)
    model.runTest(testReader, config.testOfficialResultFile)
    model.destruct()