carla 代码运行逻辑混乱的笔记1

2018 年 3 月 3 日 CreateAMind

carla 模仿学习代码  https://github.com/carla-simulator/imitation-learning,代码跳转自己查源代码即可。



carla 模仿学习代码  https://github.com/carla-simulator/imitation-learning,代码跳转自己查源代码即可。

run_CIL.py

agent = ImitationLearning(args.city_name) 定义agent。
while True:
   try:
       with
make_carla_client(args.host, args.port) as client:
           
corl = CoRL2017(args.city_name, args.log_name)

           results = corl.benchmark_agent(agent, client)
           corl.plot_summary_test()
           corl.plot_summary_train()

           break

到了carla python client

class CoRL2017(Benchmark):
class Benchmark(object):
def benchmark_agent(self, agent, carla):
# running the agent
(result, reward_vec, final_time, remaining_distance) = \
   self.run_navigation_episode(
       agent, carla, time_out, positions[end_point],
       str(experiment.Conditions.WeatherId) + '_'
   
+ str(experiment.id) + '_' + str(start_point)
   + '.' + str(end_point))
def run_navigation_episode(
       self,
       agent,
       carla,
       time_out,
       target,
       episode_name):
control = agent.run_step(measurements, sensor_data, target)

imitation_learning.py

def run_step(self, measurements, sensor_data, target):

   
direction = self._planner.get_next_command(
       (measurements.player_measurements.transform.location.x,
        measurements.player_measurements.transform.location.y, 22),
       (measurements.player_measurements.transform.orientation.x,
        measurements.player_measurements.transform.orientation.y,
        measurements.player_measurements.transform.orientation.z),
       (target.location.x, target.location.y, 22),
       (target.orientation.x, target.orientation.y, -0.001))
   ###上面的direction就是计算出 下面数字代表的执行含义
#REACH_GOAL = 0.0  
#GO_STRAIGHT = 5.0   运行指令的定义
#TURN_RIGHT = 4.0
#TURN_LEFT = 3.0
#LANE_FOLLOW = 2.0

   control = self._compute_action(sensor_data['CameraRGB'].data,
                                  measurements.player_measurements.forward_speed, direction)
   return control
class Agent(object):
   def
__init__(self, city_name):
       
self.__metaclass__ = abc.ABCMeta
       self._planner = Planner(city_name) #agent的路径规划
class Planner(object):  路径规划

   def
__init__(self, city_name):

       
self._city_track = city_track.CityTrack(city_name)

       self._commands = []

   def get_next_command(self, source, source_ori, target, target_ori):


接着 run_step

def _compute_action(self, rgb_image, speed, direction=None):

   
rgb_image = rgb_image[self._image_cut[0]:self._image_cut[1], :]
   #视觉感知的指令转换生成。
   image_input = scipy.misc.imresize(rgb_image, [self._image_size[0],
                                                 self._image_size[1]])

   image_input = image_input.astype(np.float32)
   image_input = np.multiply(image_input, 1.0 / 255.0)

   steer, acc, brake = self._control_function(image_input, speed, direction, self._sess)


def _control_function(self, image_input, speed, control_input, sess):

   
branches = self._network_tensor
   x = self._input_images
   dout = self._dout
   input_speed = self._input_data[1]


   image_input = image_input.reshape((1, self._image_size[0], self._image_size[1], self._image_size[2]))

   # Normalize with the maximum speed from the training set ( 90 km/h)
   
speed = np.array(speed / 90.0)

   speed = speed.reshape((1, 1))

   if control_input == 2 or control_input == 0.0:
       
all_net = branches[0]
   elif control_input == 3:
       
all_net = branches[2]
   elif control_input == 4:
       
all_net = branches[3]
   else:
       
all_net = branches[1]

   print control_input

   
feedDict = {x: image_input, input_speed: speed, dout: [1] * len(self.dropout_vec)}

   output_all = sess.run(all_net, feed_dict=feedDict)  神经网络从图片预测动作指令

   predicted_steers = (output_all[0][0])

   predicted_acc = (output_all[0][1])

   predicted_brake = (output_all[0][2])


   return predicted_steers, predicted_acc, predicted_brake
def run_navigation_episode(
       self,
       agent,
       carla,
       time_out,
       target,
       episode_name):

   
measurements, sensor_data = carla.read_data()
   carla.send_control(VehicleControl())

   t0 = measurements.game_timestamp
   t1 = t0
   success = False
   
measurement_vec = []
   frame = 0
   
distance = 10000

   
while(t1 - t0) < (time_out * 1000) and not success:
       
measurements, sensor_data = carla.read_data()

       control = agent.run_step(measurements, sensor_data, target)

       logging.info("Controller is Inputting:")
       logging.info('Steer = %f Throttle = %f Brake = %f ',
                    control.steer, control.throttle, control.brake)

       carla.send_control(control)



命令行相关输出log

INFO:  START 

DEBUG: (localhost:2001) connected

DEBUG: (localhost:2002) connected

INFO: ======== !!!! ==========

INFO:  Start Position 36 End Position 40 

def _poses_town01(self):
   def _poses_straight():
       return [[36, 40],

server start cmd  /home/sdc/jeven/Carla/CarlaUE4.sh /Game/Maps/Town01 -carla-server -benchmark -fps=8 -opengl3  -windowed -ResX=800 -ResY=600


2.0 from imitation learning

INFO: Controller is Inputting:

INFO: Steer = 0.003305 Throttle = 0.500242 Brake = 0.000000 

INFO: Status:

INFO: [d=24482.228564] c_x = 27635.406250, c_y = 32699.283203 ---> t_x = 8861.999023, t_y = 16985.000000


INFO: +++++ Target achieved in 18.125000 seconds! +++++


if(result > 0):
   logging.info('+++++ Target achieved in %f seconds! +++++',
         final_time)


planner class

log:

2.0 from imitation step direction

2.0 from imitation learning

INFO: Controller is Inputting:

INFO: Steer = -0.003242 Throttle = 0.501970 Brake = 0.000000 

INFO: Status:

INFO: [d=28025.629564] c_x = 32063.615234, c_y = 32705.080078 ---> t_x = 8861.999023, t_y = 16985.000000

location: (32038.08984375, 32705.1484375, 22) (8861.9990234375, 16985.0, 22)

route: [(38, 40), (37, 40), (36, 40), (35, 40), (34, 40), (33, 40), (32, 40), (31, 40), (30, 40), (29, 40), (28, 40), (27, 40), (26, 40), (25, 40), (24, 40), (23, 40), (22, 40), (21, 40), (20, 40), (19, 40), (18, 40), (17, 40), (16, 40), (15, 40), (14, 40), (13, 40), (12, 40), (11, 40), (10, 40), (9, 40), (8, 40), (7, 40), (6, 40), (5, 40), (4, 40), (3, 40), (2, 40), (1, 40), (0, 40), (0, 39), (0, 38), (0, 37), (0, 36), (0, 35), (0, 34), (0, 33), (0, 32), (0, 31), (0, 30), (0, 29), (0, 28), (0, 27), (0, 26), (0, 25), (0, 24), (0, 23), (0, 22), (0, 21), (0, 20), (0, 19), (0, 18), (0, 17), (0, 16), (0, 15), (0, 14), (0, 13), (0, 12), (0, 11), (0, 10), (0, 9), (0, 8), (0, 7), (0, 6), (0, 5), (0, 4), (0, 3), (0, 2), (0, 1), (0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0), (11, 0), (11, 1), (11, 2), (11, 3), (11, 4), (11, 5), (11, 6), (11, 7), (11, 8), (11, 9), (11, 10), (11, 11), (11, 12), (11, 13), (11, 14), (11, 15), (11, 16), (11, 17), (11, 18), (11, 19), (11, 20)]

routenow--:past,current,future (12, 40) (11, 40) (10, 40)

routenow--:past,current,future (10, 0) (11, 0) (11, 1)

routenow--:past,current,future (11, 6) (11, 7) (11, 8)

routenow--:past,current,future (11, 15) (11, 16) (11, 17)

commands_list [5.0, 4.0, 5.0, 5.0]

command: 5.0 [5.0, 4.0, 5.0, 5.0]

5.0 from imitation step direction

5.0 from imitation learning

INFO: Controller is Inputting:

INFO: Steer = 0.003829 Throttle = 0.575784 Brake = 0.000000 

INFO: Status:

INFO: [d=28004.539857] c_x = 32038.089844, c_y = 32705.148438 ---> t_x = 8861.999023, t_y = 16985.000000

5.0 from imitation step direction

5.0 from imitation learning




INFO:  START--benchmark-zdx78523 

pose [36, 40]

positions[pose[1]] location {   ##位置定义与实际场景位置是通过positions函数进行转换的。

  x: 155.999511719

  y: 4870.00195312

  z: 3943.0625


INFO: ======== !!!! ==========

INFO:  Start Position 36 End Position 40 

target,target.location.x, target.location.y location {

  x: 155.999511719

  y: 4870.00195312

  z: 3943.0625

}

orientation {

。。。。。。。。。。。。。。。。。。。

INFO: [d=7132.000000] c_x = 155.999023, c_y = 12002.001953 ---> t_x = 155.999512, t_y = 4870.001953

target,target.location.x, target.location.y location {



def _poses_town01(self):
"""
   Each matrix is a new task. We have all the four tasks

   """
   def _poses_straight():
return [[36, 40], [39, 35], [110, 114], [7, 3], [0, 4],
[68, 50], [61, 59], [47, 64], [147, 90], [33, 87],
[26, 19], [80, 76], [45, 49], [55, 44], [29, 107],
[95, 104], [84, 34], [53, 67], [22, 17], [91, 148],
[20, 107], [78, 70], [95, 102], [68, 44], [45, 69]]

def _poses_one_curve():
return [[138, 17], [47, 16], [26, 9], [42, 49], [140, 124],
[85, 98], [65, 133], [137, 51], [76, 66], [46, 39],
[40, 60], [0, 29], [4, 129], [121, 140], [2, 129],
[78, 44], [68, 85], [41, 102], [95, 70], [68, 129],
[84, 69], [47, 79], [110, 15], [130, 17], [0, 17]]

def _poses_navigation():
return [[105, 29], [27, 130], [102, 87], [132, 27], [24, 44],
[96, 26], [34, 67], [28, 1], [140, 134], [105, 9],
[148, 129], [65, 18], [21, 16], [147, 97], [42, 51],
[30, 41], [18, 107], [69, 45], [102, 95], [18, 145],
[111, 64], [79, 45], [84, 69], [73, 31], [37, 81]]

return [_poses_straight(),
#_poses_one_curve(),
           _poses_navigation(),
_poses_navigation()]

for
pose in experiment.poses[start_pose:]:
for rep in range(experiment.repetitions):
print "pose",pose
print "positions[pose[1]]",positions[pose[1]]

start_point = pose[0]
end_point = pose[1]

carla.start_episode(start_point)

logging.info('======== !!!! ==========')
logging.info(' Start Position %d End Position %d ',
start_point, end_point)

path_distance = agent.get_distance(
positions[start_point], positions[end_point])
euclidean_distance = \
sldist([positions[start_point].location.x, positions[start_point].location.y],
[positions[end_point].location.x, positions[end_point].location.y])

time_out = self._calculate_time_out(path_distance)
# running the agent
       (result, reward_vec, final_time, remaining_distance) = \
self.run_navigation_episode(
agent, carla, time_out, positions[end_point],


if (self._city_track.is_at_new_node(track_source)
and self._city_track.is_away_from_intersection(track_source)):
print "location:",source,target
route = self._city_track.compute_route(track_source, source_ori,
track_target, target_ori)
if route is None:
raise RuntimeError('Impossible to find route')
print "route:",route
self._commands = self._route_to_commands(route)
print "command:",self._commands[0],self._commands
if self._city_track.is_far_away_from_route_intersection(



简单梳理了一些carla客户端的运行逻辑。



登录查看更多
5

相关内容

CoRL的全程为Conference on Robot Learning(机器人学习大会),CoRL是一个新的以机器人学和机器学习为主题的年度国际会议。大会的组织者包括来自UC Berkrley、Google、Microsoft、CMU、MIT、ETH、Deepmind等知名院校和知名企业的研究者和从业者,同时CoRL大会的举办还得到了机器人国际机构“三巨头”之一的国际机器人研究基金会(IFRR)和机器学习领域最好的期刊之一JMLR(Journal of Machine Learning Research)的支持。
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
《代码整洁之道》:5大基本要点
专知会员服务
49+阅读 · 2020年3月3日
深度强化学习策略梯度教程,53页ppt
专知会员服务
176+阅读 · 2020年2月1日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
【书籍】深度学习框架:PyTorch入门与实践(附代码)
专知会员服务
160+阅读 · 2019年10月28日
MIT新书《强化学习与最优控制》
专知会员服务
270+阅读 · 2019年10月9日
【初学者系列】tensorboard学习笔记
专知
7+阅读 · 2019年10月4日
PLANET+SAC代码实现和解读
CreateAMind
3+阅读 · 2019年7月24日
谷歌足球游戏环境使用介绍
CreateAMind
31+阅读 · 2019年6月27日
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
Github项目推荐 | GAN评估指标的Tensorflow简单实现
AI研习社
16+阅读 · 2019年4月19日
如何编写完美的 Python 命令行程序?
CSDN
5+阅读 · 2019年1月19日
利用 TensorFlow 实现排序和搜索算法
机器学习研究会
5+阅读 · 2017年11月23日
tensorflow系列笔记:流程,概念和代码解析
北京思腾合力科技有限公司
30+阅读 · 2017年11月11日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
Arxiv
3+阅读 · 2019年3月1日
Arxiv
3+阅读 · 2018年12月18日
VIP会员
相关VIP内容
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
《代码整洁之道》:5大基本要点
专知会员服务
49+阅读 · 2020年3月3日
深度强化学习策略梯度教程,53页ppt
专知会员服务
176+阅读 · 2020年2月1日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
【书籍】深度学习框架:PyTorch入门与实践(附代码)
专知会员服务
160+阅读 · 2019年10月28日
MIT新书《强化学习与最优控制》
专知会员服务
270+阅读 · 2019年10月9日
相关资讯
【初学者系列】tensorboard学习笔记
专知
7+阅读 · 2019年10月4日
PLANET+SAC代码实现和解读
CreateAMind
3+阅读 · 2019年7月24日
谷歌足球游戏环境使用介绍
CreateAMind
31+阅读 · 2019年6月27日
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
Github项目推荐 | GAN评估指标的Tensorflow简单实现
AI研习社
16+阅读 · 2019年4月19日
如何编写完美的 Python 命令行程序?
CSDN
5+阅读 · 2019年1月19日
利用 TensorFlow 实现排序和搜索算法
机器学习研究会
5+阅读 · 2017年11月23日
tensorflow系列笔记:流程,概念和代码解析
北京思腾合力科技有限公司
30+阅读 · 2017年11月11日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
Top
微信扫码咨询专知VIP会员