pip package
Browse files
comma_car_segments/__init__.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Forks with additional car support can fork the commaCarSegments repo on huggingface or host the LFS files themselves
|
| 6 |
+
COMMA_CAR_SEGMENTS_REPO = os.environ.get("COMMA_CAR_SEGMENTS_REPO", "https://huggingface.co/datasets/commaai/commaCarSegments")
|
| 7 |
+
COMMA_CAR_SEGMENTS_BRANCH = os.environ.get("COMMA_CAR_SEGMENTS_BRANCH", "main")
|
| 8 |
+
COMMA_CAR_SEGMENTS_LFS_INSTANCE = os.environ.get("COMMA_CAR_SEGMENTS_LFS_INSTANCE", COMMA_CAR_SEGMENTS_REPO)
|
| 9 |
+
|
| 10 |
+
def get_comma_car_segments_database():
|
| 11 |
+
from opendbc.car.fingerprints import MIGRATION
|
| 12 |
+
|
| 13 |
+
database = requests.get(get_repo_raw_url("database.json")).json()
|
| 14 |
+
|
| 15 |
+
ret = {}
|
| 16 |
+
for platform in database:
|
| 17 |
+
# TODO: remove this when commaCarSegments is updated to remove selector
|
| 18 |
+
ret[MIGRATION.get(platform, platform)] = [s.rstrip('/s') for s in database[platform]]
|
| 19 |
+
|
| 20 |
+
return ret
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Helpers related to interfacing with the commaCarSegments repository, which contains a collection of public segments for users to perform validation on.
|
| 24 |
+
|
| 25 |
+
def parse_lfs_pointer(text):
|
| 26 |
+
header, lfs_version = text.splitlines()[0].split(" ")
|
| 27 |
+
assert header == "version"
|
| 28 |
+
assert lfs_version == "https://git-lfs.github.com/spec/v1"
|
| 29 |
+
|
| 30 |
+
header, oid_raw = text.splitlines()[1].split(" ")
|
| 31 |
+
assert header == "oid"
|
| 32 |
+
header, oid = oid_raw.split(":")
|
| 33 |
+
assert header == "sha256"
|
| 34 |
+
|
| 35 |
+
header, size = text.splitlines()[2].split(" ")
|
| 36 |
+
assert header == "size"
|
| 37 |
+
|
| 38 |
+
return oid, size
|
| 39 |
+
|
| 40 |
+
def get_lfs_file_url(oid, size):
|
| 41 |
+
data = {
|
| 42 |
+
"operation": "download",
|
| 43 |
+
"transfers": [ "basic" ],
|
| 44 |
+
"objects": [
|
| 45 |
+
{
|
| 46 |
+
"oid": oid,
|
| 47 |
+
"size": int(size)
|
| 48 |
+
}
|
| 49 |
+
],
|
| 50 |
+
"hash_algo": "sha256"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
headers = {
|
| 54 |
+
"Accept": "application/vnd.git-lfs+json",
|
| 55 |
+
"Content-Type": "application/vnd.git-lfs+json"
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
response = requests.post(f"{COMMA_CAR_SEGMENTS_LFS_INSTANCE}.git/info/lfs/objects/batch", json=data, headers=headers)
|
| 59 |
+
|
| 60 |
+
assert response.ok
|
| 61 |
+
|
| 62 |
+
obj = response.json()["objects"][0]
|
| 63 |
+
|
| 64 |
+
assert "error" not in obj, obj
|
| 65 |
+
|
| 66 |
+
return obj["actions"]["download"]["href"]
|
| 67 |
+
|
| 68 |
+
def get_repo_raw_url(path):
|
| 69 |
+
if "huggingface" in COMMA_CAR_SEGMENTS_REPO:
|
| 70 |
+
return f"{COMMA_CAR_SEGMENTS_REPO}/raw/{COMMA_CAR_SEGMENTS_BRANCH}/{path}"
|
| 71 |
+
|
| 72 |
+
def get_repo_url(path):
|
| 73 |
+
# Automatically switch to LFS if we are requesting a file that is stored in LFS
|
| 74 |
+
|
| 75 |
+
response = requests.head(get_repo_raw_url(path))
|
| 76 |
+
|
| 77 |
+
if "text/plain" in response.headers.get("content-type"):
|
| 78 |
+
# This is an LFS pointer, so download the raw data from lfs
|
| 79 |
+
response = requests.get(get_repo_raw_url(path))
|
| 80 |
+
assert response.status_code == 200
|
| 81 |
+
oid, size = parse_lfs_pointer(response.text)
|
| 82 |
+
|
| 83 |
+
return get_lfs_file_url(oid, size)
|
| 84 |
+
else:
|
| 85 |
+
# File has not been uploaded to LFS yet
|
| 86 |
+
# (either we are on a fork where the data hasn't been pushed to LFS yet, or the CI job to push hasn't finished)
|
| 87 |
+
return get_repo_raw_url(path)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def get_url(route, segment, file="rlog.zst"):
|
| 91 |
+
return get_repo_url(f"segments/{route.replace('|', '/')}/{segment}/{file}")
|
dist/comma_car_segments-0.1.0-py3-none-any.whl
ADDED
|
Binary file (7.26 kB). View file
|
|
|
dist/comma_car_segments-0.1.0.tar.gz
ADDED
|
Binary file (7.54 kB). View file
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "comma-car-segments"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Helpers for accessing the commaCarSegments dataset"
|
| 5 |
+
license = "MIT"
|
| 6 |
+
authors = [{ name = "Vehicle Researcher", email = "user@comma.ai" }]
|
| 7 |
+
readme = "README.md"
|
| 8 |
+
requires-python = ">=3.11"
|
| 9 |
+
|
| 10 |
+
urls = { "homepage" = "https://huggingface.co/datasets/commaai/commaCarSegments" }
|
| 11 |
+
|
| 12 |
+
dependencies = [
|
| 13 |
+
"requests",
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
[tool.setuptools]
|
| 17 |
+
packages = ["comma_car_segments"]
|
| 18 |
+
|
| 19 |
+
[build-system]
|
| 20 |
+
requires = ["setuptools"]
|
| 21 |
+
build-backend = "setuptools.build_meta"
|