Skip to content

Commit

Permalink
feat: update migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
hayato-m126 committed Jul 27, 2024
1 parent af6f993 commit a2d94e4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 73 deletions.

This file was deleted.

51 changes: 51 additions & 0 deletions log_evaluator_migration_tool/log_evaluator_migration_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,56 @@ def convert_scenario(scenario_path: Path) -> None:
scenario_file.close()


def update_annotationless_1_to_2(scenario_path: Path) -> None:
scenario_file = scenario_path.open("r+")
yaml_obj = yaml.safe_load(scenario_file)

if yaml_obj["Evaluation"]["UseCaseName"] != "annotationless_perception":
scenario_file.close()
return

if (
yaml_obj["ScenarioFormatVersion"] != "3.0.0"
or yaml_obj["Evaluation"]["UseCaseFormatVersion"] != "1.0.0"
):
print(f"{scenario_path} does not match format version") # noqa
scenario_file.close()
return

yaml_obj["Evaluation"]["UseCaseFormatVersion"] = "2.0.0"

class_cond = yaml_obj["Evaluation"]["Conditions"]["ClassConditions"]

for k, v in class_cond.items():
pass_range_dict = expand_pass_range(v["PassRange"])
for name, value in v["Threshold"].items():
threshold_values = {}
for m_k, m_v in value.items():
threshold_values[m_k] = {
"lower": m_v * pass_range_dict[m_k][0],
"upper": m_v * pass_range_dict[m_k][1],
}
class_cond[k] |= {name: threshold_values}
class_cond[k].pop("Threshold")
class_cond[k].pop("PassRange")

# 既存の内容を消す
scenario_file.seek(0)
scenario_file.truncate()

# 更新済みの内容を書き込む
yaml.safe_dump(yaml_obj, scenario_file, sort_keys=False)
scenario_file.close()


def expand_pass_range(pass_range_dict: dict) -> dict:
rtn_dict = {}
for k, v in pass_range_dict.items():
s_lower, s_upper = v.split("-")
rtn_dict[k] = [float(s_lower), float(s_upper)]
return rtn_dict


def move_dataset_and_map(scenario_path: Path) -> None:
scenario_file = scenario_path.open("r+")
yaml_obj = yaml.safe_load(scenario_file) # scenario file is 3.0.0 format
Expand Down Expand Up @@ -119,6 +169,7 @@ def main() -> None:
for scenario_path in sorted(scenario_paths):
print(f"convert {scenario_path}") # noqa
convert_scenario(scenario_path)
update_annotationless_1_to_2(scenario_path)
move_dataset_and_map(scenario_path)


Expand Down
1 change: 0 additions & 1 deletion sample/annotationless_perception/scenario.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ Evaluation:
Datasets:
- sample_dataset:
VehicleId: default

0 comments on commit a2d94e4

Please sign in to comment.