Visitar URL original
auxfun_multianimal migrate to Path in Load and Save MA data · DeepLabCut/DeepLabCut@849644a · GitHub
Skip to content

Commit 849644a

Browse files
committed
auxfun_multianimal migrate to Path in Load and Save MA data
1 parent 5daaade commit 849644a

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎deeplabcut/utils/auxfun_multianimal.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,29 @@ def SaveFullMultiAnimalData(data, metadata, dataname, suffix="_full"):
189189
"""Save predicted data as h5 file and metadata as pickle file; created by
190190
predict_videos.py.
191191
"""
192-
data_path = dataname.split(".h5")[0] + suffix + ".pickle"
193-
metadata_path = dataname.split(".h5")[0] + "_meta.pickle"
192+
dataname = Path(dataname)
193+
data_path = dataname.with_name(dataname.stem + suffix + ".pickle")
194+
metadata_path = dataname.with_name(dataname.stem + "_meta.pickle")
194195

195-
with Path(data_path).open("wb") as f:
196+
data_path.parent.mkdir(parents=True, exist_ok=True)
197+
with data_path.open("wb") as f:
196198
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
197-
with Path(metadata_path).open("wb") as f:
199+
with metadata_path.open("wb") as f:
198200
pickle.dump(metadata, f, pickle.HIGHEST_PROTOCOL)
199201
return data_path, metadata_path
200202

201203

202204
def LoadFullMultiAnimalData(dataname):
203205
"""Load predicted data and metadata from pickle files created by predict_videos.py."""
204-
data_file = dataname.split(".h5")[0] + "_full.pickle"
206+
dataname = Path(dataname)
207+
data_file = dataname.with_name(dataname.stem + "_full.pickle")
208+
metadata_file = dataname.with_name(dataname.stem + "_meta.pickle")
205209
try:
206-
with Path(data_file).open("rb") as handle:
210+
with data_file.open("rb") as handle:
207211
data = pickle.load(handle)
208212
except (pickle.UnpicklingError, FileNotFoundError):
209213
data = shelve.open(data_file, flag="r")
210-
with Path(data_file.replace("_full.", "_meta.")).open("rb") as handle:
214+
with metadata_file.open("rb") as handle:
211215
metadata = pickle.load(handle)
212216
return data, metadata
213217

0 commit comments

Comments
 (0)