From 5afe1ffb2227c4c3685690d367e29a7328b10e53 Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Mon, 29 Apr 2024 15:59:02 +0200 Subject: [PATCH] Updated brain --- ...in_carla_bird_eye_deep_learning_torch_V.py | 45 ++----------------- .../configs/CARLA/default_carla_torch.yml | 4 +- 2 files changed, 5 insertions(+), 44 deletions(-) diff --git a/behavior_metrics/brains/CARLA/pytorch/brain_carla_bird_eye_deep_learning_torch_V.py b/behavior_metrics/brains/CARLA/pytorch/brain_carla_bird_eye_deep_learning_torch_V.py index cfe77308..0ad0da05 100644 --- a/behavior_metrics/brains/CARLA/pytorch/brain_carla_bird_eye_deep_learning_torch_V.py +++ b/behavior_metrics/brains/CARLA/pytorch/brain_carla_bird_eye_deep_learning_torch_V.py @@ -127,32 +127,10 @@ def execute(self): try: image = Image.fromarray(image) - #print(image.size) - #image = image.resize((300, 225)) - #image = image.resize((225, 300)) - #print(image.size) - #image.save('imagen_guardada.png') - # (2048, 1536) - # (2048, 120) - - - # ATLAS original - #camera_bp.set_attribute('image_size_x', str(2048)) - #camera_bp.set_attribute('image_size_y', str(1536)) - # We adjust the size to retrieve images at a faster pace - #camera_bp.set_attribute('image_size_x', str(300)) - #camera_bp.set_attribute('image_size_y', str(224.85)) - altura_recorte = 120 ancho, altura = image.size y_superior = max(0, altura - altura_recorte) image = image.crop((0, y_superior, ancho, altura)) - - #print('image.size', image.size) - - - - image = self.transformations(image) @@ -161,7 +139,6 @@ def execute(self): vehicle_speed = 3.6 * math.sqrt(speed.x**2 + speed.y**2 + speed.z**2) #print('vehicle_speed', vehicle_speed) - vehicle_speed_norm = torch.clamp(torch.tensor(vehicle_speed, dtype=torch.float32) / 40.0, 0, 1.0) @@ -169,25 +146,14 @@ def execute(self): image = torch.cat((image, valor_cuartadimension), dim=0).to(self.device) image = image.unsqueeze(0) - #print('image.shape', image.shape) - #print('self.gpu_inference', self.gpu_inference) - #print(image) - start_time = time.time() with torch.no_grad(): prediction = self.net(image).cpu().numpy() if self.gpu_inference else self.net(image).numpy() self.inference_times.append(time.time() - start_time) - print('prediction', prediction) - if (prediction[0][1] < 0.4): - print('LOG!!!!!!!!!!!!!!!!!!!!!!!!!!!') + #print('prediction', prediction) #print(prediction) prediction = prediction.flatten() - # prediction = prediction.detach().cpu().numpy().flatten() - #print('prediction', prediction) - - #print('vehicle_speed', vehicle_speed) - #print('vehicle_speed_norm', vehicle_speed_norm) combined, steer = prediction combined = float(combined) @@ -197,13 +163,8 @@ def execute(self): else: break_command = (0.5 - combined) / 0.5 steer = (float(steer) * 2.0) - 1.0 + #print(throttle, steer, break_command) - #throttle = prediction[0][0] - #steer = prediction[0][1] * (1 - (-1)) + (-1) - #break_command = prediction[0][2] - - print(throttle, steer, break_command) - #print('----') if vehicle_speed > 30: self.motors.sendThrottle(0) @@ -215,7 +176,7 @@ def execute(self): self.motors.sendSteer(0.0) self.motors.sendBrake(0) else: - self.motors.sendThrottle(0.5) + self.motors.sendThrottle(throttle) self.motors.sendSteer(steer) self.motors.sendBrake(break_command) diff --git a/behavior_metrics/configs/CARLA/default_carla_torch.yml b/behavior_metrics/configs/CARLA/default_carla_torch.yml index ea6a9eee..5d140829 100644 --- a/behavior_metrics/configs/CARLA/default_carla_torch.yml +++ b/behavior_metrics/configs/CARLA/default_carla_torch.yml @@ -34,10 +34,10 @@ Behaviors: MaxV: 3 MaxW: 0.3 BrainPath: 'brains/CARLA/pytorch/brain_carla_bird_eye_deep_learning_torch_V.py' - PilotTimeCycle: 50 + PilotTimeCycle: 100 AsyncMode: True Parameters: - Model: '15_04_best_model_checkpoint_189.pth' + Model: '29_04_best_model_checkpoint_299.pth' ImageCropped: True ImageSize: [ 100,50 ] ImageNormalized: True