Skip to content

Commit

Permalink
add default settings to json file
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Aug 29, 2023
1 parent 3877521 commit 5aec3a5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Examples/reprocessSessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
# static_id. A list of strings is allowed for dynamic_trialNames.

calib_id = [] # None (auto-selected trial), [] (skip), or string of specific trial_id
static_id = None # 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

# Select which pose estimation model to use; options are 'OpenPose' and 'hrnet'.
Expand Down Expand Up @@ -111,3 +111,4 @@
poseDetector=poseDetector,
resolutionPoseDetection=resolutionPoseDetection,
deleteLocalFolder=deleteLocalFolder)
test=1
4 changes: 4 additions & 0 deletions defaultOpenCapSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"openpose": "1x736",
"hrnet": 0.8
}
1 change: 1 addition & 0 deletions docker/mmpose/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM stanfordnmbl/mmpose:0.1
COPY mmpose /mmpose
COPY utilsMMpose.py /mmpose
COPY defaultOpenCapSettings.json /mmpose
CMD python /mmpose/loop_mmpose.py
1 change: 1 addition & 0 deletions docker/openpose/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

COPY loop.py /openpose
COPY ../defaultOpenCapSettings.json /openpose
CMD python3.6 loop.py

5 changes: 4 additions & 1 deletion docker/openpose/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import shutil
import ffmpeg
import json

#%%
def getVideoOrientation(videoPath):
Expand Down Expand Up @@ -65,7 +66,9 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):
output_dir = "/openpose/data/output_openpose"

# Set resolution for OpenPose ('default', '1x736', or '1x1008_4scales').
resolutionPoseDetection = '1x736'
with open('/openpose/defaultOpenCapSettings.json') as f:
defaultOpenCapSettings = json.load(f)
resolutionPoseDetection = defaultOpenCapSettings['openpose']

if os.path.isfile(video_path):
os.remove(video_path)
Expand Down
7 changes: 6 additions & 1 deletion mmpose/loop_mmpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import logging
import shutil
import json

from utilsMMpose import detection_inference, pose_inference

Expand All @@ -13,7 +14,11 @@
output_dir = "/mmpose/data/output_mmpose"

generateVideo=False
bbox_thr=0.8

with open('/mmpose/defaultOpenCapSettings.json') as f:
defaultOpenCapSettings = json.load(f)
resolutionPoseDetection = defaultOpenCapSettings['openpose']
bbox_thr = defaultOpenCapSettings['hrnet']
model_config_person='/mmpose/faster_rcnn_r50_fpn_coco.py'
model_ckpt_person='/mmpose/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
model_config_pose='/mmpose/hrnet_w48_coco_wholebody_384x288_dark_plus.py'
Expand Down
24 changes: 13 additions & 11 deletions utilsServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
trial_url = "{}{}{}/".format(API_URL, "trials/", trial_id)

# If processTrial is run from app.py, then batchProcess is False and we
# here manually set resolutionPoseDetection and bbox_thr according to
# how they are set in loop.py (OpenPose) and loop_mmpose.py (HRnet).
# here manually set resolutionPoseDetection and bbox_thr to default.
# This is needed to have the correct settings in main_settings.yaml. We also
# set poseDetector here instead of in main.py, such that we can call
# processTrial from app.py and batchReprocess.py.
# processTrial from both app.py and batchReprocess.py.
if not batchProcess:
sessionMetadata = importMetadata(
os.path.join(session_path, 'sessionMetadata.yaml'))
poseDetector = sessionMetadata['posemodel']
file_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(file_dir,'defaultOpenCapSettings.json')) as f:
defaultOpenCapSettings = json.load(f)
if poseDetector.lower() == 'openpose':
resolutionPoseDetection = '1x736'
resolutionPoseDetection = defaultOpenCapSettings['openpose']
elif poseDetector.lower() == 'hrnet':
bbox_thr = 0.8
bbox_thr = defaultOpenCapSettings['hrnet']

# Process the 3 different types of trials
if trial_type == 'calibration':
Expand Down Expand Up @@ -102,7 +104,7 @@ def processTrial(session_id, trial_id, trial_type = 'dynamic',
deleteStaticFiles(session_path, staticTrialName = 'neutral')

# Check for calibration to use on django, if not, check for switch calibrations and post result.
calibrationOptions = getCalibration(session_id,session_path,trial_type=trial_type,getCalibrationOptions=True)
calibrationOptions = getCalibration(session_id,session_path,trial_type=trial_type,getCalibrationOptions=True)

# download the videos
trial_name = downloadVideosFromServer(session_id,trial_id,isDocker=isDocker,
Expand Down Expand Up @@ -288,16 +290,16 @@ def batchReprocess(session_ids,calib_id,static_id,dynamic_trialNames,poseDetecto
resolutionPoseDetection='default',deleteLocalFolder=True,
isServer=False, use_existing_pose_pickle=True):

if (type(calib_id) == str or type(static_id) == str or type(dynamic_ids) == str or
(type(dynamic_ids)==list and len(dynamic_ids)>0)) and len(session_ids) >1:
raise Exception('can only have one session number if hardcoding other trial ids')

# extract trial ids from trial names
# extract trial ids from trial namesspyde
if dynamic_trialNames is not None and len(dynamic_trialNames)>0:
trialNames = getTrialNameIdMapping(session_ids[0])
dynamic_ids = [trialNames[name]['id'] for name in dynamic_trialNames]
else:
dynamic_ids = dynamic_trialNames

if (type(calib_id) == str or type(static_id) == str or type(dynamic_ids) == str or
(type(dynamic_ids)==list and len(dynamic_ids)>0)) and len(session_ids) >1:
raise Exception('can only have one session number if hardcoding other trial ids')

for session_id in session_ids:
print('Processing ' + session_id)
Expand Down

0 comments on commit 5aec3a5

Please sign in to comment.