Code Monkey home page Code Monkey logo

Comments (2)

Maelic avatar Maelic commented on June 20, 2024

+1

from reltr.

yrcong avatar yrcong commented on June 20, 2024

We create the .json files in COCO format.

You can refer to the code we used:

from dataloaders.visual_genome_coco import VGDataLoader, VG
import numpy as np
from torch import optim
import torch
from PIL import Image
import time
import json

train, val, test = VG.splits(num_val_im=5000, filter_duplicate_rels=True,
                             use_proposals=False,
                            filter_non_overlap=True)
rel_categories = train.ind_to_predicates

counter = 0

images = []
annotations = []
categories = []
train_rel = {}

for idx, i in enumerate(train.ind_to_classes):
    if idx == 0:
        continue
    else:
        category = {'supercategory': i, 'id': idx, 'name': i}
        categories.append(category)


train_triplets = np.zeros([151,151,51]) #sub obj rel

for idx, i in enumerate(train.filenames):
    file_name = i.split('/')[-1]
    w, h = Image.open(i).size
    image_id = int(i.split('/')[-1].split('.')[0])
    image = {'file_name': file_name,
              'height': h,
              'width': w,
              'id': image_id}
    images.append(image)
    train_rel[image_id] = [triplet.tolist() for triplet in np.unique(train.relationships[idx],axis=0)]

    for idx2, j in enumerate(train.gt_boxes[idx]):
        j = j*max(w, h)/1024
        bbox = [int(j[0]), int(j[1]), int(j[2] - j[0] + 1), int(j[3] - j[1] + 1)]
        area = int((j[3] - j[1] + 1) * (j[2] - j[0] + 1))
        anno_id = counter
        counter = counter + 1
        annotation = {'segmentation': None,
                      'area': area,
                      'bbox': bbox,
                      'iscrowd': 0,
                      'image_id': image_id,
                      'id': anno_id,
                      'category_id': int(train.gt_classes[idx][idx2])}
        annotations.append(annotation)

    for relation in train_rel[image_id]:
        train_triplets[train.gt_classes[idx][relation[0]], train.gt_classes[idx][relation[1]], relation[2]] += 1


train_database = {'images': images,
                  'annotations': annotations,
                  'categories': categories}

from reltr.

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.