学习笔记(二)Learning High-Speed Flight in the Wild 修改策略

一、README.md 该部分内容

—————————————————————————————————————————————————
一、改变执行速度或环境
You can change the average speed at which the policy will fly as well as the environment type by changing the following files.
您可以通过更改以下文件来更改策略的平均运行速度以及环境类型。
Environment Change
环境变化

rosed agile_autonomy flightmare.yaml

Set either the spawn_trees or spawn_objects to true. Doing both at the same time is possible but would make the environment too dense for navigation. Also adapt the spacings parameter in test_settings.yaml to the environment.
spawn_treesspawn_objects设置为true。同时进行这两项工作是可能的,但会使环境过于密集,无法进行导航。还要根据环境调整test_settings.yaml中的间距参数。
Speed Change:
速度变化:
Edit the test_time_velocity and maneuver_velocity to the required speed. Note that the ckpt we provide will work for all speeds in the range [1,10] m/s. However, to reach the best performance at a specific speed, please consider finetuning the ckpt at the desired speed (see code below).
将“test_time_velocity”和“maneuver_velocity”编辑为所需速度。注意,我们提供的CKPT将在[1,10] m/s范围内的所有速度下工作。然而,为了达到特定速度的最佳性能,请考虑以期望的速度对CKPT进行精细化(见下面的代码)。
二、训练你自己的导航策略
There are two ways in which you can train your own policy. One easy and one more involved. The trained checkpoint can then be used to control a physical platform (if you have one!).
有两种方法可以训练你自己的政策。一个简单,另一个复杂。然后,可以使用经过培训的检查点来控制物理平台(如果有)。
1.Use pre-collected dataset
1.使用预先收集的数据集
The first method, requiring the least effort, is to use a dataset that we pre-collected. The dataset can be found at this link. This dataset was used to train the model we provide and collected at an average speed of 7 m/s. To do this, adapt the file train_settings.yaml to point to the train and test folder and run:
第一种方法,需要最少的努力,是使用我们预先收集的数据集。数据集可在此链接中找到。该数据集用于训练我们提供并以7 m/s的平均速度收集的模型。为此,调整文件train_settings.yaml,以指向train 和 test文件夹并运行:

cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
conda activate tf_24
cd /home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning
python train.py --settings_file=config/train_settings.yaml

Feel free to ablate the impact of each parameter!
请随意消除每个参数的影响!
2.Collect your own dataset
2.收集自己的数据集
You can use the following commands to generate data in simulation and train your model on it. Note that training a policy from scratch could require a lot of data, and depending on the speed of your machine this could take several days. Therefore, we always recommend finetuning the provided checkpoint to your use case. As a general rule of thumb, you need a dataset with comparable size to ours to train a policy from scratch, but only 1/10th of it to finetune.
可以使用以下命令在模拟中生成数据,并在其上训练模型。请注意,从头开始培训策略可能需要大量数据,根据机器的速度,这可能需要几天时间。因此,我们始终建议根据您的用例微调提供的检查点。一般来说,你需要一个与我们的数据集大小相当的数据集来从无到有地训练一个策略,但只有十分之一的数据集可以进行微调。
3.Generate data
3.生成数据
To train or finetune a policy, use the following commands: Launch the simulation in one terminal
要训练或微调策略,请使用以下命令:在一个终端中启动模拟

cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
roslaunch agile_autonomy simulation.launch

Launch data collection (with dagger) in an other terminal
在另一个终端启动数据采集(使用dagger)

cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
conda activate tf_24
cd /home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning
python dagger_training.py --settings_file=config/dagger_settings.yaml

It is possible to change parameters (number of rollouts, dagger constants, tracking a global trajectory, etc. ) in the file dagger_settings.yaml. Keep in mind that if you change the network or input, you will need to adapt the file test_settings.yaml for compatibility.
可以在文件dagger_settings.yaml 中更改参数(卷展栏数、dagger 常数、跟踪全局轨迹等)。请记住,如果更改网络或输入,则需要调整文件test_settings.yaml的兼容性。
When training from scratch, follow a pre-computed global trajectory to give consistent labels. To activate this, you need to put to true the flag perform_global_planning in default.yaml and label_generation.yaml. Note that this will make the simulation slower (a global plan has to be computed at each iteration). The network will not have access to this global plan, but only to the straight (possibly in collision) reference.
当从头开始训练时,遵循预先计算的全局轨迹,给出一致的标签。要激活此功能,您需要在默认情况下设置标志perform_global_planning,该标志位于default.yaml 和 label_generation.yaml。请注意,这将使模拟速度变慢(必须在每次迭代时计算全局计划)。网络将无法访问该全球计划,只能访问直接(可能发生冲突)参考。
4.Visualize the Data
4.将数据可视化
You can visualize the generated trajectories in open3d using the visualize_trajectories.py script.
可以使用visualize_trajectories.py脚本在open3d中可视化生成的轨迹。

python visualize_trajectories.py --data_dir /PATH/TO/rollout_21-09-21-xxxx --start_idx 0 --time_steps 100 --pc_cutoff_z 2.0 --max_traj_to_plot 100

The result should more or less look as the following
结果大致如下
在这里插入图片描述5.Test the Network
5.测试网络
To test the network you trained, adapt the test_settings.yaml with the new checkpoint path. You might consider putting back the flag perform_global_planning in default.yaml to false to make the simulation faster. Then follow the instructions in the above section (Let’s Fly!) to test.
要测试您培训的网络,请使用新的检查点路径调整“测试设置”。您可能会考虑将标志“PrPrimeGualAlgPayStudio”默认设置为false,以使模拟更快。然后按照上面部分的说明(让我们飞吧!)测试。
6.Ackowledgements
6.收购
We would like to thank Yunlong Song and Selim Naji for their help with the implementations of the simulation environment. The code for global planning is strongly inspired by the one of Search-based Motion Planning for Aggressive Flight in SE(3).
我们要感谢宋云龙和塞利姆·纳吉在模拟环境的实现方面提供的帮助。《全球规划代码》深受SE(3)中基于搜索的攻击性飞行运动规划的启发。
—————————————————————————————————————————————————

二、根据上述内容进行更改,查看变化

1.更改环境:
/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/data_generation/agile_autonomy/parameters路径内,找到flightmare.yaml文件,双击进行编辑。以下是该文件内容:

unity:
  spawn_trees: false # 这里是树林样式,该内容原本为ture,现设置为false,查看效果,就是之前默认产生的树林飞行路线。
  spawn_objects: ture # 这里原本是false,现设置为ture,即随机障碍物环境。
  perform_sgm: true
  seed: 69 # == 0: generate random seed, != 0: use this fixed random seed 随机种子,用于复现
  env_idx: 4 # 0 wasteland, 1 japanese street, 4 emptyforest in other standalone 
  # 0:荒地,1:日本街,4:空森林
  avg_tree_spacing: 4.0 # 这里还不清楚这个参数的作用
  avg_object_spacing: 5.0 # 这里还不清楚这个参数的作用
  rand_width: 5.0 # width of the uniform distribution that perturbs the regular spawning grid
  # 扰乱规则产卵网格的均匀分布的宽度
  object_names: ["Cylinder", "Cube"] # "Cylinder", "Cube",  "Sphere", "narrow_gap"
  bounding_box: [235.0, 235.0, 15.0] # spawn objects within this bounding box
  # 在此边界框内生成对象 即边界
  bounding_box_origin: [20.0, 0.0, 0.0] # relative to the quadrotor start position
  min_object_scale: [0.5, 0.5, 0.5]   # scale of objects in meters, will sample uniformly between bounds 以米为单位的对象比例将在边界之间均匀采样
  max_object_scale: [5.0, 5.0, 5]   # scale of objects in meters, will sample uniformly between bounds 以米为单位的对象比例将在边界之间均匀采样
  min_object_angles: [0.0, 0.0, 0.0]  # euler angles in degrees, will sample uniformly between bounds
  max_object_angles: [180.0, 180.0, 180.0]  # euler angles in degrees, will sample uniformly between bounds
  pointcloud_resolution: 0.2  # will be used for both above- and below-ground 将用于地上和地下
camera: # 摄像头 
  fov: 91.0 # horizontal FOV in degrees 水平视场(度)
  width: 640
  height: 480
  baseline: 0.1
  pitch_angle_deg: 0.0 # camera pitch angle in degrees 摄像机俯仰角(度)

1.1修改spawn_trees、spawn_objects:

spawn_trees: false
spawn_objects: ture

这里可以看到环境已经变化了
在这里插入图片描述信息窗口,提示error信息如下:
在这里插入图片描述该错误是由于从cuda版本与Nvidia driver 版本不匹配导致的,具体的信息可以查看这一篇文章,但是之前已经正常安装了Nvidia驱动与cuda,并且对应,现查看Nvidia版本:

nvidia-smi

输出如下:
在这里插入图片描述发现无法输出Nvidia驱动的信息,说明nvidia驱动由于某些原因,不能用了。该原因可能是ubuntu自动更新导致,所以安装完成ubuntu之后,应该首先关闭自动更新。
关闭自动更新:
在这里插入图片描述再重新安装一遍Nvidia驱动。驱动与ubuntu内核是对应的,自动更新后,内核可能发生变化,导致显卡驱动不能用。
在这里插入图片描述修改完成后,输出结果如下:
在这里插入图片描述成功解决。

1.2 修改env_idx

  env_idx: 4 # 0 wasteland, 1 japanese street, 4 emptyforest in other standalone 
  # 0:荒地,1:日本街,4:空森林

修改为0:
在这里插入图片描述在这里插入图片描述从这里可以发现,树木(障碍物)点云是生成在基础环境上的。基础环境由上述参数设定。

1.3 修改avg_tree_spacing

这个参数在修改的过程中,还没有发现区别。

1.4 修改Generate data中的内容

(1)设置/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/data_generation/agile_autonomy/parameters/default.yaml中:perform_global_planning设置为true
(2)设置/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/data_generation/traj_sampler/parameters/label_generation.yaml中:perform_global_planning设置为true
这紫色路径部分应该是生成的专家路径,是用来进行监督学习的部分。橙色部分路径是飞行器实际生成(飞行)的路线,或者是说在该环境下飞行器获得的最好路径。
在这里插入图片描述获取环境点云。这部分需要在Rivz部分勾选相关选项。
在这里插入图片描述在这里插入图片描述简单记录一下RViz面板的项功能:
Controller-MPC Path:选中之后会在飞行器世纪的运行轨迹后端显示预测路径。

Images:不同选项会在该界面显示不同的摄像头图像,如RGB或者深度图。
Trajectories-Raw Trajectories:会在每个选择节点显示不同的选择路径。实际飞行的路线就是从这些路径中选择出来的。
在这里插入图片描述

Trajectories-selected Trajectories:会给上述的路径的染上不同的颜色。具体颜色的含义目前还没有弄清。
其他的选项都是同理,都会产生一簇路径。
在这里插入图片描述
Trajectories-Planned Trajectories:从起点指向重点的路径。
GlobalPlanner-PointCloud2:环境点云
GlobalPlanner-ellpsoidArray:专家路径上的飞行器姿态
GlobalPlanner-Trajectory:专家路径
在这里插入图片描述

2、训练模型

由于电脑内存不够,将数据集存储在了移动硬盘内,这可能对于训练模型的速度有一定的影响。同时需要修改配置文件中的路径。
打开/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning/config中的train_settings.yaml 文件,该文件内容如下:

log_dir: '/tmp/train_straight_7ms'
quad_name: 'none'
odometry_topic: 'ground_truth/odometry'
rgb_topic: 'agile_autonomy/unity_rgb'
depth_topic: 'agile_autonomy/sgm_depth'
use_rgb: False # Use camera images
use_depth: True # Use depth images
state_dim: 3 # x,y,z
out_seq_len: 10 # Number of steps in the future to predict
predict_state_number: [] # Empty list means will predict all states in out_seq_len. Otherwise it will train only for the single state. Only supported mode is len(predict_state_number) == 1.
seq_len: 1 # Number of inputs to load in the last second
poly_coeff: 3 # Equivalent to poly order minus 1
img_width: 224
img_height: 224
future_time: 5.0 # in seconds, how much in the future to track the reference
modes: 3 # Modes of distribution
checkpoint:
  resume_training: False
  resume_file: ""
train:
  max_training_epochs: 150
  batch_size: 8
  freeze_backbone: False
  top_trajectories: 3
  summary_freq: 400
  data_save_freq: 15
  train_dir: "data/train"
  val_dir: "data/val"
  log_images: False
  save_every_n_epochs: 5
  ref_frame: 'bf'
  track_global_traj: False
inputs:
  position: False
  attitude: True
  bodyrates: True
  velocity_frame: 'bf'

将该文件内容中的train_dir以及val_dir文件分别指向下载的数据集中的agile_autonomy_dataset/data/train_all_7ms/train以及agile_autonomy_dataset/data/train_all_7ms/test 文件夹。

train_dir: "/media/pipiw/Passport/dataset/agile_autonomy_dataset/data/train_all_7ms/train"
val_dir: "/media/pipiw/Passport/dataset/agile_autonomy_dataset/data/train_all_7ms/test"

其他的内容都是与训练模型有关的参数,如batch_size、max_training_epochs等,可以根据自己的需求也进行相应的修改,这里不做更改。
打开新的终端,输入:

cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
conda activate tf_24
cd /home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning
python train.py --settings_file=config/train_settings.yaml

注意:训练部分可以不打开ROS仿真界面。
训练过程如下:
在这里插入图片描述从提示中可以看出,由于本机的GPU为GTX 1050,显存很小,这里提示说如果现存更大,训练速度会更快。但是该问题可以更改训练参数解决,但这样会使得训练速度更慢。所以在此不再训练,近进行到这一步为止。
同时可以看出训练的模型位于/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning/models文件夹中:
在这里插入图片描述出现的问题:
(1)无法找到位于硬盘中的文件夹
解决办法:是由于硬盘路径出现了空格符号,导致路径无法找到,通过更改硬盘名称解决。
(2)一些警告,如gast的警告:
解决办法:查阅资料可知是gast的版本问题,但是更改版本之后,导致tensorflow无法使用,再更改tensorflow版本之后,又出现了新的问题,所以最终没有理会这个警告。

3、获取模型数据

需要配置/home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning/config中的dagger_settings.yaml文件,该文件内容如下:

log_dir: '/tmp/train_7m_object_straight/'
quad_name: 'hummingbird'
odometry_topic: 'ground_truth/odometry'
rgb_topic: 'agile_autonomy/unity_rgb'
depth_topic: 'agile_autonomy/sgm_depth'
use_rgb: False # Use camera images
use_depth: True # Use depth images
state_dim: 3 # x,y,z
out_seq_len: 10 # Number of steps in the future to predict
future_time: 5.0 # in seconds, how much in the future to track the reference
predict_state_number: [ ] # Empty list means will predict all states in out_seq_len. Otherwise it will train only for the single state. Only supported mode is len(predict_state_number) == 1.
seq_len: 1 # History Len. Reactive (hist = 1) works best.
modes: 3 # Number of modes
img_width: 224
img_height: 224
data_generation:
  max_rollouts: 100
  train_every_n_rollouts: 10
  expert_folder: "../data_generation/data"
  increase_net_usage_every_n_rollouts: 10
checkpoint:
  resume_training: True
  resume_file: "models/ckpt-50"
train:
  max_training_epochs: 5
  batch_size: 8
  data_save_freq: 15
  top_trajectories: 3
  summary_freq: 400
  train_dir: "data/train"
  val_dir: "data/val" # you should fill this with some validation data
  log_images: False
  freeze_backbone: False
  save_every_n_epochs: 5
  ref_frame: 'bf'
  track_global_traj: False
  spacings: [6,5,4] # mt
test_time:
  execute_nw_predictions: True
  perform_inference: True # If `False` completely disables network forward passes
  accept_thresh: 0.9 # when ratio btw other and best score is larger than this, other trajectory will be sent as well.
  input_update_freq: 15 #Hz
  fallback_radius_expert: 10 #m distance to trajectory to switch back. Put to zero when training from scratch
  network_frequency: 15.0 #Hz
  crashed_thr: 0.20 # 10 cm from a point is crash
verbose: False # saving net inputs
inputs:
  position: False
  attitude: True
  bodyrates: True
  velocity_frame: 'bf'
  pitch_angle: 0
unity:
  random_seed: 0
  # x,y,z, yaw
  # forest
  unity_start_pos: [[-20.,20.,0.,0]]

运行过程如下:

cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
roslaunch agile_autonomy simulation.launch
cd agile_autonomy_ws
source catkin_aa/devel/setup.bash
conda activate tf_24
cd /home/pipiw/agile_autonomy_ws/catkin_aa/src/agile_autonomy/planner_learning
python dagger_training.py --settings_file=config/dagger_settings.yaml

运行过程如下:
在这里插入图片描述每次训练完成,都会生成一个文件,在data/train文件内。
打开收集到的文件,该文件内容如下:

在这里插入图片描述在这里插入图片描述该部分是深度图以及RGB图
在这里插入图片描述该部分是轨迹信息。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值