-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TDHTTTT/tony/resturcture
Tony/resturcture
- Loading branch information
Showing
13 changed files
with
1,053 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
__pycache__ | ||
output/ | ||
/data/ | ||
log/ | ||
*.swp | ||
.ipynb_checkpoints/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## DEMO | ||
|
||
### Automatically | ||
|
||
Many configurations can be customized (300 seconds simulation called demo-a with 5 ego cars and 300 NPC cars): | ||
```bash | ||
python3 generate_data.py --duration 300 --name demo-a --ego-cars 5 --npc-cars 300 | ||
``` | ||
|
||
The cameras' angle, location (wrt to the ego vehicle), orientation and resolution are fully configurable: | ||
```bash | ||
python3 generate_data.py --duration 300 --name demo-b --resolution-x 200 --resolution-y 100 --cam-yaw 90 --cam-pitch 10 --cam-z 1.4 --fov 115 | ||
``` | ||
|
||
### Manually | ||
|
||
Since Carla's builtin autopilot function is somewhat limited and if you might want to control the ego vehicle manually. | ||
|
||
First do | ||
```bash | ||
python3 manual_control.py --filter <EGO_CAR_TYPE> | ||
``` | ||
|
||
Then | ||
```bash | ||
python3 generate_data.py --duration 300 --name demo-c --debug 2 --npc-cars 10 --ego-cars 1 --ego-type <EGO_CAR_TYPE> | ||
``` |
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
|
||
while [[ "$#" -gt 0 ]]; do case $1 in | ||
-r|--remove-files) remove=1; shift;; | ||
-v|--verbose) verbose=1;; | ||
*) echo "Unknown parameter passed: $1"; exit 1;; | ||
esac; shift; done | ||
|
||
cat ../../data/*/*.csv > ../../data/all.csv | ||
|
||
if [ "$verbose" = "1" ] | ||
then | ||
read lines words chars <<< $(wc ../../data/all.csv) | ||
echo "Done!" | ||
echo "Total number of samples: $lines" | ||
fi | ||
|
||
if [ "$remove" = "1" ] | ||
then | ||
rm ../../data/*/*.csv | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import sys | ||
import os | ||
import numpy as np | ||
from pandas import read_csv | ||
from skimage import io, transform | ||
from torch.utils.data import Dataset | ||
|
||
value_range = [ | ||
(-0.5, 0.5), # angle | ||
(-7, -2.5), # toMarking_L | ||
(-2, 3.5), # toMarking_M | ||
( 2.5, 7), # toMarking_R | ||
( 0, 75), # dist_L | ||
( 0, 75), # dist_R | ||
(-9.5, -4), # toMarking_LL | ||
(-5.5, -0.5), # toMarking_ML | ||
( 0.5, 5.5), # toMarking_MR | ||
( 4, 9.5), # toMarking_RR | ||
( 0, 75), # dist_LL | ||
( 0, 75), # dist_MM | ||
( 0, 75), # dist_RR | ||
( 0, 1) # fast | ||
] | ||
|
||
min_nv = 0.1 | ||
max_nv = 0.9 | ||
|
||
def normalize(av): | ||
def f(v, r): | ||
v = float(v) | ||
min_v = float(r[0]) | ||
max_v = float(r[1]) | ||
v = (v - min_v) / (max_v - min_v) | ||
v = v * (max_nv - min_nv) + min_nv | ||
v = min(max(v, 0.0), 1.0) | ||
return v | ||
|
||
for (i, v) in enumerate(av): | ||
av[i] = f(v, value_range[i]) | ||
|
||
return av | ||
|
||
def denormalize(av): | ||
def f(v, r): | ||
v = float(v) | ||
min_v = float(r[0]) | ||
max_v = float(r[1]) | ||
v = (v - min_nv) / (max_nv - min_nv) | ||
v = v * (max_v - min_v) + min_v | ||
return v | ||
|
||
for (i, v) in enumerate(av): | ||
av[i] = f(v, value_range[i]) | ||
|
||
return av | ||
|
||
class CarlaDataset(Dataset): | ||
"""CARLA dataset.""" | ||
|
||
def __init__(self, csv_file, root_dir, valid, transform=None): | ||
self.metadata = read_csv(csv_file, header=None) | ||
self.root_dir = root_dir | ||
self.transform = transform | ||
self.valid = valid | ||
|
||
def __len__(self): | ||
return len(self.metadata) | ||
|
||
def __getitem__(self, idx): | ||
img_id = self.metadata.iloc[idx,0].split('-') | ||
img_name = os.path.join(self.root_dir, img_id[0], img_id[1], "{}.png".format(img_id[2])) | ||
image = io.imread(img_name) | ||
|
||
# Delete alpha channel | ||
if image.shape[-1] == 4: | ||
image = np.delete(image, 3, 2) | ||
|
||
# Scale to 280x210 | ||
image = transform.resize(image, (210, 280, 3), mode='constant', anti_aliasing=True) | ||
|
||
# Make it CHW | ||
image = image.transpose(2, 0, 1).astype('float32') | ||
|
||
av = self.metadata.iloc[idx,1:].values | ||
av = av.astype('float32') | ||
av = av[self.valid] | ||
av = normalize(av) | ||
sample = {'image': image, 'affordance_vector': av} | ||
|
||
if self.transform: | ||
sample = self.transform(sample) | ||
|
||
return sample | ||
|
Oops, something went wrong.