Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Bugs, Loader.py not working? #4

Closed
SinghJasdeep opened this issue Feb 27, 2018 · 5 comments
Closed

Possible Bugs, Loader.py not working? #4

SinghJasdeep opened this issue Feb 27, 2018 · 5 comments

Comments

@SinghJasdeep
Copy link

Hello we are using you code to preprocess the data and build a few models on top of and are running into some bugs. Don't know why this is not working for us.

https://github.com/SinghJasdeep/CS230-CS224N-VQA

Mainly issues in the loader.py file:

i_batch.append(self.i_feat[iid]) is actually a dictionary not an array of size (36,2048)?

Your help would be greatly appreciated Mark.

@SinghJasdeep
Copy link
Author

I think the error is possibly how we are saving coco_features.npy

Could you please post the version of read_tsv.py you use.

We are using this:

import base64
import numpy as np
import csv
import sys
import zlib
import time
import mmap

csv.field_size_limit(sys.maxsize)

FIELDNAMES = ['image_id', 'image_w', 'image_h', 'num_boxes', 'boxes', 'features']
infile = '/home/vhying/Downloads/CS230-CS224N-VQA/data/trainval_36/trainval_resnet101_faster_rcnn_genome_36.tsv'
outfile = '/home/vhying/Downloads/CS230-CS224N-VQA/data/coco_features.npy'

if name == 'main':

# Verify we can read a tsv
in_data = {}
with open(infile, "r+b") as tsv_in_file:
    reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames=FIELDNAMES)
    for item in reader:
        item['image_id'] = int(item['image_id'])
        item['image_h'] = int(item['image_h'])
        item['image_w'] = int(item['image_w'])
        item['num_boxes'] = int(item['num_boxes'])
        for field in ['boxes', 'features']:
            item[field] = np.frombuffer(base64.decodestring(item[field]),
                                        dtype=np.float32).reshape((item['num_boxes'], -1))
        in_data[item['image_id']] = item

    with open(outfile, "wb") as Out_f:
        np.save(outfile, in_data)

@SinghJasdeep
Copy link
Author

Issue Solved

@kevgeo
Copy link

kevgeo commented Jun 14, 2018

Hi @SinghJasdeep , even I am facing a similar problem. How did you resolve the issue? Could you share your version of read_tsv.py? That would be great.

@markdtw
Copy link
Owner

markdtw commented Jun 23, 2018

Hi, sorry I really should've put my read_tsv.py here

it's like this

...
    in_data = {}
...
        for item in reader:
            data = {}
            data['image_id'] = int(item['image_id'])
            for field in ['features']:
                data[field] = np.frombuffer(base64.decodestring(item[field]),
                    dtype=np.float32).reshape((36, -1))
            in_data[data['image_id']] = data['features']

        np.save('purefeat.npy', in_data)
...

@kevgeo
Copy link

kevgeo commented Jun 24, 2018

@markdtw Thank you so much for the code :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants