Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GenVQA
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vision
GenVQA
Commits
f88c7cd9
Commit
f88c7cd9
authored
8 years ago
by
tgupta6
Browse files
Options
Downloads
Patches
Plain Diff
add_hypernyms fun in visual_genome_parser
parent
7e43c711
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
visual_genome_parser.py
+38
-2
38 additions, 2 deletions
visual_genome_parser.py
with
38 additions
and
2 deletions
visual_genome_parser.py
+
38
−
2
View file @
f88c7cd9
...
...
@@ -29,6 +29,8 @@ _raw_attribute_labels = 'raw_attribute_labels.json'
_object_labels
=
'
object_labels.json
'
_attribute_labels
=
'
attribute_labels.json
'
_regions_with_labels
=
'
region_with_labels.json
'
_regions_with_hypernym_labels
=
'
region_with_hypernym_labels.json
'
_object_labels_to_hypernyms
=
'
object_labels_to_hypernyms.json
'
_unknown_token
=
'
UNK
'
_unopenable_images
=
'
unopenable_images.json
'
_vocab
=
'
vocab.json
'
...
...
@@ -528,6 +530,37 @@ def create_genome_to_vqa_map():
return
map
def
add_hypernyms
(
in_regions_json
,
out_regions_json
,
labels_to_hypernyms_json
):
in_regions_json_filename
=
os
.
path
.
join
(
_outdir
,
in_regions_json
)
print
'
Reading file {} ...
'
.
format
(
in_regions_json_filename
)
with
open
(
in_regions_json_filename
,
'
r
'
)
as
file
:
regions_data
=
ujson
.
load
(
file
)
labels_to_hypernyms_json_filename
=
os
.
path
.
join
(
_outdir
,
labels_to_hypernyms_json
)
print
'
Reading file {} ...
'
.
format
(
labels_to_hypernyms_json_filename
)
with
open
(
labels_to_hypernyms_json_filename
,
'
r
'
)
as
file
:
hypernyms
=
ujson
.
load
(
file
)
print
len
(
hypernyms
)
for
region_id
,
region_info
in
regions_data
.
items
():
object_names
=
set
(
region_info
[
'
object_names
'
])
for
label
in
region_info
[
'
object_names
'
]:
if
label
in
hypernyms
:
object_names
.
update
(
hypernyms
[
label
])
regions_data
[
region_id
][
'
object_names
'
]
=
list
(
object_names
)
out_regions_json_filename
=
os
.
path
.
join
(
_outdir
,
out_regions_json
)
print
'
Writing file {} ...
'
.
format
(
out_regions_json_filename
)
with
open
(
out_regions_json_filename
,
'
w
'
)
as
file
:
ujson
.
dump
(
regions_data
,
file
,
sort_keys
=
True
,
indent
=
4
)
def
partition_region_ids
(
vqa_train_subset_qids_json
,
...
...
@@ -668,7 +701,10 @@ if __name__=='__main__':
# _vqa_train_anno,
# _vqa_val_anno,
# _genome_train_subset_region_ids)
generate_md5hash
()
add_hypernyms
(
_regions_with_labels
,
_regions_with_hypernym_labels
,
_object_labels_to_hypernyms
)
# generate_md5hash()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment