Skip to content

Commit

Permalink
minor logging stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Jun 24, 2024
1 parent 019eeca commit 67ba898
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
16 changes: 9 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import yaml
import traceback

import logging
logging.basicConfig(level=logging.INFO)

from utils import importMetadata, loadCameraParameters, getVideoExtension
from utils import getDataDirectory, getOpenPoseDirectory, getMMposeDirectory
from utilsChecker import saveCameraParameters
Expand Down Expand Up @@ -203,16 +206,15 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
# Intrinsics and extrinsics already exist for this session.
if os.path.exists(
os.path.join(camDir,"cameraIntrinsicsExtrinsics.pickle")):
print("Load extrinsics for {} - already existing".format(
logging.info("Load extrinsics for {} - already existing".format(
camName))
CamParams = loadCameraParameters(
os.path.join(camDir, "cameraIntrinsicsExtrinsics.pickle"))
loadedCamParams[camName] = True

# Extrinsics do not exist for this session.
else:
print("Compute extrinsics for {} - not yet existing".format(
camName))
logging.info("Compute extrinsics for {} - not yet existing".format(camName))
# Intrinsics ##################################################
# Intrinsics directories.
intrinsicDir = os.path.join(baseDir, 'CameraIntrinsics',
Expand Down Expand Up @@ -408,7 +410,7 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
if runMarkerAugmentation:
os.makedirs(postAugmentationDir, exist_ok=True)
augmenterDir = os.path.join(baseDir, "MarkerAugmenter")
print('Augmenting marker set')
logging.info('Augmenting marker set')
try:
vertical_offset = augmentTRC(
pathOutputFiles[trialName],sessionMetadata['mass_kg'],
Expand Down Expand Up @@ -480,11 +482,11 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
thresholdTime=0.1, removeRoot=True)
success = True
except Exception as e:
print(f"Attempt with thresholdPosition {thresholdPosition} failed: {e}")
logging.info(f"Attempt identifying scaling time range with thresholdPosition {thresholdPosition} failed: {e}")
thresholdPosition += increment # Increase the threshold for the next iteration

# Run scale tool.
print('Running Scaling')
logging.info('Running Scaling')
pathScaledModel = runScaleTool(
pathGenericSetupFile4Scaling, pathGenericModel4Scaling,
sessionMetadata['mass_kg'], pathTRCFile4Scaling,
Expand Down Expand Up @@ -522,7 +524,7 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
# Path TRC file.
pathTRCFile4IK = pathAugmentedOutputFiles[trialName]
# Run IK tool.
print('Running Inverse Kinematics')
logging.info('Running Inverse Kinematics')
try:
pathOutputIK = runIKTool(
pathGenericSetupFile4IK, pathScaledModel,
Expand Down
12 changes: 0 additions & 12 deletions utilsAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import os
import boto3
import requests
import logging
logging.basicConfig(level=logging.INFO)

from decouple import config
from datetime import datetime, timedelta
Expand Down Expand Up @@ -51,18 +49,13 @@ def getASInstance():
# Check if the ECS_CONTAINER_METADATA_FILE environment variable exists
ecs_metadata_file = os.getenv('ECS_CONTAINER_METADATA_FILE')
if ecs_metadata_file:
logging.info(f"ECS_CONTAINER_METADATA_FILE is set to: {ecs_metadata_file}")
if os.path.isfile(ecs_metadata_file):
logging.info("Metadata file exists.")
return True
else:
logging.warning("Metadata file does not exist at the specified path.")
return False
else:
logging.info("ECS_CONTAINER_METADATA_FILE is not set.")
return False
except Exception as e:
logging.error(f"Error occurred while checking ECS_CONTAINER_METADATA_FILE: {e}")
return False

def get_metric_average(namespace, metric_name, start_time, end_time, period):
Expand Down Expand Up @@ -100,9 +93,7 @@ def get_number_of_pending_trials(period=60):

if stats['Datapoints']:
average = stats['Datapoints'][0]['Average']
logging.info(f"Average value of '{metric_name}' over the last minute: {average}")
else:
logging.info("No data points found.")
# Maybe raise an exception or do nothing to have control-loop retry this call later
return None

Expand Down Expand Up @@ -131,8 +122,5 @@ def set_instance_protection(instance_id, asg_name, protect):

def unprotect_current_instance():
instance_id = get_instance_id()
logging.info("Instance ID: " + instance_id)
asg_name = get_auto_scaling_group_name(instance_id)
logging.info("Auto Scaling Group Name: " + asg_name)
set_instance_protection(instance_id, asg_name, protect=False)
logging.info("Done unprotecting instance.")
4 changes: 2 additions & 2 deletions utilsAugmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def augmentTRC(pathInputTRCFile, subject_mass, subject_height,
augmenterModelType_all = [augmenterModelType_lower, augmenterModelType_upper]
feature_markers_all = [feature_markers_lower, feature_markers_upper]
response_markers_all = [response_markers_lower, response_markers_upper]
print('Using augmenter model: {}'.format(augmenter_model))
# print('Using augmenter model: {}'.format(augmenter_model))

# %% Process data.
# Import TRC file
Expand Down Expand Up @@ -112,7 +112,7 @@ def augmentTRC(pathInputTRCFile, subject_mass, subject_height,
json_file.close()
model = tf.keras.models.model_from_json(pretrainedModel_json)
model.load_weights(os.path.join(augmenterModelDir, "weights.h5"))
outputs = model.predict(inputs)
outputs = model.predict(inputs, verbose=2)

# %% Post-process outputs.
# Step 1: Reshape if necessary (eg, LSTM)
Expand Down
7 changes: 0 additions & 7 deletions utilsDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import sys
import time

import logging
logging.basicConfig(level=logging.INFO)

from decouple import config

from utils import getOpenPoseMarkerNames, getMMposeMarkerNames, getVideoExtension
Expand Down Expand Up @@ -311,21 +308,17 @@ def runMMposeVideo(
try:
# wait until the video is processed (i.e. until the video is removed -- then json should be ready)
start = time.time()
logging.info("Processing mmpose. Before waiting for video to be processed.")
while True:
if not os.path.isfile(vid_path):
logging.info("Processing mmpose. Video not available. Break.")
break

if start + 60*60 < time.time():
raise Exception("Pose detection timed out. This is unlikely to be your fault, please report this issue on the forum. You can proceed with your data collection (videos are uploaded to the server) and later reprocess errored trials.", 'timeout - hrnet')

time.sleep(0.1)

logging.info("Processing mmpose. Before copying.")
# copy /data/output to pathOutputPkl
os.system("cp /data/output_mmpose/* {pathOutputPkl}/".format(pathOutputPkl=pathOutputPkl))
logging.info("Processing mmpose. After copying.")
pkl_path_tmp = os.path.join(pathOutputPkl, 'human.pkl')
os.rename(pkl_path_tmp, pklPath)

Expand Down
11 changes: 7 additions & 4 deletions utilsMMpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pickle
import torch

from tqdm import tqdm
# from tqdm import tqdm
from mmpose_utils import process_mmdet_results, frame_iter, concat, convert_instance_to_frame
try:
from mmdet.apis import inference_detector, init_detector
Expand Down Expand Up @@ -47,7 +47,8 @@ def detection_inference(model_config, model_ckpt, video_path, bbox_path,

output = []
nFrames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
for img in tqdm(frame_iter(cap), total=nFrames):
# for img in tqdm(frame_iter(cap), total=nFrames):
for img in frame_iter(cap):
# test a single image, the resulting box is (x1, y1, x2, y2)
mmdet_results = inference_detector(det_model, img)

Expand Down Expand Up @@ -87,7 +88,8 @@ def pose_inference(model_config, model_ckpt, video_path, bbox_path, pkl_path,
# run pose inference
print("Running pose inference...")
instances = []
for batch in tqdm(dataloader):
# for batch in tqdm(dataloader):
for batch in dataloader:
batch['img'] = batch['img'].to(device)
batch['img_metas'] = [img_metas[0] for img_metas in batch['img_metas'].data]
with torch.no_grad():
Expand Down Expand Up @@ -122,7 +124,8 @@ def pose_inference(model_config, model_ckpt, video_path, bbox_path, pkl_path,
dataset = model.cfg.data.test.type
dataset_info_d = get_dataset_info()
dataset_info = DatasetInfo(dataset_info_d[dataset])
for pose_results, img in tqdm(zip(results, frame_iter(cap))):
# for pose_results, img in tqdm(zip(results, frame_iter(cap))):
for pose_results, img in zip(results, frame_iter(cap)):
for instance in pose_results:
instance['keypoints'] = instance['preds_with_flip']
vis_img = vis_pose_tracking_result(model, img, pose_results,
Expand Down

0 comments on commit 67ba898

Please sign in to comment.