Skip to content

Commit

Permalink
Merge pull request carla-simulator#2 from intel-sandbox/enable_tracking
Browse files Browse the repository at this point in the history
Enable object tracking scenario and add kwcoco/MOTS annotations
  • Loading branch information
sissiok committed Mar 28, 2022
2 parents 0600301 + 9fd8ddf commit ce4ec31
Show file tree
Hide file tree
Showing 12 changed files with 905 additions and 384 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## Latest
* Added native ackermann controller:
- `apply_ackermann_control`: to apply an ackermann control command to a vehicle
- `get_ackermann_controller_settings`: to get the last ackermann controller settings applied
- `apply_ackermann_controller_settings`: to apply new ackermann controller settings
* Fixed bug causing the Traffic Manager to not be deterministic when using hybrid mode
* Added `NormalsSensor`, a new sensor with normals information
* Added support for N wheeled vehicles

## CARLA sissiok:data_collector
* Added a data collection tool
- `carla_data_saver.py`: saves sensor data and simulation metadata. Can be used for generate synthetic object detection and tracking datasets.
- `carla_annotator.py`: generates annotations in kwcoco format and MOTS format for camera images saved by `carla_data_saver.py`
- `Dockerfile`: builds a docker image for CARLA client upon the current CARLA docker image which only supports CARLA server.

## CARLA 0.9.13

* Added new **instance aware semantic segmentation** sensor `sensor.camera.instance_segmentation`
Expand Down
24 changes: 24 additions & 0 deletions PythonAPI/util/data_collector/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022 Intel Corporation.
#
# SPDX-License-Identifier: MIT

FROM carlasim/carla:0.9.13
USER root
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y libjpeg-dev libtiff-dev
RUN apt-get install -y python3.7 python3.7-dev python3-distutils
RUN apt-get install -y python3-pip
RUN apt-get install -y git
RUN apt-get install -y xdg-user-dirs xdg-utils
RUN apt-get install -y fontconfig
RUN apt-get install -y zip
RUN apt-get clean
USER carla
RUN python3.7 -m pip install Cython
RUN python3.7 -m pip install --upgrade pip
RUN python3.7 -m pip install -r /home/carla/PythonAPI/examples/requirements.txt
COPY requirements.txt /tmp/requirements.txt
RUN python3.7 -m pip install -r /tmp/requirements.txt
ENV PYTHONPATH "${PYTHONPATH}:/home/carla/PythonAPI/carla/dist/carla-0.9.13-py3.7-linux-x86_64.egg"
WORKDIR /home/carla
76 changes: 76 additions & 0 deletions PythonAPI/util/data_collector/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
DATASETS ?= /datasets/data_collector
PORT := $(shell seq 49152 65535 | shuf | head -n1)
TM_PORT := $(shell echo "$(PORT) + 2" | bc)
CARLA_QUALITY_LEVEL ?= Epic
CONFIG_FILE ?= config_tracking
TRACKING_FORMAT ?= mots_png
TRACKING_LABELS ?= Pedestrian
NV_GPU ?= "device=0"
UUID := $(shell uuidgen)
PYTHON = python3.7

DOCKER_TAG ?= carla-client:0.9.13
DOCKER_OPTIONS += --rm
DOCKER_OPTIONS += --net=host
DOCKER_OPTIONS += --volume $(shell pwd)\:/home/carla/PythonAPI/util/data_collector\:ro
DOCKER_OPTIONS += --volume $(DATASETS)\:$(DATASETS)\:rw
DOCKER_OPTIONS += --gpus $(NV_GPU)
DOCKER_RUN = docker run $(DOCKER_OPTIONS) $(DOCKER_TAG)
DOCKER_RUND = docker run -d $(DOCKER_OPTIONS) --name $(UUID) $(DOCKER_TAG)

# Taken from https://tech.davis-hansson.com/p/make/
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
endif
.RECIPEPREFIX = >

# Taken from https://suva.sh/posts/well-documented-makefiles/
.PHONY: help
help: ## Display this help
> @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[1-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-36s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

#
# General Targets
#
.PHONY: docker_image
docker_image: Dockerfile requirements.txt ## Build docker image
> docker build -f $< -t $(DOCKER_TAG) .

.PHONY: kill_carla_servers
kill_carla_servers: ## Kill all CARLA server docker instances
> docker ps --filter="ancestor=carla-client:0.9.13" -q | xargs docker kill


.PHONY: clean_annotations
clean_annotations: ## Clean existing annotations
> @echo "Clearing annotations "
> $(DOCKER_RUN) rm -rf $(DATASETS)/*/*/kwcoco_annotations.json
> $(DOCKER_RUN) rm -rf $(DATASETS)/*/*/instances*

.PHONY: clean
clean: ## Clean all directories
> @echo "Clearing all directories"
> $(DOCKER_RUN) rm -rf $(DATASETS)/*

$(DATASETS)/%.yaml: ## Run data collection with specified configuration
> $(DOCKER_RUND) /bin/bash ./CarlaUE4.sh -RenderOffScreen -carla-port=$(PORT) -quality-level=$(CARLA_QUALITY_LEVEL)
> while ! nc -z localhost $(PORT); do sleep 1; done
> $(DOCKER_RUN) $(PYTHON) PythonAPI/util/data_collector/carla_data_saver.py --config-name $(@F) carla.port=$(PORT) carla.traffic_manager_port=$(TM_PORT) hydra.run.dir="$(@D)/$*/$(UUID)"
> docker ps --quiet --filter="name=$(UUID)" -q | xargs docker kill

.PRECIOUS: $(DATASETS)/$(CONFIG_FILE)/%/collection_done
$(DATASETS)/$(CONFIG_FILE)/%/collection_done: ## Run data collection with config_tracking configuration
> $(DOCKER_RUND) /bin/bash ./CarlaUE4.sh -RenderOffScreen -carla-port=$(PORT) -quality-level=$(CARLA_QUALITY_LEVEL)
> while ! nc -z localhost $(PORT); do sleep 1; done
> $(DOCKER_RUN) $(PYTHON) PythonAPI/util/data_collector/carla_data_saver.py --config-name $(CONFIG_FILE).yaml carla.port=$(PORT) carla.traffic_manager_port=$(TM_PORT) hydra.run.dir="$(@D)"
> docker ps --quiet --filter="name=$(UUID)" -q | xargs docker kill
> $(DOCKER_RUN) /bin/bash -c "echo $(UUID) > $@"

.PRECIOUS: $(DATASETS)/%/kwcoco_annotations.json ## Generate kwcoco annotations
$(DATASETS)/%/kwcoco_annotations.json: $(DATASETS)/%/collection_done
> $(DOCKER_RUN) $(PYTHON) PythonAPI/util/data_collector/carla_annotator.py --format $(TRACKING_FORMAT) --output $@ --dataset_parent_dir $(@D) --labels $(TRACKING_LABELS)

.PRECIOUS: $(DATASETS)/%/instances.zip ## Generate annotation in MOTS format
$(DATASETS)/%/instances.zip: $(DATASETS)/%/collection_done
> $(DOCKER_RUN) $(PYTHON) PythonAPI/util/data_collector/carla_annotator.py --format $(TRACKING_FORMAT) --output $(@D)/instances --dataset_parent_dir $(@D) --labels $(TRACKING_LABELS)
> $(DOCKER_RUN) /bin/bash -c "cd $(@D) ; zip -r instances.zip instances"
Loading

0 comments on commit ce4ec31

Please sign in to comment.