Skip to content

Commit

Permalink
camerastouse in sessionMetaData
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Jun 28, 2024
1 parent 038b00a commit 17853b6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 45 deletions.
15 changes: 8 additions & 7 deletions Examples/changeSessionMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@

from utils import changeSessionMetadata

session_ids = ["0d46adef-62cb-455f-9ff3-8116717cc2fe"]
session_ids = ["6dc0721a-7457-4ce1-8523-577900b5399f"]

# Dictionary of metadata fields to change (see sessionMetadata.yaml).
newMetadata = {
'openSimModel':'LaiUhlrich2022_shoulder',
'posemodel':'hrnet',
'augmentermodel':'v0.3',
'filterfrequency':15,
'datasharing':'Share processed data and identified videos',
'scalingsetup': 'upright_standing_pose'
'camerastouse': ['all_available']
# 'openSimModel':'LaiUhlrich2022_shoulder',
# 'posemodel':'hrnet',
# 'augmentermodel':'v0.3',
# 'filterfrequency':15,
# 'datasharing':'Share processed data and identified videos',
# 'scalingsetup': 'upright_standing_pose'
}
changeSessionMetadata(session_ids,newMetadata)
9 changes: 5 additions & 4 deletions Examples/reprocessSessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Enter the identifier(s) of the session(s) you want to reprocess. This is a list of one
# or more session identifiers. The identifier is found as the 36-character string at the
# end of the session url: app.opencap.ai/session/<session_id>
session_ids = ['23d52d41-69fe-47cf-8b60-838e4268dd50']
session_ids = ['6dc0721a-7457-4ce1-8523-577900b5399f']

# Select which trials to reprocess. You can reprocess all trials in the session
# by entering None in all fields below. The correct calibration and static
Expand All @@ -68,7 +68,7 @@

calib_id = [] # None (auto-selected trial), [] (skip), or string of specific trial_id
static_id = [] # None (auto-selected trial), [] (skip), or string of specific trial_id
dynamic_trialNames = None # None (all dynamic trials), [] (skip), or list of trial names
dynamic_trialNames = ['test_2'] # None (all dynamic trials), [] (skip), or list of trial names

# Select which pose estimation model to use; options are 'OpenPose' and 'hrnet'.
# If the same pose estimation model was used when collecting data with the web
Expand All @@ -79,7 +79,7 @@
# selected 'hrnet' when collecting data with the web app. You can however re-
# process data originally collected with 'hrnet' with 'OpenPose' if you have
# installed OpenPose locally (see README.md for instructions).
poseDetector = 'OpenPose'
poseDetector = 'hrnet'

# OpenPose only:
# Select the resolution at which the videos are processed. There are no
Expand Down Expand Up @@ -110,4 +110,5 @@
batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,
poseDetector=poseDetector,
resolutionPoseDetection=resolutionPoseDetection,
deleteLocalFolder=deleteLocalFolder)
deleteLocalFolder=deleteLocalFolder,
cameras_to_use = ['all_available'])
23 changes: 5 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,11 @@
headers = {"Authorization": "Token {}".format(API_TOKEN)})
continue

# This is a hack to have the trials with status "reprocess" to be reprocessed
# with camerasToUse = ['all_available'] instead of ['all']. In practice, this
# allows reprocessing on server trials that failed because video(s) were not available.
# This is a temporary solution until we have a better way to handle this. By default,
# trials with missing videos are error-ed out directly so that we do not spend time
# on processing them. Problem is that these trials then don't have pose pickles, which
# makes is hard for local reprocessing (hrnet still a hassle to install locally on Windows).
# status = trial["status"]
# status = 'reprocess'
# logging.info(f"Trial status: {status}")
# if status == "reprocess":
# camerasToUse_c = ['all_available']
# else:
# camerasToUse_c = ['all']
# if any([v["video"] is None for v in trial["videos"]]):
# r = requests.patch(trial_url, data={"status": "error"},
# headers = {"Authorization": "Token {}".format(API_TOKEN)})
# continue
# The following is now done in main, to allow reprocessing trials with missing videos
# if any([v["video"] is None for v in trial["videos"]]):
# r = requests.patch(trial_url, data={"status": "error"},
# headers = {"Authorization": "Token {}".format(API_TOKEN)})
# continue

trial_type = "dynamic"
if trial["name"] == "calibration":
Expand Down
18 changes: 11 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from utilsAugmenter import augmentTRC
from utilsOpenSim import runScaleTool, getScaleTimeRange, runIKTool, generateVisualizerJson

def main(sessionName, trialName, trial_id, camerasToUse=['all'],
def main(sessionName, trialName, trial_id, cameras_to_use=['all'],
intrinsicsFinalFolder='Deployed', isDocker=False,
extrinsicsTrial=False, alternateExtrinsics=None,
calibrationOptions=None,
Expand All @@ -41,7 +41,8 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
genericFolderNames=False, offset=True, benchmark=False,
dataDir=None, overwriteAugmenterModel=False,
filter_frequency='default', overwriteFilterFrequency=False,
scaling_setup='upright_standing_pose', overwriteScalingSetup=False):
scaling_setup='upright_standing_pose', overwriteScalingSetup=False,
overwriteCamerasToUse=False):

# %% High-level settings.
# Camera calibration.
Expand Down Expand Up @@ -121,11 +122,14 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
else:
scalingSetup = scaling_setup

# If reprocess is in sessionMetadata, reprocess with all cameras available
# instead of all cameras. This allows reprocessing of trials with missing
# videos.
if 'reprocess' in sessionMetadata:
camerasToUse = ['all_available']
# If camerastouse is in sessionMetadata, reprocess with specified cameras.
# This allows reprocessing trials with missing videos. If
# overwriteCamerasToUse is True, the camera selection is the one
# passed as an argument to main(). This is useful for local testing.
if 'camerastouse' in sessionMetadata and not overwriteCamerasToUse:
camerasToUse = sessionMetadata['camerastouse']
else:
camerasToUse = cameras_to_use

# %% Paths to pose detector folder for local testing.
if poseDetector == 'OpenPose':
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def changeSessionMetadata(session_ids,newMetaDict):
for newMeta in newMetaDict:
if not newMeta in addedKey:
print("Could not find {} in existing metadata, trying to add it.".format(newMeta))
settings_fields = ['framerate', 'posemodel', 'openSimModel', 'augmentermodel', 'filterfrequency', 'scalingsetup']
settings_fields = ['framerate', 'posemodel', 'openSimModel', 'augmentermodel', 'filterfrequency', 'scalingsetup', 'camerastouse']
if newMeta in settings_fields:
if 'settings' not in existingMeta:
existingMeta['settings'] = {}
Expand Down
16 changes: 8 additions & 8 deletions utilsServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
hasWritePermissions = True,
use_existing_pose_pickle = False,
batchProcess = False,
camerasToUse=['all']):
cameras_to_use=['all']):

# Get session directory
session_name = session_id
Expand All @@ -63,7 +63,7 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
try:
main(session_name, trial_name, trial_id, isDocker=isDocker, extrinsicsTrial=True,
imageUpsampleFactor=imageUpsampleFactor,genericFolderNames = True,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)
except Exception as e:
error_msg = {}
error_msg['error_msg'] = e.args[0]
Expand Down Expand Up @@ -125,7 +125,7 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
genericFolderNames = True,
bbox_thr = bbox_thr,
calibrationOptions = calibrationOptions,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)
except Exception as e:
# Try to post pose pickles so can be used offline. This function will
# error at kinematics most likely, but if pose estimation completed,
Expand Down Expand Up @@ -215,7 +215,7 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
resolutionPoseDetection = resolutionPoseDetection,
genericFolderNames = True,
bbox_thr = bbox_thr,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)
except Exception as e:
# Try to post pose pickles so can be used offline. This function will
# error at kinematics most likely, but if pose estimation completed,
Expand Down Expand Up @@ -336,7 +336,7 @@ def newSessionSameSetup(session_id_old,session_id_new,extrinsicTrialName='calibr
def batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,poseDetector='OpenPose',
resolutionPoseDetection='1x736',deleteLocalFolder=True,
isServer=False, use_existing_pose_pickle=True,
camerasToUse=['all']):
cameras_to_use=['all']):

# extract trial ids from trial names
if dynamic_trialNames is not None and len(dynamic_trialNames)>0:
Expand Down Expand Up @@ -372,7 +372,7 @@ def batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,poseDetecto
deleteLocalFolder = deleteLocalFolder,
isDocker=isServer,
hasWritePermissions = hasWritePermissions,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)
statusData = {'status':'done'}
_ = requests.patch(API_URL + "trials/{}/".format(calib_id_toProcess), data=statusData,
headers = {"Authorization": "Token {}".format(API_TOKEN)})
Expand All @@ -399,7 +399,7 @@ def batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,poseDetecto
hasWritePermissions = hasWritePermissions,
use_existing_pose_pickle = use_existing_pose_pickle,
batchProcess = True,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)
statusData = {'status':'done'}
_ = requests.patch(API_URL + "trials/{}/".format(static_id_toProcess), data=statusData,
headers = {"Authorization": "Token {}".format(API_TOKEN)})
Expand Down Expand Up @@ -431,7 +431,7 @@ def batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,poseDetecto
hasWritePermissions = hasWritePermissions,
use_existing_pose_pickle = use_existing_pose_pickle,
batchProcess = True,
camerasToUse=camerasToUse)
cameras_to_use=cameras_to_use)

statusData = {'status':'done'}
_ = requests.patch(API_URL + "trials/{}/".format(dID), data=statusData,
Expand Down

0 comments on commit 17853b6

Please sign in to comment.