-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict_control_jirl.py
53 lines (50 loc) · 1.47 KB
/
predict_control_jirl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import keras
import pandas as pd
import numpy as np
import os
from jetracer.nvidia_racecar import NvidiaRacecar
from jetcam.csi_camera import CSICamera
import time
import vae
from vae.controller import VAEController
from stable_baselines import SAC
car = NvidiaRacecar()
throttle = 0.8
#path = "jetcar_weights.pkl"
path = "logs/sac/JetVae-v0_46/JetVae-v0.pkl"
input_array = np.zeros((1, 256))
try:
i = 0
v = VAEController()
v.load("logs/vae-256.pkl")
#model = keras.models.load_model(path)
model = SAC.load(path)
camera = CSICamera(width=112, height=112)
camera.running = True
print("Imported Camera! Ready to Start!")
while True:
print("Starting to read image")
image = camera.value.copy()
print("Image Read!")
#image = cv2.resize(image, (224//2, 224//2))
print(type(image))
tmp = v.encode_from_raw_image(image)
print("Got image")
input_array[0,:] = tmp
print("Predicing from Model")
action, _ = model.predict(input_array, deterministic = True)
t = (action[1] + 1) / 2
# Convert from [0, 1] to [min, max]
action[1] = (1 - t) * 0.45 + 0.6 * t
print(action)
steer = float(action[0])
throttle = float(action[1])
print("Frame: {}\t Steer: {}\t Throttle:{}".format(i, steer, throttle))
i+=1
car.throttle = throttle
car.steering = steer
except:
car.throttle = 0
car.steer = 0
import sys
sys.exit(1)