Use Carla simulator to create synthetic road images that can be used to train object detectors
The instructions below assume that you installed everything in the root directory, which means
~/carla
~/UnrealEngine_4.24
~/simulation4detection_v2
If you installed anything elsewhere, be sure to swap in the correct directory paths.
Before launch the Unreal Engine editor, choose which town/map to load, specifically:
Open the file DefaultEngine.ini in ~/carla/Unreal/CarlaUE4/Config/DefaultEngine.ini
.
Inside the file, change the town numbers in the following lines:
EditorStartupMap=/Game/Carla/Maps/Town01.Town01
GameDefaultMap=/Game/Carla/Maps/Town01.Town01
ServerDefaultMap=/Game/Carla/Maps/Town01.Town01
TransitionMap=/Game/Carla/Maps/Town01.Town01
*these lines are listed in commit df83fb53.
Launch the Unreal Engine editor
$ cd ~/carla
$ make launch
Add Fire Hydrants onto the map
Content/carla/Static
. FireHydrants
. The name must be FireHydrants because the Python client will use this folder name to tag fire hydrant objects.FireHydrants
folder.Configure the PythonAPI to recognize Fire Hydrants. According to Carla.org documentation: "Adding new tags: At the moment adding new tags is not very flexible and requires to modify the C++ code. Add a new label to the ECityObjectLabel enum in Tagger.h, and its corresponding filepath check inside GetLabelByFolderName() function in Tagger.cpp."
~/carla
directory. $ cd ~/carla
$ make LibCarla
$ make PythonAPI.3
$ pip3 uninstall carla
$ cp PythonAPI/carla/dist/carla-0.9.9-py3.6-linux-x86_64.egg ~/simulation4detection_v2/carla/PythonAPI/carla/dist/carla-0.9.9-py3-linux-x86_64.egg
Click Play button at the top tool bar in Unreal Engine.
Launch Python Agent to collect data
$ cd ~/simulation4detection_v2/carla/PythonAPI
$ python3 examples/collectData.py
A window will open with the agent's camera view. At the same time two new folders _out_rgb
and _out_seg
are created, where the output camera images will be stored.
Install CUDA 11.0
$ cd ~/Desktop
$ wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run
$ sudo sh cuda_11.0.2_450.51.05_linux.run
$ vim ~/.bashrc
# Copy paste the following
export PATH=/usr/local/cuda-11.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.0/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-11.0/lib64
Install Nvidia Driver 450
Check installation
$ nvcc --version # should display 11.0
$ nvidia-smi # should display CUDA 11.0 and Nvidia driver 450
Install PyTorch
$ pip3 install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Install Detectron2
$ cd ~/Desktop
$ git clone https://github.com/facebookresearch/detectron2.git
$ python3 -m pip install -e detectron2
Run main scripts
simulation4detection_v2/detectron2/main.py
as needed
$ cd ~/simulation4detection_v2/detectron2
$ python3 main.py