CARLA教程-01-环境准备
01 环境准备
1.1 系统
- Ubuntu 22.04(CARLA 0.9.16 官方测试版本;不建议 24.04)
- 内存:建议 32GB+(UE4+CARLA 编译和运行较吃内存)
- 磁盘:约 130GB(UE4 ~91GB + CARLA ~31GB + 模型/依赖)
- GPU:NVIDIA,显存 8GB+(本教程环境为 16GB)
1.2 GPU 驱动与 CUDA
安装 NVIDIA 驱动(570+)和 CUDA 12.8(与 TensorRT 版本匹配)。验证:
1 | nvidia-smi # 应显示驱动版本和 CUDA Version: 12.8 |
1.3 TensorRT
安装 TensorRT 10.9(本教程使用,用于 rf-DETR 推理)。假设安装在 /opt/TensorRT-10.9.0.34。
把 Python 绑定装到系统 python3(不是 conda),并加环境变量到 ~/.bashrc / ~/.zshrc:
1 | # 安装 tensorrt python 绑定 (cp310 对应 python3.10) |
验证(系统 python):
1 | /usr/bin/python3 -c "import tensorrt; print(tensorrt.__version__)" # 10.9.0.34 |
⚠️ 关键:检测节点用系统 python 跑(rclpy 是系统 python),所以 torch、tensorrt、cv_bridge 都要装在系统 python,不要装在 conda。否则 ROS2 会因找不到 ros2cli 等包而崩溃。
1.4 ROS2 Humble
按官方文档安装 ROS2 Humble(desktop full)。验证:
1 | source /opt/ros/humble/setup.zsh |
额外安装感知相关包:
1 | sudo apt install ros-humble-cv-bridge ros-humble-vision-msgs \ |
1.5 conda + CARLA Python 客户端环境
创建一个 conda 环境专门给 CARLA Python 客户端用:
1 | conda create -n carla python=3.10 -y |
这个环境只用于跑 CARLA 自带的 Python 脚本(generate_traffic.py 等),不参与 ROS2/检测。
1.6 系统依赖(CARLA 编译用)
1 | sudo apt-get update |
1.7 检测/跟踪模型仓库
准备两个模型仓库(克隆或下载):
- rf-DETR:
~/models/rf-detr(需要其中的weights/onnx/rfdetr-medium.engine) - OC-SORT:
~/models/OC_SORT
OC-SORT 的 Python 依赖 filterpy 需装到系统 python:
1 | /usr/bin/python3 -m pip install filterpy |
1.8 验证系统 python 依赖齐全
1 | /usr/bin/python3 -c "import torch, tensorrt, cv2, numpy, rclpy, cv_bridge, filterpy; print('all OK')" |
应输出 all OK(torch 来自 CUDA 安装,其余按上面装)。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 TeachCraft Blog!
评论