-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add meta data link and script to convert lmdb
- Loading branch information
Showing
6 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import h5py | ||
import os | ||
import pdb | ||
import numpy as np | ||
import json | ||
import sys | ||
FIELDNAMES = ['image_id', 'image_w','image_h','num_boxes', 'boxes', 'features', 'cls_prob'] | ||
import csv | ||
import base64 | ||
import pickle | ||
import lmdb # install lmdb by "pip install lmdb" | ||
|
||
csv.field_size_limit(sys.maxsize) | ||
|
||
count = 0 | ||
num_file = 1 | ||
name = '/srv/share2/jlu347/bottom-up-attention/feature/flickr30k/flickr30k_test_resnet101_faster_rcnn_genome.tsv.%d' | ||
infiles = [name % i for i in range(num_file)] | ||
# infiles.append('/srv/share2/jlu347/bottom-up-attention/feature/coco/coco_val_resnet101_faster_rcnn_genome.tsv.0') | ||
|
||
save_path = os.path.join('flickr30k_test_resnet101_faster_rcnn_genome1.lmdb') | ||
env = lmdb.open(save_path, map_size=1099511627776) | ||
|
||
id_list = [] | ||
with env.begin(write=True) as txn: | ||
for infile in infiles: | ||
with open(infile) as tsv_in_file: | ||
reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames = FIELDNAMES) | ||
for item in reader: | ||
img_id = str(item['image_id']).encode() | ||
id_list.append(img_id) | ||
txn.put(img_id, pickle.dumps(item)) | ||
if count % 1000 == 0: | ||
print(count) | ||
count += 1 | ||
txn.put('keys'.encode(), pickle.dumps(id_list)) | ||
|
||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import h5py | ||
import os | ||
import pdb | ||
import numpy as np | ||
import json | ||
import sys | ||
FIELDNAMES = ['image_id', 'image_w','image_h','num_boxes', 'boxes', 'features', 'cls_prob'] | ||
import csv | ||
import base64 | ||
csv.field_size_limit(sys.maxsize) | ||
import sys | ||
import pickle | ||
import lmdb # install lmdb by "pip install lmdb" | ||
|
||
count = 0 | ||
num_file = 1 | ||
name = '/srv/share2/jlu347/bottom-up-attention/feature/refcoco_unc/refcoco+_unc_resnet101_faster_rcnn_genome.tsv.%d' | ||
infiles = [name % i for i in range(num_file)] | ||
|
||
save_path = os.path.join('refcoco+.lmdb') | ||
env = lmdb.open(save_path, map_size=1099511627776) | ||
|
||
id_list = [] | ||
with env.begin(write=True) as txn: | ||
for infile in infiles: | ||
with open(infile) as tsv_in_file: | ||
reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames = FIELDNAMES) | ||
for item in reader: | ||
|
||
img_id = str(item['image_id']).encode() | ||
id_list.append(img_id) | ||
txn.put(img_id, pickle.dumps(item)) | ||
|
||
if count % 1000 == 0: | ||
print(count) | ||
count += 1 | ||
txn.put('keys'.encode(), pickle.dumps(id_list)) | ||
|
||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import h5py | ||
import os | ||
import pdb | ||
import numpy as np | ||
import json | ||
import sys | ||
FIELDNAMES = ['image_id', 'image_w','image_h','num_boxes', 'boxes', 'features', 'cls_prob'] | ||
import csv | ||
import base64 | ||
csv.field_size_limit(sys.maxsize) | ||
import sys | ||
import pickle | ||
import lmdb # install lmdb by "pip install lmdb" | ||
|
||
count = 0 | ||
num_file = 1 | ||
name = '/srv/share2/jlu347/bottom-up-attention/feature/refcoco_unc/refcoco+_unc_gt_resnet101_faster_rcnn_genome.tsv.%d' | ||
infiles = [name % i for i in range(num_file)] | ||
|
||
save_path = os.path.join('refcoco+_gt.lmdb') | ||
env = lmdb.open(save_path, map_size=1099511627776) | ||
|
||
id_list = [] | ||
with env.begin(write=True) as txn: | ||
for infile in infiles: | ||
with open(infile) as tsv_in_file: | ||
reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames = FIELDNAMES) | ||
for item in reader: | ||
|
||
img_id = str(item['image_id']).encode() | ||
id_list.append(img_id) | ||
txn.put(img_id, pickle.dumps(item)) | ||
|
||
if count % 1000 == 0: | ||
print(count) | ||
count += 1 | ||
txn.put('keys'.encode(), pickle.dumps(id_list)) | ||
|
||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import h5py | ||
import os | ||
import pdb | ||
import numpy as np | ||
import json | ||
import sys | ||
FIELDNAMES = ['image_id', 'image_w','image_h','num_boxes', 'boxes', 'features'] | ||
import csv | ||
import base64 | ||
import pickle | ||
import lmdb # install lmdb by "pip install lmdb" | ||
|
||
csv.field_size_limit(sys.maxsize) | ||
|
||
name = '/srv/share2/jlu347/bottom-up-attention/feature/coco/test2015/test2015_resnet101_faster_rcnn_genome.tsv' | ||
infiles = [name] | ||
|
||
save_path = os.path.join('coco_test_resnet101_faster_rcnn_genome.lmdb') | ||
env = lmdb.open(save_path, map_size=1099511627776) | ||
|
||
id_list = [] | ||
count = 0 | ||
with env.begin(write=True) as txn: | ||
for infile in infiles: | ||
with open(infile) as tsv_in_file: | ||
reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames = FIELDNAMES) | ||
for item in reader: | ||
img_id = str(item['image_id']).encode() | ||
id_list.append(img_id) | ||
txn.put(img_id, pickle.dumps(item)) | ||
if count % 1000 == 0: | ||
print(count) | ||
count += 1 | ||
txn.put('keys'.encode(), pickle.dumps(id_list)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import h5py | ||
import os | ||
import pdb | ||
import numpy as np | ||
import json | ||
import sys | ||
FIELDNAMES = ['image_id', 'image_w','image_h','num_boxes', 'boxes', 'features'] | ||
import csv | ||
import base64 | ||
import pickle | ||
import lmdb # install lmdb by "pip install lmdb" | ||
|
||
csv.field_size_limit(sys.maxsize) | ||
|
||
count = 0 | ||
infiles = [] | ||
|
||
path = '/srv/share2/jlu347/bottom-up-attention/feature/coco/trainval/' | ||
infiles.append(path + 'karpathy_train_resnet101_faster_rcnn_genome.tsv.0') | ||
infiles.append(path + 'karpathy_train_resnet101_faster_rcnn_genome.tsv.1') | ||
infiles.append(path + 'karpathy_val_resnet101_faster_rcnn_genome.tsv') | ||
infiles.append(path + 'karpathy_test_resnet101_faster_rcnn_genome.tsv') | ||
|
||
save_path = os.path.join('coco_trainval_resnet101_faster_rcnn_genome.lmdb') | ||
env = lmdb.open(save_path, map_size=1099511627776) | ||
|
||
id_list = [] | ||
with env.begin(write=True) as txn: | ||
for infile in infiles: | ||
with open(infile) as tsv_in_file: | ||
reader = csv.DictReader(tsv_in_file, delimiter='\t', fieldnames = FIELDNAMES) | ||
for item in reader: | ||
img_id = str(item['image_id']).encode() | ||
id_list.append(img_id) | ||
txn.put(img_id, pickle.dumps(item)) | ||
if count % 1000 == 0: | ||
print(count) | ||
count += 1 | ||
txn.put('keys'.encode(), pickle.dumps(id_list)) | ||
|
||
print(count) |