<s> import sys <EOL> import os <EOL> import json <EOL> import re <EOL> import cPickle as pkl <EOL> from nn . func import * <EOL> import imageqa_test as it <EOL> import imageqa_ensemble as ie <EOL> import requests <EOL> jsonTrainFilename = '<STR_LIT>' <EOL> jsonValidFilename = '<STR_LIT>' <EOL> htmlHyperLink = '<STR_LIT>' <EOL> cssHyperLink = '<STR_LIT>' <EOL> daquarImageFolder = '<STR_LIT>' <EOL> def renderLatexAnswerList ( <EOL> correctAnswer , <EOL> topAnswers , <EOL> topAnswerScores ) : <EOL> result = [ ] <EOL> for i , answer in enumerate ( topAnswers ) : <EOL> if answer == correctAnswer : <EOL> colorStr = '<STR_LIT>' <EOL> elif i == <NUM_LIT:0> : <EOL> colorStr = '<STR_LIT>' <EOL> else : <EOL> colorStr = '<STR_LIT:%s>' <EOL> result . append ( colorStr % ( '<STR_LIT>' % ( answer , topAnswerScores [ i ] ) ) ) <EOL> return '<STR_LIT>' . join ( result ) <EOL> def renderLatexSingleItem ( <EOL> questionIndex , <EOL> question , <EOL> correctAnswer , <EOL> pictureFolder = '<STR_LIT>' , <EOL> comment = None , <EOL> topAnswers = None , <EOL> topAnswerScores = None , <EOL> modelNames = None ) : <EOL> result = [ ] <EOL> imgPath = os . path . join ( pictureFolder , '<STR_LIT>' % questionIndex ) <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' % imgPath ) <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' % ( questionIndex , question ) ) <EOL> result . append ( '<STR_LIT>' % correctAnswer ) <EOL> i = <NUM_LIT:0> <EOL> if modelNames is not None and len ( modelNames ) > <NUM_LIT:1> : <EOL> for modelAnswer , modelAnswerScore , modelName in zip ( topAnswers , topAnswerScores , modelNames ) : <EOL> result . append ( '<STR_LIT>' % modelName ) <EOL> result . append ( <EOL> renderLatexAnswerList ( <EOL> correctAnswer , <EOL> modelAnswer , <EOL> modelAnswerScore ) ) <EOL> if i != len ( modelNames ) - <NUM_LIT:1> : <EOL> result . append ( '<STR_LIT>' ) <EOL> i += <NUM_LIT:1> <EOL> result . append ( '<STR_LIT:\n>' ) <EOL> elif topAnswers is not None : <EOL> result . append ( <EOL> renderLatexAnswerList ( <EOL> correctAnswer , <EOL> topAnswers , <EOL> topAnswerScores ) ) <EOL> result . append ( '<STR_LIT:\n>' ) <EOL> if comment is not None : <EOL> result . append ( '<STR_LIT>' + comment ) <EOL> result . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( result ) <EOL> def renderLatexSinglePage ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> outputFolder , <EOL> pictureFolder = '<STR_LIT>' , <EOL> topK = <NUM_LIT:10> , <EOL> comments = None , <EOL> caption = None , <EOL> modelOutputs = None , <EOL> modelNames = None , <EOL> questionIds = None ) : <EOL> result = [ ] <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' ) <EOL> imgPerRow = <NUM_LIT:3> <EOL> imgFolder = os . path . join ( outputFolder , pictureFolder ) <EOL> for n in range ( inputData . shape [ <NUM_LIT:0> ] ) : <EOL> imageId = inputData [ n , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> imageFilename = urlDict [ imageId - <NUM_LIT:1> ] <EOL> r = requests . get ( imageFilename ) <EOL> qid = questionIds [ n ] if questionIds is not None else n <EOL> if not os . path . exists ( imgFolder ) : <EOL> os . makedirs ( imgFolder ) <EOL> with open ( os . path . join ( imgFolder , '<STR_LIT>' % qid ) , '<STR_LIT:wb>' ) as f : <EOL> f . write ( r . content ) <EOL> question = it . decodeQuestion ( inputData [ n ] , questionIdict ) <EOL> answer = ansIdict [ targetData [ n , <NUM_LIT:0> ] ] <EOL> topAnswers , topAnswerScores = pickTopAnswers ( <EOL> ansIdict , <EOL> n , <EOL> topK = topK , <EOL> modelOutputs = modelOutputs , <EOL> modelNames = modelNames ) <EOL> comment = comments [ n ] if comments is not None else None <EOL> result . append ( <EOL> renderLatexSingleItem ( <EOL> qid , <EOL> question , <EOL> answer , <EOL> pictureFolder = pictureFolder , <EOL> comment = comment , <EOL> topAnswers = topAnswers , <EOL> topAnswerScores = topAnswerScores , <EOL> modelNames = modelNames ) ) <EOL> if np . mod ( n , imgPerRow ) == imgPerRow - <NUM_LIT:1> : <EOL> result . append ( '<STR_LIT>' ) <EOL> if n != inputData . shape [ <NUM_LIT:0> ] - <NUM_LIT:1> : <EOL> result . append ( '<STR_LIT>' ) <EOL> else : <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' % caption if caption is not None else '<STR_LIT>' ) <EOL> result . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( result ) <EOL> def renderLatex ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> outputFolder , <EOL> pictureFolder = '<STR_LIT>' , <EOL> topK = <NUM_LIT:10> , <EOL> comments = None , <EOL> caption = None , <EOL> modelOutputs = None , <EOL> modelNames = None , <EOL> questionIds = None , <EOL> filename = '<STR_LIT>' ) : <EOL> imgPerRow = <NUM_LIT:3> <EOL> rowsPerPage = <NUM_LIT:3> <EOL> imgPerPage = imgPerRow * rowsPerPage <EOL> imgFolder = os . path . join ( outputFolder , '<STR_LIT>' ) <EOL> if inputData . shape [ <NUM_LIT:0> ] < imgPerPage : <EOL> latexStr = renderLatexSinglePage ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> outputFolder , <EOL> pictureFolder = pictureFolder , <EOL> topK = topK , <EOL> comments = comments , <EOL> caption = caption , <EOL> modelOutputs = modelOutputs , <EOL> modelNames = modelNames , <EOL> questionIds = questionIds ) <EOL> else : <EOL> result = [ ] <EOL> numPages = int ( np . ceil ( inputData . shape [ <NUM_LIT:0> ] / float ( imgPerPage ) ) ) <EOL> for i in range ( numPages ) : <EOL> start = imgPerPage * i <EOL> end = min ( inputData . shape [ <NUM_LIT:0> ] , imgPerPage * ( i + <NUM_LIT:1> ) ) <EOL> if modelOutputs is not None : <EOL> modelOutputSlice = [ ] <EOL> for j in range ( len ( modelNames ) ) : <EOL> modelOutputSlice . append ( modelOutputs [ j ] [ start : end ] ) <EOL> else : <EOL> modelOutputSlice = None <EOL> page = renderLatexSinglePage ( <EOL> inputData [ start : end ] , <EOL> targetData [ start : end ] , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> outputFolder , <EOL> pictureFolder = pictureFolder , <EOL> topK = topK , <EOL> comments = comments [ start : end ] if comments is not None else None , <EOL> caption = caption , <EOL> modelOutputs = modelOutputSlice , <EOL> modelNames = modelNames , <EOL> questionIds = questionIds [ start : end ] ) <EOL> result . append ( page ) <EOL> latexStr = '<STR_LIT>' . join ( result ) <EOL> with open ( os . path . join ( outputFolder , filename ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( latexStr ) <EOL> def renderHtml ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> topK = <NUM_LIT:10> , <EOL> modelOutputs = None , <EOL> modelNames = None , <EOL> questionIds = None ) : <EOL> imgPerPage = <NUM_LIT:1000> <EOL> if inputData . shape [ <NUM_LIT:0> ] < imgPerPage : <EOL> return [ renderSinglePage ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> iPage = <NUM_LIT:0> , <EOL> numPages = <NUM_LIT:1> , <EOL> topK = topK , <EOL> modelOutputs = modelOutputs , <EOL> modelNames = modelNames , <EOL> questionIds = questionIds ) ] <EOL> else : <EOL> result = [ ] <EOL> numPages = int ( np . ceil ( inputData . shape [ <NUM_LIT:0> ] / float ( imgPerPage ) ) ) <EOL> for i in range ( numPages ) : <EOL> start = imgPerPage * i <EOL> end = min ( inputData . shape [ <NUM_LIT:0> ] , imgPerPage * ( i + <NUM_LIT:1> ) ) <EOL> if modelOutputs is not None : <EOL> modelOutputSlice = [ ] <EOL> for j in range ( len ( modelNames ) ) : <EOL> modelOutputSlice . append ( modelOutputs [ j ] [ start : end ] ) <EOL> else : <EOL> modelOutputSlice = None <EOL> page = renderSinglePage ( <EOL> inputData [ start : end ] , <EOL> targetData [ start : end ] , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> iPage = i , <EOL> numPages = numPages , <EOL> topK = topK , <EOL> modelOutputs = modelOutputSlice , <EOL> modelNames = modelNames , <EOL> questionIds = questionIds [ start : end ] ) <EOL> result . append ( page ) <EOL> return result <EOL> def renderMenu ( iPage , numPages ) : <EOL> htmlList = [ ] <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> for n in range ( numPages ) : <EOL> if n != iPage : <EOL> htmlList . append ( '<STR_LIT>' % ( ( htmlHyperLink % n ) , n ) ) <EOL> else : <EOL> htmlList . append ( '<STR_LIT>' % n ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( htmlList ) <EOL> def renderCss ( ) : <EOL> cssList = [ ] <EOL> cssList . append ( '<STR_LIT>' ) <EOL> cssList . append ( '<STR_LIT>' ) <EOL> cssList . append ( '<STR_LIT>' ) <EOL> cssList . append ( '<STR_LIT>' ) <EOL> cssList . append ( '<STR_LIT>' ) <EOL> cssList . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( cssList ) <EOL> def renderAnswerList ( <EOL> correctAnswer , <EOL> topAnswers , <EOL> topAnswerScores ) : <EOL> htmlList = [ ] <EOL> for i , answer in enumerate ( topAnswers ) : <EOL> if answer == correctAnswer : <EOL> colorStr = '<STR_LIT>' <EOL> elif i == <NUM_LIT:0> : <EOL> colorStr = '<STR_LIT>' <EOL> else : <EOL> colorStr = '<STR_LIT>' <EOL> htmlList . append ( '<STR_LIT>' % ( colorStr , i + <NUM_LIT:1> , <EOL> answer , topAnswerScores [ i ] ) ) <EOL> return '<STR_LIT>' . join ( htmlList ) <EOL> def renderSingleItem ( <EOL> imageFilename , <EOL> questionIndex , <EOL> question , <EOL> correctAnswer , <EOL> topAnswers = None , <EOL> topAnswerScores = None , <EOL> modelNames = None ) : <EOL> """<STR_LIT>""" <EOL> htmlList = [ ] <EOL> htmlList . append ( '<STR_LIT>' % imageFilename ) <EOL> htmlList . append ( '<STR_LIT>' % ( questionIndex , question ) ) <EOL> htmlList . append ( '<STR_LIT>' % correctAnswer ) <EOL> if topAnswers is not None : <EOL> for modelAnswer , modelAnswerScore , modelName in zip ( topAnswers , topAnswerScores , modelNames ) : <EOL> htmlList . append ( '<STR_LIT>' % modelName ) <EOL> htmlList . append ( <EOL> renderAnswerList ( <EOL> correctAnswer , <EOL> modelAnswer , <EOL> modelAnswerScore ) ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( htmlList ) <EOL> def pickTopAnswers ( <EOL> ansIdict , <EOL> n , <EOL> topK = <NUM_LIT:10> , <EOL> modelOutputs = None , <EOL> modelNames = None , <EOL> questionIds = None ) : <EOL> if modelOutputs is not None : <EOL> topAnswers = [ ] <EOL> topAnswerScores = [ ] <EOL> for j , modelOutput in enumerate ( modelOutputs ) : <EOL> sortIdx = np . argsort ( modelOutput [ n ] , axis = <NUM_LIT:0> ) <EOL> sortIdx = sortIdx [ : : - <NUM_LIT:1> ] <EOL> topAnswers . append ( [ ] ) <EOL> topAnswerScores . append ( [ ] ) <EOL> for i in range ( <NUM_LIT:0> , topK ) : <EOL> topAnswers [ - <NUM_LIT:1> ] . append ( ansIdict [ sortIdx [ i ] ] ) <EOL> topAnswerScores [ - <NUM_LIT:1> ] . append ( modelOutput [ n , sortIdx [ i ] ] ) <EOL> else : <EOL> topAnswers = None <EOL> topAnswerScores = None <EOL> return topAnswers , topAnswerScores <EOL> def renderSinglePage ( <EOL> inputData , <EOL> targetData , <EOL> questionIdict , <EOL> ansIdict , <EOL> urlDict , <EOL> iPage = <NUM_LIT:0> , <EOL> numPages = <NUM_LIT:1> , <EOL> topK = <NUM_LIT:10> , <EOL> modelOutputs = None , <EOL> modelNames = None , <EOL> questionIds = None ) : <EOL> htmlList = [ ] <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> htmlList . append ( '<STR_LIT>' % renderCss ( ) ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> imgPerRow = <NUM_LIT:4> <EOL> htmlList . append ( renderMenu ( iPage , numPages ) ) <EOL> for n in range ( inputData . shape [ <NUM_LIT:0> ] ) : <EOL> if np . mod ( n , imgPerRow ) == <NUM_LIT:0> : <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> imageId = inputData [ n , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> imageFilename = urlDict [ imageId - <NUM_LIT:1> ] <EOL> question = it . decodeQuestion ( inputData [ n ] , questionIdict ) <EOL> qid = questionIds [ n ] if questionIds is not None else n <EOL> topAnswers , topAnswerScores = pickTopAnswers ( <EOL> ansIdict , <EOL> n , <EOL> topK = topK , <EOL> modelOutputs = modelOutputs , <EOL> modelNames = modelNames , <EOL> questionIds = questionIds ) <EOL> htmlList . append ( renderSingleItem ( <EOL> imageFilename , <EOL> qid , <EOL> question , <EOL> ansIdict [ targetData [ n , <NUM_LIT:0> ] ] , <EOL> topAnswers = topAnswers , <EOL> topAnswerScores = topAnswerScores , <EOL> modelNames = modelNames ) ) <EOL> if np . mod ( n , imgPerRow ) == imgPerRow - <NUM_LIT:1> : <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> htmlList . append ( renderMenu ( iPage , numPages ) ) <EOL> htmlList . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( htmlList ) <EOL> def readImgDictCocoqa ( imgidDict ) : <EOL> with open ( jsonTrainFilename ) as f : <EOL> captiontxt = f . read ( ) <EOL> urlDict = { } <EOL> caption = json . loads ( captiontxt ) <EOL> for item in caption [ '<STR_LIT>' ] : <EOL> urlDict [ item [ '<STR_LIT:id>' ] ] = item [ '<STR_LIT:url>' ] <EOL> with open ( jsonValidFilename ) as f : <EOL> captiontxt = f . read ( ) <EOL> caption = json . loads ( captiontxt ) <EOL> for item in caption [ '<STR_LIT>' ] : <EOL> urlDict [ item [ '<STR_LIT:id>' ] ] = item [ '<STR_LIT:url>' ] <EOL> urlList = [ None ] * len ( imgidDict ) <EOL> for i , key in enumerate ( imgidDict ) : <EOL> urlList [ i ] = urlDict [ int ( key ) ] <EOL> return urlList <EOL> def readImgDictDaquar ( ) : <EOL> urlList = [ ] <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> urlList . append ( daquarImageFolder + '<STR_LIT>' % i ) <EOL> return urlList <EOL> def loadImgUrl ( dataset , dataFolder ) : <EOL> print '<STR_LIT>' <EOL> if dataset == '<STR_LIT>' : <EOL> imgidDictFilename = os . path . join ( dataFolder , '<STR_LIT>' ) <EOL> with open ( imgidDictFilename , '<STR_LIT:rb>' ) as f : <EOL> imgidDict = pkl . load ( f ) <EOL> urlDict = readImgDictCocoqa ( imgidDict ) <EOL> elif dataset == '<STR_LIT>' : <EOL> urlDict = readImgDictDaquar ( ) <EOL> return urlDict <EOL> def loadImgPath ( dataset , dataFolder ) : <EOL> print '<STR_LIT>' <EOL> cocoImgIdRegex = '<STR_LIT>' <EOL> if dataset == '<STR_LIT>' : <EOL> imgidDictFilename = os . path . join ( dataFolder , '<STR_LIT>' ) <EOL> with open ( imgidDictFilename , '<STR_LIT:rb>' ) as f : <EOL> imgidDict = pkl . load ( f ) <EOL> pathList = [ None ] * len ( imgidDict ) <EOL> pathDict = { } <EOL> with open ( '<STR_LIT>' ) as f : <EOL> imageList = f . readlines ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> imageList . extend ( f . readlines ( ) ) <EOL> for imgPath in imageList : <EOL> match = re . search ( cocoImgIdRegex , imgPath ) <EOL> imgid = match . group ( '<STR_LIT>' ) <EOL> pathDict [ imgid ] = imgPath [ : - <NUM_LIT:1> ] <EOL> for i , key in enumerate ( imgidDict ) : <EOL> pathList [ i ] = pathDict [ key ] <EOL> return pathList <EOL> elif dataset == '<STR_LIT>' : <EOL> pathList = [ ] <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> pathList . append ( '<STR_LIT>' % i ) <EOL> return pathList <EOL> else : <EOL> raise Exception ( '<STR_LIT>' + dataset ) <EOL> def escapeLatexIdict ( idict ) : <EOL> for i in range ( len ( idict ) ) : <EOL> if '<STR_LIT:_>' in idict [ i ] : <EOL> idict [ i ] = idict [ i ] . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> return idict <EOL> def parseComparativeParams ( argv ) : <EOL> """<STR_LIT>""" <EOL> dataset = '<STR_LIT>' <EOL> filename = '<STR_LIT:result>' <EOL> pictureFolder = '<STR_LIT>' <EOL> resultsFolder = '<STR_LIT>' <EOL> K = <NUM_LIT:1> <EOL> models = [ ] <EOL> format = '<STR_LIT:html>' <EOL> inputFile = None <EOL> for i , flag in enumerate ( argv ) : <EOL> if flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> parts = sys . argv [ i + <NUM_LIT:1> ] . split ( '<STR_LIT::>' ) <EOL> models . append ( { <EOL> '<STR_LIT:name>' : parts [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:id>' : parts [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> parts = sys . argv [ i + <NUM_LIT:1> ] . split ( '<STR_LIT::>' ) <EOL> models . append ( { <EOL> '<STR_LIT:name>' : parts [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:id>' : parts [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> parts = sys . argv [ i + <NUM_LIT:1> ] . split ( '<STR_LIT::>' ) <EOL> models . append ( { <EOL> '<STR_LIT:name>' : parts [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:id>' : parts [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True <EOL> } ) <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> parts = sys . argv [ i + <NUM_LIT:1> ] . split ( '<STR_LIT::>' ) <EOL> models . append ( { <EOL> '<STR_LIT:name>' : parts [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:id>' : parts [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> dataFolder = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> inputFile = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' : <EOL> K = int ( sys . argv [ i + <NUM_LIT:1> ] ) <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> pictureFolder = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> outputFolder = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> resultsFolder = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' or flag == '<STR_LIT>' : <EOL> filename = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' : <EOL> dataset = sys . argv [ i + <NUM_LIT:1> ] <EOL> elif flag == '<STR_LIT>' : <EOL> format = sys . argv [ i + <NUM_LIT:1> ] <EOL> return { <EOL> '<STR_LIT>' : models , <EOL> '<STR_LIT>' : dataFolder , <EOL> '<STR_LIT>' : inputFile , <EOL> '<STR_LIT>' : outputFolder , <EOL> '<STR_LIT>' : resultsFolder , <EOL> '<STR_LIT>' : K , <EOL> '<STR_LIT>' : pictureFolder , <EOL> '<STR_LIT>' : filename , <EOL> '<STR_LIT>' : dataset , <EOL> '<STR_LIT>' : format <EOL> } <EOL> def getModelNames ( modelSpecs ) : <EOL> modelNames = [ ] <EOL> for spec in modelSpecs : <EOL> modelNames . append ( spec [ '<STR_LIT:name>' ] ) <EOL> return modelNames <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> """<STR_LIT>""" <EOL> params = parseComparativeParams ( sys . argv ) <EOL> print ( '<STR_LIT>' ) <EOL> urlDict = loadImgUrl ( params [ '<STR_LIT>' ] , params [ '<STR_LIT>' ] ) <EOL> data = it . loadDataset ( params [ '<STR_LIT>' ] ) <EOL> if len ( params [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' ) <EOL> singleModel = [ params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ] <EOL> modelOutputs = ie . runAllModels ( <EOL> data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> data [ '<STR_LIT>' ] , <EOL> singleModel , <EOL> params [ '<STR_LIT>' ] , <EOL> params [ '<STR_LIT>' ] , <EOL> params [ '<STR_LIT>' ] ) <EOL> else : <EOL> modelOutputs = None <EOL> print ( '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> if not os . path . exists ( params [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( params [ '<STR_LIT>' ] ) <EOL> pages = renderHtml ( <EOL> data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , <EOL> data [ '<STR_LIT>' ] , <EOL> data [ '<STR_LIT>' ] , <EOL> urlDict , <EOL> topK = params [ '<STR_LIT>' ] , <EOL> modelOutputs = modelOutputs , <EOL> modelNames = getModelNames ( singleModel ) , <EOL> questionIds = np . arange ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . shape [ <NUM_LIT:0> ] ) ) <EOL> for i , page in enumerate ( pages ) : <EOL> with open ( os . path . join ( params [ '<STR_LIT>' ] , <EOL> htmlHyperLink % i ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( page ) </s>
