Skip to content

Commit

Permalink
Updated brain
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopaniego committed Apr 29, 2024
1 parent 4fe663b commit 5afe1ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -161,33 +139,21 @@ 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)


valor_cuartadimension = torch.full((1, image.shape[1], image.shape[2]), float(vehicle_speed_norm))
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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions behavior_metrics/configs/CARLA/default_carla_torch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5afe1ff

Please sign in to comment.