Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download script for CarlaGear #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ the ego-vehicle has a single gear.
This problem is discussed in [this issue](https://github.com/carla-simulator/carla/issues/269).

The server can be dowloaded with [this link](https://drive.google.com/open?id=1X52PXqT0phEi5WEWAISAQYZs-Ivx4VoE).
Alternatively, you can download it by running:

python3 tools/download_carla_gear.py

It is possible to collect data on a regular CARLA version,
however the controller will be less smooth.
Expand Down
61 changes: 61 additions & 0 deletions tools/download_carla_gear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import requests
import os
import sys

from zipfile import ZipFile


def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params={'id': id}, stream=True)
token = get_confirm_token(response)

if token:
params = {'id': id, 'confirm': token}
response = session.get(URL, params=params, stream=True)

save_response_content(response, destination)


def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value

return None


def save_response_content(response, destination):
CHUNK_SIZE = 32768
total_downloaded = 0
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
total_downloaded += CHUNK_SIZE
sys.stdout.write("Downloaded " + str(total_downloaded))
sys.stdout.flush()
sys.stdout.write("\r")
f.write(chunk)


if __name__ == "__main__":
# Download the datasets
file_id = '1X52PXqT0phEi5WEWAISAQYZs-Ivx4VoE'
destination_pack = 'CarlaGear.zip'

print("Downloading Carla Server (1.6GB total)")
download_file_from_google_drive(file_id, destination_pack)
destination_final = os.path.join("./CarlaServer/",)
if not os.path.exists(destination_final):
os.makedirs(destination_final)

print("Unpacking the dataset")

with ZipFile(destination_pack, 'r') as zip:
# extracting all the files
print('Extracting all the files now...')
zip.extractall(destination_final)
print('Done!')

os.remove("CarlaGear.zip")