def renderSinglePage( inputData, targetData, questionIdict, ansIdict, urlDict, iPage=0, numPages=1, topK=10, modelOutputs=None, modelNames=None, questionIds=None): htmlList = [] htmlList.append('<html><head>\n') htmlList.append('<style>%s</style>' % renderCss()) htmlList.append('</head><body>\n') htmlList.append('<table>') imgPerRow = 4 htmlList.append(renderMenu(iPage, numPages)) for n in range(inputData.shape[0]): if np.mod(n, imgPerRow) == 0: htmlList.append('<tr>') imageId = inputData[n, 0, 0] imageFilename = urlDict[imageId - 1] question = it.decodeQuestion(inputData[n], questionIdict) qid = questionIds[n] if questionIds is not None else n topAnswers, topAnswerScores = pickTopAnswers( ansIdict, n, topK=topK, modelOutputs=modelOutputs, modelNames=modelNames, questionIds=questionIds) htmlList.append(renderSingleItem( imageFilename, qid, question, ansIdict[targetData[n, 0]], topAnswers=topAnswers, topAnswerScores=topAnswerScores, modelNames=modelNames)) if np.mod(n, imgPerRow) == imgPerRow - 1: htmlList.append('</tr>') htmlList.append('</table>') htmlList.append(renderMenu(iPage, numPages)) htmlList.append('</body></html>') return ''.join(htmlList)
def renderLatexSinglePage( inputData, targetData, questionIdict, ansIdict, urlDict, outputFolder, pictureFolder='img', topK=10, comments=None, caption=None, modelOutputs=None, modelNames=None, questionIds=None): result = [] result.append('\\begin{figure*}[ht!]\n') result.append('\\centering\\small\n') result.append('$\\begin{array}{p{5cm} p{5cm} p{5cm}}\n') imgPerRow = 3 imgFolder = os.path.join(outputFolder, pictureFolder) for n in range(inputData.shape[0]): # Download the images imageId = inputData[n, 0, 0] imageFilename = urlDict[imageId - 1] r = requests.get(imageFilename) qid = questionIds[n] if questionIds is not None else n if not os.path.exists(imgFolder): os.makedirs(imgFolder) with open(os.path.join(imgFolder, '%d.jpg' % qid), 'wb') as f: f.write(r.content) question = it.decodeQuestion(inputData[n], questionIdict) answer = ansIdict[targetData[n, 0]] topAnswers, topAnswerScores = \ pickTopAnswers( ansIdict, n, topK=topK, modelOutputs=modelOutputs, modelNames=modelNames) comment = comments[n] \ if comments is not None else None result.append( renderLatexSingleItem( qid, question, answer, pictureFolder=pictureFolder, comment=comment, topAnswers=topAnswers, topAnswerScores=topAnswerScores, modelNames=modelNames)) if np.mod(n, imgPerRow) == imgPerRow - 1: result.append('\\\\\n') if n != inputData.shape[0] - 1: result.append('\\noalign{\\smallskip}\\\ noalign{\\smallskip}\\noalign{\\smallskip}\n') else: result.append('&\n') result.append('\end{array}$\n') result.append('\caption{%s}\n' % caption if caption is not None else '') result.append('\end{figure*}\n') return ''.join(result)