Skip to content

Commit 0091038

Browse files
Merge pull request #249 from stanfordnmbl/batchDownloadData_pose-pickle
Batch download data pose pickle
2 parents c98e70d + 0f6bd85 commit 0091038

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

Examples/batchDownloadData.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@
5454

5555
# Batch download.
5656
for session_id in session_ids:
57+
print(f'Downloading session id {session_id}')
5758
utils.downloadAndZipSession(session_id,justDownload=True,data_dir=downloadFolder,
58-
useSubjectNameFolder=useSubjectIdentifierAsFolderName)
59+
useSubjectNameFolder=useSubjectIdentifierAsFolderName,
60+
include_pose_pickles=False)

utils.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ def postMotionData(trial_id,session_path,trial_name=None,isNeutral=False,
817817

818818
return
819819

820-
def getMotionData(trial_id,session_path,simplePath=False):
820+
def getMotionData(trial_id, session_path,
821+
simplePath=False,
822+
include_pose_pickles=False):
821823
trial = getTrialJson(trial_id)
822824
trial_name = trial['name']
823825
resultTags = [res['tag'] for res in trial['results']]
@@ -835,14 +837,44 @@ def getMotionData(trial_id,session_path,simplePath=False):
835837
# get IK data
836838
if 'ik_results' in resultTags:
837839
ikFolder = os.path.join(session_path,'OpenSimData','Kinematics')
838-
if simplePath:
839-
ikFolder = os.path.join(session_path,'OpenSimData','Kinematics')
840840
ikPath = os.path.join(ikFolder,trial_name + '.mot')
841841
os.makedirs(ikFolder, exist_ok=True)
842842
ikURL = trial['results'][resultTags.index('ik_results')]['media']
843843
download_file(ikURL,ikPath)
844844

845-
# TODO will want to get pose pickles eventually, once those are processed elsewhere
845+
# get pose pickles
846+
if include_pose_pickles and 'pose_pickle' in resultTags:
847+
# metadata needed for pose pickle folder naming
848+
main_settings = getMainSettings(trial_id)
849+
poseDetector = main_settings['poseDetector']
850+
851+
# sometimes mmpose is used instead of hrnet
852+
if poseDetector.lower() == 'mmpose':
853+
poseDetector = 'hrnet'
854+
855+
# infer pose detection from main settings to get correct folders
856+
if poseDetector.lower() == 'openpose':
857+
getPosePickles(trial_id, session_path,
858+
poseDetector=poseDetector,
859+
resolutionPoseDetection=main_settings['resolutionPoseDetection'])
860+
861+
elif poseDetector.lower() == 'hrnet':
862+
# shared check with `checkAndGetPosePickles()`
863+
if 'bbox_thr' in main_settings:
864+
bbox_thr = main_settings['bbox_thr']
865+
else:
866+
# There was a bug in main, where bbox_thr was not saved in main_settings.yaml.
867+
# Since there is in practice no option to change bbox_thr in the GUI, we can
868+
# assume that the default value was used.
869+
bbox_thr = 0.8
870+
871+
getPosePickles(trial_id, session_path,
872+
poseDetector=poseDetector,
873+
bbox_thr=bbox_thr)
874+
else:
875+
print(f'pose pickles found, but specified pose detector \
876+
{poseDetector} does not exist. skipping pose pickle \
877+
download')
846878

847879
return
848880

@@ -1004,7 +1036,8 @@ def getMainSettings(trial_id):
10041036

10051037
def downloadAndZipSession(session_id,deleteFolderWhenZipped=True,isDocker=True,
10061038
writeToDjango=False,justDownload=False,data_dir=None,
1007-
useSubjectNameFolder=False):
1039+
useSubjectNameFolder=False,
1040+
include_pose_pickles=False):
10081041

10091042
session = getSessionJson(session_id)
10101043

@@ -1027,14 +1060,14 @@ def downloadAndZipSession(session_id,deleteFolderWhenZipped=True,isDocker=True,
10271060

10281061
# Neutral
10291062
getModelAndMetadata(session_id,session_path)
1030-
getMotionData(neutral_id,session_path)
1063+
getMotionData(neutral_id,session_path,include_pose_pickles=include_pose_pickles)
10311064
downloadVideosFromServer(session_id,neutral_id,isDocker=isDocker,
10321065
isCalibration=False,isStaticPose=True,session_path=session_path)
10331066
getSyncdVideos(neutral_id,session_path)
10341067

10351068
# Dynamic
10361069
for dynamic_id in dynamic_ids:
1037-
getMotionData(dynamic_id,session_path)
1070+
getMotionData(dynamic_id,session_path,include_pose_pickles=include_pose_pickles)
10381071
downloadVideosFromServer(session_id,dynamic_id,isDocker=isDocker,
10391072
isCalibration=False,isStaticPose=False,session_path=session_path)
10401073
getSyncdVideos(dynamic_id,session_path)

0 commit comments

Comments
 (0)