def visQnImgAtt(): print('Running qn Visuals') config = Attention_LapConfig(load=True, args=args) reader = AttModelInputProcessor(config.testAnnotFile, config.rawQnValTestFile, config.valImgFile, config, is_training=False) #reader = AttModelInputProcessor(config.trainAnnotFile, # config.rawQnTrain, # config.trainImgFile, # config, # is_training=False) model = QnAttentionModel(config) saveData = True model.loadTrainedModel(config.restoreQuAttSigmoidModel, config.restoreQuAttSigmoidModelPath) #model.loadTrainedModel(config.restoreQnImAttModel, # config.restoreQnImAttModelPath) qnAlphas, alphas, img_ids, qns, preds, topk, labs = model.runPredict( reader, config.csvResults, 200, mini=True, chooseBatch=30) model.destruct() out = OutputGenerator(config.valImgPaths) #out = OutputGenerator(config.trainImgPaths) #out.displayQnImgAttention(qnAlphas, alphas, img_ids, qns, preds, topk, labs,saveData) out.displayQnImgAttSaveSplit(qnAlphas, alphas, img_ids, qns, preds, topk, labs,saveData)
def solve(): print('Running solve') config = Attention_LapConfig(load=True, args=args) out = OutputGenerator(config.trainImgPaths) #img_id = raw_input('Img_id--> ') img_id = str(262415) img = Image.open(out.convertIDtoPath(str(img_id))) img.show() qn = raw_input('Question--> ') print(qn) model = ImageAttentionModel(config) model.loadTrainedModel(config.restoreModel, config.restoreModelPath) alpha, pred = model.solve(qn, img_id) out.displaySingleOutput(alpha, img_id, qn, pred) ''' -a otest -r ./results/Att21Mar1334/att21Mar1334.meta -p ./results/Att21Mar1334/
def solveqn(): print('Running solve') config = Attention_LapConfig(load=True, args=args) out = OutputGenerator(config.valImgPaths) #img_id = raw_input('Img_id--> ') img_id = str(337826) #214587 img = Image.open(out.convertIDtoPath(str(img_id))) img.show() model = QnAttentionModel(config) model.loadTrainedModel(config.restoreQnImAttModel, config.restoreQnImAttModelPath) processor = OnlineProcessor(config.valImgFile, config) for i in range(5): qn = raw_input('Question--> ') print(qn) qnalpha, alpha, pred = model.solve(qn, img_id, processor) out.displaySingleOutput(alpha, img_id, qn, pred)
def runVisualise(): print('Running Visuals') config = Attention_LapConfig(load=True, args=args) reader = AttModelInputProcessor(config.trainAnnotFile, config.rawQnTrain, config.trainImgFile, config, is_training=False) model = ImageAttentionModel(config) model.loadTrainedModel(config.restoreModel, config.restoreModelPath) alphas, img_ids, qns, preds = model.runPredict( reader, config.csvResults, 5, mini=True) model.destruct() reader.destruct() out = OutputGenerator(config.trainImgPaths) out.displayOutput(alphas, img_ids, qns, preds)
def runVisualiseVal(): print('Running Visuals') config = Attention_LapConfig(load=True, args=args) reader = AttModelInputProcessor(config.testAnnotFile, config.rawQnValTestFile, config.valImgFile, config, is_training=False) model = ImageAttentionModel(config) model.loadTrainedModel(config.restoreModel, config.restoreModelPath) alphas, img_ids, qns, preds, labels = model.runPredict( reader, config.csvResults, 180, mini=True, chooseBatch=0) model.destruct() reader.destruct() out = OutputGenerator(config.valImgPaths) out.displayEachSample(alphas, img_ids, qns, preds, labels, saveData=True)
def visQnImgAtt(): print('Running qn Visuals') config = Attention_LapConfig(load=True, args=args) reader = AttModelInputProcessor(config.testAnnotFile, config.rawQnValTestFile, config.valImgFile, config, is_training=False) model = QnAttentionModel(config) model.loadTrainedModel(config.restoreQnImAttModel, config.restoreQnImAttModelPath) qnAlphas, alphas, img_ids, qns, preds, topk = model.runPredict( reader, config.csvResults, 5, mini=True) model.destruct() out = OutputGenerator(config.valImgPaths) out.displayQnImgAttention(qnAlphas, alphas, img_ids, qns, preds, topk)