-
Notifications
You must be signed in to change notification settings - Fork 3
/
par.py
174 lines (126 loc) · 4.79 KB
/
par.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import gymnasium as gym
import torch
import time
from stable_baselines3 import PPO
from CarlaEnv import CustomEnv
from HardEnv import HardEnv
import matplotlib.pyplot as plt
import numpy as np
# ## Actor-Reporter-Planner
# ## Actor
# In[2]:
# load model and env
model = PPO.load("ppo/carla-lanefollow-empty_trial1")
vec_env = HardEnv(ego_vehicle='car1')
# ## Planner
# In[2]:
from openai import OpenAI
import warnings
warnings.filterwarnings('ignore')
# In[3]:
# OpenAI ChatCompletions API client initialization
client = OpenAI(
api_key=""
)
# In[4]:
def selectAction(prompt):
completion = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
messages=[
{"role": "system", "content": "Your goal is to drive safely and efficiently. You are directing the ego vehicle in our simulation, selecting actions when prompted."},
{"role": "user", "content": prompt}
]
)
return completion.choices[0].message.content.strip()
# In[6]:
selectAction("There is a motorcycle directly in front of me that appears to be stopping. Select 1) brake or 2) continue for me.")
# ## Reporter
# In[5]:
from llava.model.builder import load_pretrained_model
from llava.mm_utils import get_model_name_from_path
from llava.eval.run_llava import eval_model
# In[8]:
vec_env = HardEnv(ego_vehicle='car1')
obs, info = vec_env.reset()
plt.imsave("basic.jpg", obs['image'][0],cmap='gray')
# get initial llava report
model_path = "carla-llava-checkpoint/llava-v1.5-7b-task-lora"
model_base = "liuhaotian/llava-v1.5-7b"
prompt = "What are objects worth noting in the current scenario? What are the vehicles in the image, their positions, and are they a possible threat to the ego vehicle based on their driving? Answer as the point of view of the driver in the image. I am driving at 40 mph. Be as succinct as possible."
image_file = "basic.jpg"
args = type('Args', (), {
"model_path": model_path,
"model_base": model_base,
"model_name": get_model_name_from_path(model_path),
"query": prompt,
"conv_mode": None,
"image_file": image_file,
"sep": ",",
"temperature": 0,
"top_p": None,
"num_beams": 1,
"max_new_tokens": 512
})()
eval_model(args)
# In[12]:
report = "There is a vehicle 49.37 meters away. There is a vehicle 49.87 meters away. There is a vehicle 49.33 meters away. There is a vehicle 49.41 meters away. There is a vehicle 49.91 meters away. There is a vehicle 49.71 meters away. There is a vehicle 49.39 meters away. There is a vehicle 49.85 meters away. There is a vehicle 49.45 meters away. There is a vehicle 49.30 meters away. There is a vehicle 49.96 meters away. There is a vehicle 49.57 meters away. There is a vehicle 49.41 meters away. There is a vehicle 49.83 meters away. There is a vehicle 49.35 meters away. There is a vehicle 49.53 meters away. There is a vehicle 49.99 meters away. There is a vehicle 49.61 meters away. There is a vehicle 49.49 meters away. There is a vehicle 49.89 meters away. There is a vehicle 49.32 meters away. There is a vehicle 49.59 meters away. There is a vehicle 49.94 meters away. There is a vehicle 49.66 meters away. There is a vehicle 49.43 meters away. There is a vehicle 49.86 meters away. There is a vehicle 49.38 meters away. There is a vehicle 49.99 meters away. There is a vehicle 49.61 meters away. There is a vehicle 49.53 meters away. There is a vehicle 49.49 meters away. There is a vehicle 49.83 meters away. There is a vehicle 49.33 meters away. There is a vehicle 49.96 meters away. There is a vehicle 49.66 meters away. There is a vehicle 49.44 meters away. There is a vehicle 49.89 meters away. There is a vehicle 49.38 meters away. There is a vehicle 49.99 meters away. There is a vehicle"
report += " Select 1) brake or 2) continue for me."
selectAction(report)
# Vehicle obstacle test:
# Trial 1: pass
# Trial 2: pass
# Trial 3: fail
# Trial 4: fail
# Trial 5: fail
# Trial 6: pass
# Trial 7: pass
# Trial 8: fail
# Trial 9: fail
# Trial 10: pass
# Vehicle lane follow test, zero-shot:
# Trial 1: fail
# Trial 2: pass
# Trial 3: pass
# Trial 4: pass
# Trial 5: pass
# Trial 6: pass
# Trial 7: fail
# Trial 8: pass
# Trial 9: fail
# Trial 10: pass
# Vehicle lane follow test, fine-tuned:
# Trial 1: pass
# Trial 2: pass
# Trial 3: pass
# Trial 4: pass
# Trial 5: pass
# Trial 6: pass
# Trial 7: fail
# Trial 8: pass
# Trial 9: pass
# Trial 10: fail
# Vehicle lane follow test, fine-tuned:
# Trial 1: pass
# Trial 2: pass
# Trial 3: pass
# Trial 4: pass
# Trial 5: pass
# Trial 6: pass
# Trial 7: fail
# Trial 8: pass
# Trial 9: pass
# Trial 10: fail
# Vehicle obstacle test, fine-tuned:
# Trial 1: fail
# Trial 2: fail
# Trial 3: pass
# Trial 4: fail
# Trial 5: fail
# Trial 6: fail
# Trial 7: fail
# Trial 8: pass
# Trial 9: fail
# Trial 10: fail