Skip to content

Commit

Permalink
Merge pull request #275 from JdeRobot/issue-274
Browse files Browse the repository at this point in the history
General app refactor
  • Loading branch information
sergiopaniego authored Jan 5, 2022
2 parents 8c3b4b0 + dd320e6 commit 4a92e28
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 178 deletions.
6 changes: 3 additions & 3 deletions behavior_metrics/analyze_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@
data = json.loads(h)
metadata = json.loads(data['data'])

for topic, point, t in bag.read_messages(topics=['/lap_stats']):
for topic, point, t in bag.read_messages(topics=['/lap_metrics']):
y = yaml.load(str(point), Loader=yaml.FullLoader)
h = json.dumps(y, indent=4)
data = json.loads(h)
lapdata = json.loads(data['data'])

for topic, point, t in bag.read_messages(topics=['/time_stats']):
for topic, point, t in bag.read_messages(topics=['/time_metrics']):
y = yaml.load(str(point), Loader=yaml.FullLoader)
h = json.dumps(y, indent=4)
data = json.loads(h)
time_stats_metadata = json.loads(data['data'])
time_metrics_metadata = json.loads(data['data'])

for topic, point, t in bag.read_messages(topics=['/first_image']):
first_image = bridge.imgmsg_to_cv2(point, desired_encoding='passthrough')
Expand Down
2 changes: 1 addition & 1 deletion behavior_metrics/brains/f1/brain_f1_keras-lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, sensors, actuators, model=None, handler=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False
self.previous_images = np.zeros((1, 50, 100, 3))
print(self.previous_images.shape)
print(self.previous_images.shape)
Expand Down
2 changes: 1 addition & 1 deletion behavior_metrics/brains/f1/brain_f1_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
import tensorflow as tf

self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False

if model:
if not path.exists(PRETRAINED_MODELS + model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False

if model:
if not path.exists(PRETRAINED_MODELS + model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False

if model:
if not path.exists(PRETRAINED_MODELS + model):
Expand Down
2 changes: 1 addition & 1 deletion behavior_metrics/brains/f1/brain_f1_keras_preprocessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False

if model:
if not path.exists(PRETRAINED_MODELS + model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False
self.previous_images = np.zeros((2, 13))
if model:
print(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False
self.previous_images = np.zeros((3, 60))

print(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False
#self.previous_images = np.zeros((25, 13))
self.previous_images = np.zeros((3, 31))
#self.previous_images_1 = np.zeros((5, 13))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False
self.previous_images = np.zeros((25, 13))

if model:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.handler = handler
self.cont = 0
self.inference_times = []
self.gpu_inferencing = True if tf.test.gpu_device_name() else False
self.gpu_inference = True if tf.test.gpu_device_name() else False

if model:
if not path.exists(PRETRAINED_MODELS + model[0]) or not path.exists(PRETRAINED_MODELS + model[1]):
Expand Down
2 changes: 1 addition & 1 deletion behavior_metrics/brains/f1/brain_f1_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.cont = 0
self.inference_times = []
self.device = torch.device("cpu")
self.gpu_inferencing = torch.cuda.is_available()
self.gpu_inference = torch.cuda.is_available()
self.first_image = None
self.transformations = transforms.Compose([
transforms.ToTensor()
Expand Down
2 changes: 1 addition & 1 deletion behavior_metrics/brains/f1/brain_f1_torchstacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
self.inference_times = []
self.device = torch.device("cpu")

self.gpu_inferencing = torch.cuda.is_available()
self.gpu_inference = torch.cuda.is_available()
self.first_image = None
if config:
if 'ImageCrop' in config.keys():
Expand Down
32 changes: 14 additions & 18 deletions behavior_metrics/pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def run(self):
"TODO: cleanup measure of ips"
it = 0
ss = time.time()
stopped_brain_stats = False
stopped_brain_metrics = False
successful_iteration = False
brain_iterations_time = []
while not self.kill_event.is_set():
start_time = datetime.now()
if not self.stop_event.is_set():
self.execution_completed = False
stopped_brain_stats = True
stopped_brain_metrics = True
try:
self.brains.active_brain.execute()
successful_iteration = True
Expand All @@ -136,40 +136,36 @@ def run(self):
logger.error(e)
successful_iteration = False
else:
if stopped_brain_stats:
if stopped_brain_metrics:
self.execution_completed = False
stopped_brain_stats = False
stopped_brain_metrics = False
successful_iteration = False
try:
logger.info('----- MEAN INFERENCE TIME -----')
self.brains.active_brain.inference_times = self.brains.active_brain.inference_times[10:-10]
mean_inference_time = sum(self.brains.active_brain.inference_times) / len(
self.brains.active_brain.inference_times)
frame_rate = len(self.brains.active_brain.inference_times) / sum(
self.brains.active_brain.inference_times)
gpu_inferencing = self.brains.active_brain.gpu_inferencing
gpu_inference = self.brains.active_brain.gpu_inference
first_image = self.brains.active_brain.first_image
logger.info(mean_inference_time)
logger.info(frame_rate)
logger.info('-------------------')
logger.info('* Mean network inference time ---> ' + str(mean_inference_time) + ' s')
logger.info('* Frame rate ---> ' + str(frame_rate) + ' fps')
except Exception as e:
logger.error(e)
mean_inference_time = 0
frame_rate = 0
gpu_inferencing = False
gpu_inference = False
first_image = None
logger.info('No inference brain')

logger.info('----- MEAN ITERATION TIME -----')
mean_iteration_time = sum(brain_iterations_time) / len(brain_iterations_time)
logger.info(mean_iteration_time)
logger.info('-------------------')
logger.info(hasattr(self.controller, 'stats_filename'))
if hasattr(self.controller, 'stats_filename'):
logger.info('* Mean brain iteration time ---> ' + str(mean_iteration_time) + ' s')
logger.info(hasattr(self.controller, 'experiment_metrics_filename'))
if hasattr(self.controller, 'experiment_metrics_filename'):
try:
logger.info('Entering Stats into Bag')
self.controller.save_time_stats(mean_iteration_time, mean_inference_time, frame_rate,
gpu_inferencing, first_image)
logger.info('Saving metrics to ROS bag')
self.controller.save_metrics(mean_iteration_time, mean_inference_time, frame_rate,
gpu_inference, first_image)
except Exception as e:
logger.info('Empty ROS bag')
logger.error(e)
Expand Down
Loading

0 comments on commit 4a92e28

Please sign in to comment.