diff --git a/main.py b/main.py index c2fd3f3..57ffece 100644 --- a/main.py +++ b/main.py @@ -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 @@ -203,7 +206,7 @@ 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")) @@ -211,8 +214,7 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'], # 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', @@ -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'], @@ -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, @@ -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, diff --git a/utilsAPI.py b/utilsAPI.py index 142b1c1..cf0e837 100644 --- a/utilsAPI.py +++ b/utilsAPI.py @@ -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 @@ -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): @@ -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 @@ -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.") \ No newline at end of file diff --git a/utilsAugmenter.py b/utilsAugmenter.py index f10c4b1..c7eee42 100644 --- a/utilsAugmenter.py +++ b/utilsAugmenter.py @@ -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 @@ -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) diff --git a/utilsDetector.py b/utilsDetector.py index 0816abf..21c7fc2 100644 --- a/utilsDetector.py +++ b/utilsDetector.py @@ -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 @@ -311,10 +308,8 @@ 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(): @@ -322,10 +317,8 @@ def runMMposeVideo( 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) diff --git a/utilsMMpose.py b/utilsMMpose.py index 2319c90..0201620 100644 --- a/utilsMMpose.py +++ b/utilsMMpose.py @@ -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 @@ -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) @@ -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(): @@ -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,