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

Add cats to hierarchy #35

Merged
merged 8 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion bddl/data_generation/get_hierarchy_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@
problem that each synset can have multiple hypernyms
'''
import json
import pandas as pd
import pathlib
from nltk.corpus import wordnet as wn

HIERARCHY_OUTPUT_FN = pathlib.Path(__file__).parents[1] / "generated_data" / "output_hierarchy.json"
CATEGORY_MAPPING_FN = pathlib.Path(__file__).parents[1] / "generated_data" / "category_mapping.csv"


def add_igibson_objects(node, synset_to_cat):
'''
Go through the hierarchy and add the words associated with the synsets as attributes.
'''
# categories =
if node["name"] in synset_to_cat:
node["igibson_categories"] = sorted(synset_to_cat[node["name"]])

if "children" in node:
for child_node in node["children"]:
add_igibson_objects(child_node, synset_to_cat)


def add_path(path, hierarchy):
if not path:
return
# print("Path is nontrivial")
synset = path[-1]
if "children" not in hierarchy:
hierarchy["children"] = []
Expand Down Expand Up @@ -56,6 +70,16 @@ def get_hierarchy(syn_prop_dict):
for path in paths:
add_path(path[:-1], hierarchy)

synset_to_cat_raw = pd.read_csv(CATEGORY_MAPPING_FN)[["category", "synset"]].to_dict(orient="records")
synset_to_cat = {}
for rec in synset_to_cat_raw:
syn, cat = rec["synset"], rec["category"]
if syn in synset_to_cat:
synset_to_cat[syn].append(cat)
else:
synset_to_cat[syn] = [cat]
add_igibson_objects(hierarchy, synset_to_cat)

with open(HIERARCHY_OUTPUT_FN, "w") as f:
json.dump(hierarchy, f, indent=2)
return hierarchy
Expand Down
3 changes: 2 additions & 1 deletion bddl/data_generation/get_syn_prop_annots_canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"nonSubstance": None,
"sceneObject": None,
"drapeable": None,
"physicalSubstance": None
"physicalSubstance": None,
"mixingTool": None,
}

########### GET INPUT CANONICALS ###########
Expand Down
21 changes: 0 additions & 21 deletions bddl/data_generation/process_prop_param_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

def add_cookable_params(propagated_canonical, props_to_syns, synset_nonexistent, param_but_no_prop, prop_but_no_param):
# Cooking
print("COOKING")
print()
cooking_params = pd.read_csv(PROP_PARAM_ANNOTS_DIR / "cooking.csv")
cooking_params = cooking_params[cooking_params["require_cookable/overcookable_temperature"] == True][["synset", "value_cook(C)", "value_overcook(C)"]]
for i, [synset, cook_temp, overcook_temp] in cooking_params.iterrows():
Expand All @@ -24,15 +22,12 @@ def add_cookable_params(propagated_canonical, props_to_syns, synset_nonexistent,
prop_but_no_param["cookable"].append(synset)
continue
if synset not in propagated_canonical:
# print(f"{synset} not in syn-to-prop file.")
synset_nonexistent["cookable"].append(synset)
continue
if "cookable" not in propagated_canonical[synset]:
# print(f"{synset} is not cookable but has cookable property param annotation.")
param_but_no_prop["cookable"].append(synset)
continue
propagated_canonical[synset]["cookable"]["cook_temperature"] = float(cook_temp)
# syns_to_props[synset]["cookable"]["overcook_temperature"] = float(overcook_temp)

for cookable_synset in props_to_syns["cookable"]:
try:
Expand All @@ -41,15 +36,11 @@ def add_cookable_params(propagated_canonical, props_to_syns, synset_nonexistent,
continue
if "cook_temperature" not in propagated_canonical[cookable_synset]["cookable"] and \
all(syn.name in propagated_canonical for syn in wn.synset(cookable_synset).hyponyms()):
# print(f"{cookable_synset} is annotated as cookable but does not have cookable property param annotation")
prop_but_no_param["cookable"].append(cookable_synset)


def add_coldsource_params(propagated_canonical, props_to_syns, synset_nonexistent, param_but_no_prop, prop_but_no_param):
# coldSource
print(); print()
print("COLDSOURCE")
print()
coldSource_params = pd.read_csv(PROP_PARAM_ANNOTS_DIR / "coldSource.csv")
coldSource_params = coldSource_params[coldSource_params["require_coldsource_temperature"] == True][["synset", "value(C)"]]
for i, [synset, temp] in coldSource_params.iterrows():
Expand All @@ -62,11 +53,9 @@ def add_coldsource_params(propagated_canonical, props_to_syns, synset_nonexisten
prop_but_no_param["coldSource"].append(synset)
continue
if synset not in propagated_canonical:
# print(f"{synset} not in syn-to-prop file.")
synset_nonexistent["coldSource"].append(synset)
continue
if "coldSource" not in propagated_canonical[synset]:
# print(f"{synset} is not coldSource but has coldSource property param annotation.")
param_but_no_prop["coldSource"].append(synset)
continue
propagated_canonical[synset]["coldSource"]["temperature"] = float(temp)
Expand All @@ -79,36 +68,27 @@ def add_coldsource_params(propagated_canonical, props_to_syns, synset_nonexisten
continue
if "temperature" not in propagated_canonical[coldSource_synset]["coldSource"] and \
all(syn.name in propagated_canonical for syn in wn.synset(coldSource_synset).hyponyms()):
# print(f"{coldSource_synset} is annotated as coldSource_synset but does not have coldSource_synset property param annotation")
prop_but_no_param["coldSource"].append(coldSource_synset)


def add_heatsource_params(propagated_canonical, props_to_syns, synset_nonexistent, param_but_no_prop, prop_but_no_param):
# heatSource
print(); print()
print("HEATSOURCE")
print()
heatSource_params = pd.read_csv(PROP_PARAM_ANNOTS_DIR / "heatSource.csv")

heatSource_params = heatSource_params[heatSource_params["require_heatsource_temperature"] == True][["synset", "value(C)"]]
# print(heatSource_params)
# import sys; sys.exit()
for i, [synset, temp] in heatSource_params.iterrows():
try:
float(temp)
except ValueError:
prop_but_no_param["heatSource"].append(synset)
continue
if pd.isna(float(temp)):
print(synset)
prop_but_no_param["heatSource"].append(synset)
continue
if synset not in propagated_canonical:
# print(f"{synset} not in syn-to-prop file.")
synset_nonexistent["heatSource"].append(synset)
continue
if "heatSource" not in propagated_canonical[synset]:
# print(f"{synset} is not heatSource but has heatSource property param annotation.")
param_but_no_prop["heatSource"].append(synset)
continue
propagated_canonical[synset]["heatSource"]["temperature"] = float(temp)
Expand All @@ -121,7 +101,6 @@ def add_heatsource_params(propagated_canonical, props_to_syns, synset_nonexisten
continue
if "temperature" not in propagated_canonical[heatSource_synset]["heatSource"] and \
all(syn.name in propagated_canonical for syn in wn.synset(heatSource_synset).hyponyms()):
# print(f"{heatSource_synset} is annotated as heatSource but does not have heatSource property param annotation")
prop_but_no_param["heatSource"].append(heatSource_synset)

# TODO check if that everything that SHOULD have a certain parameter annotation DOES have it
Expand Down
1 change: 1 addition & 0 deletions bddl/data_generation/prop_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"particleSource",
"needsOrientation",
"waterCook",
"mixingTool",
"sceneObject"
]
Loading