Skip to content

Commit 67ba898

Browse files
minor logging stuff
1 parent 019eeca commit 67ba898

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import yaml
1414
import traceback
1515

16+
import logging
17+
logging.basicConfig(level=logging.INFO)
18+
1619
from utils import importMetadata, loadCameraParameters, getVideoExtension
1720
from utils import getDataDirectory, getOpenPoseDirectory, getMMposeDirectory
1821
from utilsChecker import saveCameraParameters
@@ -203,16 +206,15 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
203206
# Intrinsics and extrinsics already exist for this session.
204207
if os.path.exists(
205208
os.path.join(camDir,"cameraIntrinsicsExtrinsics.pickle")):
206-
print("Load extrinsics for {} - already existing".format(
209+
logging.info("Load extrinsics for {} - already existing".format(
207210
camName))
208211
CamParams = loadCameraParameters(
209212
os.path.join(camDir, "cameraIntrinsicsExtrinsics.pickle"))
210213
loadedCamParams[camName] = True
211214

212215
# Extrinsics do not exist for this session.
213216
else:
214-
print("Compute extrinsics for {} - not yet existing".format(
215-
camName))
217+
logging.info("Compute extrinsics for {} - not yet existing".format(camName))
216218
# Intrinsics ##################################################
217219
# Intrinsics directories.
218220
intrinsicDir = os.path.join(baseDir, 'CameraIntrinsics',
@@ -408,7 +410,7 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
408410
if runMarkerAugmentation:
409411
os.makedirs(postAugmentationDir, exist_ok=True)
410412
augmenterDir = os.path.join(baseDir, "MarkerAugmenter")
411-
print('Augmenting marker set')
413+
logging.info('Augmenting marker set')
412414
try:
413415
vertical_offset = augmentTRC(
414416
pathOutputFiles[trialName],sessionMetadata['mass_kg'],
@@ -480,11 +482,11 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
480482
thresholdTime=0.1, removeRoot=True)
481483
success = True
482484
except Exception as e:
483-
print(f"Attempt with thresholdPosition {thresholdPosition} failed: {e}")
485+
logging.info(f"Attempt identifying scaling time range with thresholdPosition {thresholdPosition} failed: {e}")
484486
thresholdPosition += increment # Increase the threshold for the next iteration
485487

486488
# Run scale tool.
487-
print('Running Scaling')
489+
logging.info('Running Scaling')
488490
pathScaledModel = runScaleTool(
489491
pathGenericSetupFile4Scaling, pathGenericModel4Scaling,
490492
sessionMetadata['mass_kg'], pathTRCFile4Scaling,
@@ -522,7 +524,7 @@ def main(sessionName, trialName, trial_id, camerasToUse=['all'],
522524
# Path TRC file.
523525
pathTRCFile4IK = pathAugmentedOutputFiles[trialName]
524526
# Run IK tool.
525-
print('Running Inverse Kinematics')
527+
logging.info('Running Inverse Kinematics')
526528
try:
527529
pathOutputIK = runIKTool(
528530
pathGenericSetupFile4IK, pathScaledModel,

utilsAPI.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import os
88
import boto3
99
import requests
10-
import logging
11-
logging.basicConfig(level=logging.INFO)
1210

1311
from decouple import config
1412
from datetime import datetime, timedelta
@@ -51,18 +49,13 @@ def getASInstance():
5149
# Check if the ECS_CONTAINER_METADATA_FILE environment variable exists
5250
ecs_metadata_file = os.getenv('ECS_CONTAINER_METADATA_FILE')
5351
if ecs_metadata_file:
54-
logging.info(f"ECS_CONTAINER_METADATA_FILE is set to: {ecs_metadata_file}")
5552
if os.path.isfile(ecs_metadata_file):
56-
logging.info("Metadata file exists.")
5753
return True
5854
else:
59-
logging.warning("Metadata file does not exist at the specified path.")
6055
return False
6156
else:
62-
logging.info("ECS_CONTAINER_METADATA_FILE is not set.")
6357
return False
6458
except Exception as e:
65-
logging.error(f"Error occurred while checking ECS_CONTAINER_METADATA_FILE: {e}")
6659
return False
6760

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

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

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

132123
def unprotect_current_instance():
133124
instance_id = get_instance_id()
134-
logging.info("Instance ID: " + instance_id)
135125
asg_name = get_auto_scaling_group_name(instance_id)
136-
logging.info("Auto Scaling Group Name: " + asg_name)
137126
set_instance_protection(instance_id, asg_name, protect=False)
138-
logging.info("Done unprotecting instance.")

utilsAugmenter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def augmentTRC(pathInputTRCFile, subject_mass, subject_height,
4545
augmenterModelType_all = [augmenterModelType_lower, augmenterModelType_upper]
4646
feature_markers_all = [feature_markers_lower, feature_markers_upper]
4747
response_markers_all = [response_markers_lower, response_markers_upper]
48-
print('Using augmenter model: {}'.format(augmenter_model))
48+
# print('Using augmenter model: {}'.format(augmenter_model))
4949

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

117117
# %% Post-process outputs.
118118
# Step 1: Reshape if necessary (eg, LSTM)

utilsDetector.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import sys
88
import time
99

10-
import logging
11-
logging.basicConfig(level=logging.INFO)
12-
1310
from decouple import config
1411

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

320315
if start + 60*60 < time.time():
321316
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')
322317

323318
time.sleep(0.1)
324319

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

utilsMMpose.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pickle
33
import torch
44

5-
from tqdm import tqdm
5+
# from tqdm import tqdm
66
from mmpose_utils import process_mmdet_results, frame_iter, concat, convert_instance_to_frame
77
try:
88
from mmdet.apis import inference_detector, init_detector
@@ -47,7 +47,8 @@ def detection_inference(model_config, model_ckpt, video_path, bbox_path,
4747

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

@@ -87,7 +88,8 @@ def pose_inference(model_config, model_ckpt, video_path, bbox_path, pkl_path,
8788
# run pose inference
8889
print("Running pose inference...")
8990
instances = []
90-
for batch in tqdm(dataloader):
91+
# for batch in tqdm(dataloader):
92+
for batch in dataloader:
9193
batch['img'] = batch['img'].to(device)
9294
batch['img_metas'] = [img_metas[0] for img_metas in batch['img_metas'].data]
9395
with torch.no_grad():
@@ -122,7 +124,8 @@ def pose_inference(model_config, model_ckpt, video_path, bbox_path, pkl_path,
122124
dataset = model.cfg.data.test.type
123125
dataset_info_d = get_dataset_info()
124126
dataset_info = DatasetInfo(dataset_info_d[dataset])
125-
for pose_results, img in tqdm(zip(results, frame_iter(cap))):
127+
# for pose_results, img in tqdm(zip(results, frame_iter(cap))):
128+
for pose_results, img in zip(results, frame_iter(cap)):
126129
for instance in pose_results:
127130
instance['keypoints'] = instance['preds_with_flip']
128131
vis_img = vis_pose_tracking_result(model, img, pose_results,

0 commit comments

Comments
 (0)