Exemplo n.º 1
0
def saveResultPagePool(loadPath):
    # image, task, converation, GT, pred
    page = HTML(4);
    page.setTitle(['Pool', 'GT', 'Conversation', 'Pred']);

    savePath = loadPath.replace('json', 'html').replace('chatlog', 'chatpage');

    with open(loadPath, 'r') as fileId: talk = json.load(fileId);

    maps = {};
    cleaner = lambda x: maps[x] if x in maps else x;

    for datum in talk:
        datum['pool'] = [[cleaner(jj) for jj in ii] \
                                        for ii in datum['pool']];
        datum['gt'] = [cleaner(ii) for ii in datum['gt']];
        datum['pred'] = [cleaner(ii) for ii in datum['pred']];
        datum['chat'] = [cleaner(ii) for ii in datum['chat']];

        row = ['\n'.join([', '.join(ii) for ii in datum['pool']])];
        row.append(', '.join(datum['gt']));

        # add chat
        chat = 'Q1 : %3s \tA1: %s ' % (datum['chat'][0], datum['chat'][1]);
        if len(datum['chat']) > 3:
            chat += '\tQ2 : %3s \t A2: %s' % (datum['chat'][2], datum['chat'][3]);
        row.append(chat)

        # add GT and pred
        row.append(', '.join(datum['pred']));
        page.addRow(row);

    # render and save page
    page.savePage(savePath);
Exemplo n.º 2
0
def saveResultPage(loadPath):
    # image, task, converation, GT, pred
    page = HTML(5);
    page.setTitle(['Image', 'Task', 'Conversation', 'GT', 'Pred']);

    savePath = loadPath.replace('json', 'html').replace('chatlog', 'chatpage');

    with open(loadPath, 'r') as fileId: talk = json.load(fileId);

    maps = {'rectangle':'triangle', 'rhombus':'star', 'cyan':'purple'};
            #'A':'  I', 'B':' II', 'C':'III'};
    cleaner = lambda x: maps[x] if x in maps else x;

    for datum in talk:
        datum['image'] = [cleaner(ii) for ii in datum['image']];
        datum['gt'] = [cleaner(ii) for ii in datum['gt']];
        datum['pred'] = [cleaner(ii) for ii in datum['pred']];
        datum['chat'] = [cleaner(ii) for ii in datum['chat']];

        row = [', '.join(datum['image']), ', '.join(datum['task'])];

        # add chat
        chat = 'Q1 : %3s \tA1: %s ' % (datum['chat'][0], datum['chat'][1]);
        if len(datum['chat']) > 3:
            chat += '\tQ2 : %3s \t A2: %s' % (datum['chat'][2], datum['chat'][3]);
        row.append(chat)

        # add GT and pred
        row.extend([', '.join(datum['gt']), ', '.join(datum['pred'])]);

        page.addRow(row);

    # render and save page
    page.savePage(savePath);
Exemplo n.º 3
0
def visualizeBatch(dataloader):
    # local alias
    dl = dataloader

    # get batch
    batch = dl.getTrainBatch()
    # create a html page
    page = HTML(4)
    imgPath = 'train2014/COCO_train2014_%012d.jpg'

    # Get the unique image locations
    imgSum = batch['image'].sum(1).numpy()
    curSum = imgSum[0]
    count = 0
    for ii in xrange(imgSum.shape[0]):
        if curSum != imgSum[ii]: count += 1
        curSum = imgSum[ii]

        # New row
        # add image, set, pos, neg examples
        row = [page.linkImage(imgPath % batch['imageId'][count])]
        setWords = [dl.ind2word[jj] for jj in list(batch['set'][ii])]
        row.append(', '.join(setWords))

        row.append(dl.ind2word[batch['pos'][ii, 0]])
        row.append(dl.ind2word[batch['neg'][ii, 0]])

        # add the row
        page.addRow(row)

    # render page
    page.savePage('visualize_batch.html')
Exemplo n.º 4
0
def savePredictedTags(scores, groundTruth, dataloader, topN=20):
    # local aliases
    gtLabels, imgIds = groundTruth['gtLabels'], groundTruth['imageId']

    # Create a page with 3 columns
    page = HTML(3)
    page.setTitle(['Image', 'Ground Truth', 'Predicted Tags'])
    imgPath = 'val2014/COCO_val2014_%012d.jpg'
    numImgs = 100

    for ii in xrange(numImgs):
        rowContent = [page.linkImage(imgPath % imgIds[ii])]
        #data = dataloader.getIndexInstance(ii, 'test');
        # set
        #setData = data[:dataloader.evalSize];
        #setWords = [dataloader.ind2word[str(setData[jj])] \
        #                for jj in xrange(setData.size(0))];
        #rowContent.append('\n'.join(setWords));

        # gt words, scores, ranks
        #gtData = data[dataloader.evalSize:];
        gtWords = [dataloader.ind2word[jj] for jj in gtLabels[ii]]
        rowContent.append('\n'.join(gtWords))

        # Get the predicted tags
        imgScore = scores[ii, :]
        predTags = imgScore.argsort()[-topN:][::-1]
        tags = [dataloader.ind2word[jj] for jj in predTags]
        rowContent.append('\n'.join(tags))

        page.addRow(rowContent)

    # render page and save
    page.savePage('img_tags_espgame.html')
Exemplo n.º 5
0
def saveTopWords(result, dataloader, dtype, topN=10):
    # local aliases
    _, scores, gtRanks = result

    # Create a page with 3 columns
    page = HTML(3)
    page.setTitle(['Set', 'Ground Truth', 'Top Words'])

    numInst = dataloader.numInst[dtype]
    for ii in xrange(numInst):
        rowContent = []
        # row

        data = dataloader.getIndexInstance(ii, dtype)
        # set
        setData = data[:dataloader.evalSize]
        setWords = [dataloader.ind2word[str(setData[jj])] \
                        for jj in xrange(setData.size(0))]
        rowContent.append('\n'.join(setWords))

        # gt words, scores, ranks
        gtData = data[dataloader.evalSize:]
        gtWords = [dataloader.ind2word[str(gtData[jj])] \
                        for jj in xrange(gtData.size(0))]
        gtInfo = ['%s \t(%f)\t[%d]' \
                    % (gtWords[jj], scores[ii, gtData[jj]], gtRanks[ii, jj])\
                    for jj in xrange(gtData.size(0))]
        rowContent.append('\n'.join(gtInfo))

        # topN words, scores, ranks
        argScores = scores[ii].numpy()
        topData = argScores.argsort()[-topN:][::-1]
        topWords = [dataloader.ind2word[str(topData[jj])] \
                        for jj in xrange(topData.shape[0])]
        topInfo = ['%s \t(%f)\t[%d]' \
                    % (topWords[jj], scores[ii, topData[jj]], jj)\
                    for jj in xrange(topData.shape[0])]
        rowContent.append('\n'.join(topInfo))

        page.addRow(rowContent)

    # render page and save
    page.savePage(dataloader.resultPath)