Use Carla simulator to create synthetic road images that can be used to train object detectors
- Notes and Disclaimers
- Steps to run this project
- Install everything and test the installation
- Set up and launch the Carla simulator server in Unreal Engine
- Prepare and connect the Python client, and Collect Data
- Train the model with data collected from step 3
-
This project is developed on Linux system, Ubuntu 18.04.3 LTS to be specific.
-
The instructions below assume that you installed everything in the root directory, which means
- the carla directory is at
~/carla
- the Unreal Engine is at
~/UnrealEngine_4.24
- this repo simulation4detection_v2 is at
~/simulation4detection_v2
If you installed anything elsewhere, be sure to swap in the correct directory paths.
- the carla directory is at
-
Prepare up to 100 GB in the directory where you wish to store this entire project.
-
We are using Carla 0.9.6 and Unreal Engine 4.22. For the latest and the greatest, please checkout the official Carla Document How to build the latest CARLA in Linux.
- Follow the instructions to Install Carla Simulator 0.9.9 and Unreal Engine 4.22.
- Test connecting a Python client with the carla simulator, by following the instructions for using a Python client to control the Carla simulator
-
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
- Open a terminal window and run
$ cd ~/carla $ make launch
- Open a terminal window and run
-
Add Fire Hydrants onto the map
- At the bottom of the Unreal Engine Editor, you will find the Content Browser section.
- Navigate to path
Content/carla/Static
. - Once you are in the Static folder, click the green Add New button and click New Folder. Name the folder
FireHydrants
. The name must be FireHydrants because the Python client will use this folder name to tag fire hydrant objects. - Navigate into this
FireHydrants
folder. - Click Import and find the fire hydrant mesh inside this directory.
- Now your content browser should look like this
- Drag the mesh onto the map and place them to the desired Locations.
- Here is a detailed instruction for reconstructing 3D object.
-
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."
- Follow commit c46e8970 and change the tagger.h, tagger.cpp and CityScapesPalette.h files in
~/carla
directory. - Update the installed Carla Python API.
$ 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
- After this step, the Carla segmentation camera will only detect fire hydrants in orange RGB(220, 110, 0). All other objects will be black.
- Follow commit c46e8970 and change the tagger.h, tagger.cpp and CityScapesPalette.h files in
-
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
- Select Linux -> x86_64 -> Ubuntu -> 18.04 -> runfile(local) (Might be different depend on machine configuration)
$ 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
- Select Continue -> type accept -> select only CUDA 11.0 (deselect all other options)
- Add CUDA to system PATH
$ 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
- Log out and log back in
-
Install Nvidia Driver 450
- Open Software & Updates
- Go to tab Additional Drivers
- Select Nvidia Driver 450
- Apply changes
-
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
- Edit
simulation4detection_v2/detectron2/main.py
as needed
$ cd ~/simulation4detection_v2/detectron2 $ python3 main.py
- Edit