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

Create parent dir, when serializing Sim(2), if it doesnt exist #252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions argoverse/utils/sim2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import json
import os
from pathlib import Path
from typing import Union

import numpy as np
Expand Down Expand Up @@ -153,6 +154,9 @@ def save_as_json(self, save_fpath: _PathLike) -> None:
Args:
save_fpath: path to where json file should be saved
"""
if not Path(save_fpath).exists():
Copy link
Contributor

@benjaminrwilson benjaminrwilson Jul 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jlambert,

Thanks for adding this. I notice that this function calls save_json_dict. Do you think that it might be convenient if we move directory creation into that function?

My thought is this: https://github.com/argoai/argoverse-api/blob/9ad7251e863590603c3f6064a45830dabd3a15e2/argoverse/utils/json_utils.py#L32 could be modified as:

json_fpath = Path(json_fpath)
json_fpath.parent.mkdir(parents=True, exist_ok=True)
with json_fpath.open("w") as f:
    json.dump(dictionary, f)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this.

os.makedirs(Path(save_fpath).parent, exist_ok=True)

dict_for_serialization = {
"R": self.rotation.flatten().tolist(),
"t": self.translation.flatten().tolist(),
Expand Down