Git Product home page Git Product logo

Comments (1)

xingyizhou avatar xingyizhou commented on September 15, 2024

Hi,

  1. We used LVIS v1.0. We mapped the labels back to v0.5 when doing test set evaluation.
  2. Please find my (un-cleaned) script below:
import argparse
import json
import os
from detectron2.structures import Boxes, BoxMode

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred', default='')
    parser.add_argument('--ann', default='')
    parser.add_argument('--convert_v05', default='')
    parser.add_argument('--minus1', action='store_true')
    parser.add_argument('--plus1', action='store_true')
    args = parser.parse_args()

    print('Loading', args.ann)
    data = json.load(open(args.ann, 'r'))
    print('Done')

    print('Loading', args.convert_v05)
    data_v05 = json.load(open(args.convert_v05, 'r'))
    cats_v05 = data_v05['categories']
    catid2synset = {x['id']: x['synset'] for x in data['categories']}
    synset2v05 = {x['synset']: x['id'] for x in cats_v05}
    catid2v05 = {x['id']: synset2v05[catid2synset[x['id']]] \
        for x in data['categories'] if catid2synset[x['id']] in synset2v05}

    print('Loading', args.pred)
    if args.pred.endswith('.pth'):
        import torch
        pred_data = torch.load(args.pred)
        preds = []
        # import pdb; pdb.set_trace()
        for x in pred_data:
            preds.extend(x['instances'])
    else:
        preds = json.load(open(args.pred, 'r'))
    print('Done')

    out_path = args.pred[:-5] + '_v05.json'
    ret = []
    for x in preds:
        cat_id = x['category_id']
        if args.minus1:
            cat_id = cat_id - 1
        if args.plus1:
            cat_id = cat_id + 1
        if cat_id in catid2v05:
            cat_id = catid2v05[cat_id]
        else:
            continue
        x['category_id'] = cat_id
        ret.append(x)
    print('Writing to', out_path)
    json.dump(ret, open(out_path, 'w'))

from gtr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.