Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
714b1ae
add helper functions for detection algorithm
YongmingFrankGe Oct 11, 2022
22bc1c6
style: [CI] format
Oct 11, 2022
6486ad3
algorithms necessary functions finish, integration testing not comple…
YongmingFrankGe Oct 20, 2022
a557e70
Merge branch 'detection_estimation' of github.com:apperception-db/app…
YongmingFrankGe Oct 20, 2022
ccad0dc
delete trailing lines
YongmingFrankGe Oct 25, 2022
d9ff137
add test
YongmingFrankGe Oct 25, 2022
f6be16d
finish all implementation of sample plan, unit tested through notebook
YongmingFrankGe Oct 27, 2022
342f02b
end to end flow succeed, integration testing ongoing
YongmingFrankGe Nov 3, 2022
747a06a
thorough run of videos
YongmingFrankGe Nov 10, 2022
98c642e
fix ego exit segment
YongmingFrankGe Nov 15, 2022
54d1512
fix small bug
YongmingFrankGe Nov 15, 2022
eb30a32
fix detection problem after ego exit fix
YongmingFrankGe Nov 15, 2022
14ee07a
Merge branch 'optimized_ingestion' into detection_estimation
YongmingFrankGe Nov 16, 2022
6c284d0
style: [CI] format
Nov 16, 2022
d14b8bb
add doc string
YongmingFrankGe Nov 16, 2022
6dc1b4a
Merge branch 'detection_estimation' of github.com:apperception-db/app…
YongmingFrankGe Nov 16, 2022
146e8ad
revert data files
YongmingFrankGe Nov 16, 2022
c52cb8d
.
chanwutk Nov 16, 2022
e681552
typing
chanwutk Nov 16, 2022
76e7e6c
annotate typing
chanwutk Nov 17, 2022
bbc8000
add necessary typing
chanwutk Nov 18, 2022
a6aced9
style: [CI] format
Nov 18, 2022
d080b83
add ego stop action
YongmingFrankGe Nov 18, 2022
1408df7
fix import
chanwutk Nov 18, 2022
c79f113
Integrate detection estimation to pipeline (#186)
chanwutk Nov 22, 2022
244c6db
fix errors
chanwutk Nov 22, 2022
929f6fc
fix error
chanwutk Nov 22, 2022
1a19027
clean up
chanwutk Nov 23, 2022
cb8d387
style: [CI] format
Nov 23, 2022
a6d1eb0
detection estimation as stage
chanwutk Nov 30, 2022
c3ee953
Merge branch 'detection_estimation' of github.com:apperception-db/app…
chanwutk Nov 30, 2022
5616028
style: [CI] format
Nov 30, 2022
fc9497c
add detection_estimation to notebook
chanwutk Nov 30, 2022
76f88eb
style: [CI] format
Nov 30, 2022
105b4a3
use logger instead of print
chanwutk Nov 30, 2022
02341b8
style: [CI] format
Nov 30, 2022
ddb28e7
fix typing in python3.8
YongmingFrankGe Dec 1, 2022
0ce6aa7
style: [CI] format
Dec 1, 2022
6108896
clean up
chanwutk Dec 1, 2022
44fc698
style: [CI] format
Dec 1, 2022
7bbcb8e
add TODO for detection coversio
YongmingFrankGe Dec 3, 2022
274ab09
Merge branch 'detection_estimation' of github.com:apperception-db/app…
YongmingFrankGe Dec 3, 2022
19be139
Add 3d calibration against the road segment (#187)
YongmingFrankGe Dec 6, 2022
be15dca
benchmark
chanwutk Dec 7, 2022
757c032
fix LineString error + output trajectories for benchmark
chanwutk Dec 8, 2022
0c14e3d
style: [CI] format
Dec 8, 2022
13f85d3
performance benchmark
chanwutk Dec 14, 2022
8c48aff
Detection Estimation: add 3D detection and output DetectionInfo (#189)
chanwutk Dec 15, 2022
5fb33c1
fix algorithms with new discovery in segment lines (#188)
YongmingFrankGe Dec 15, 2022
878fa29
cleanup duplicate road segments
chanwutk Dec 24, 2022
f1365b3
style: [CI] format
Dec 24, 2022
a982f59
allow none uid
chanwutk Dec 24, 2022
d30108e
fix test
chanwutk Dec 24, 2022
0d863e0
fix linting error
chanwutk Dec 24, 2022
407b013
video with skipped frames
chanwutk Jan 5, 2023
d7c2de8
style: [CI] format
Jan 5, 2023
81403d7
Merge branch 'optimized_ingestion' into detection_estimation
chanwutk Jan 12, 2023
1575f38
Construct segment trajectory (#191)
YongmingFrankGe Jan 14, 2023
7698ff9
add detection type annotation
chanwutk Jan 14, 2023
1006dcf
fix detection estimation errors (#195)
chanwutk Jan 15, 2023
08ec805
Add object type filter (#196)
chanwutk Jan 16, 2023
2a55372
Fix Detection Estimation segment mapping (#197)
chanwutk Jan 19, 2023
cb35f7d
pruning testing of detection estimation (#199)
YongmingFrankGe Jan 25, 2023
f83c134
Optimized mapping (#200)
YongmingFrankGe Feb 15, 2023
9f9bdfc
Fix road type (#201)
YongmingFrankGe Feb 20, 2023
c80eac0
Clean up duplicate ingest (#204)
chanwutk Feb 21, 2023
555cdce
Cleanup duplicate ingest (#206)
chanwutk Feb 21, 2023
0136c78
Cleanup duplicate ingest (#208)
chanwutk Feb 21, 2023
3e5950a
Fix segment trajectory 3 (#207)
chanwutk Feb 21, 2023
a90fafc
Fig13 end to end (#202)
YongmingFrankGe Feb 21, 2023
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: 2 additions & 1 deletion .github/workflows/clean-up-and-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
pip install --upgrade pip
pip install nbconvert
python -m jupyter nbconvert --clear-output --inplace benchmarks/**/*.ipynb benchmarks/*.ipynb
python -m jupyter nbconvert --clear-output --inplace nb-scripts/**/*.ipynb nb-scripts/*.ipynb
python -m jupyter nbconvert --clear-output --inplace scripts/**/*.ipynb scripts/*.ipynb
python -m jupyter nbconvert --clear-output --inplace playground/**/*.ipynb playground/*.ipynb

- name: Commit clean up changes
run: ./scripts/commit-and-push.sh "[CI] cleanup python notebooks"
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ models

weights

outputs
outputs

yolov5s.pt
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,45 @@ Apperception ingests video data from many perspectives and makes them queryable

## Require
```
python >= 3.7
python >= 3.8
```

## How to Setup Apperception Repo
### Install dependencies:
#### Debian based Linux
```sh
apt-get update && apt-get install -y postgresql python3-opencv
```
#### macOS
```sh
brew install postgresql
apt-get update && apt-get install -y python3-opencv
```
### Clone the Apperception repo
For ssh:
```sh
git clone git@github.com:apperception-db/apperception.git
cd apperception
git checkout optimized_ingestion
```
For HTTPS:

### We use Conda/Mamba to manage our python environment
Install Mamba: https://mamba.readthedocs.io/en/latest/installation.html
or install Conda: https://docs.conda.io/en/latest/miniconda.html

### Setup Environment and Dependencies
```sh
git clone https://github.com/apperception-db/apperception.git
cd apperception
# clone submodules
git submodule update --init --recursive

# setup virtual environment
# with conda
conda env create -f environment.yml
conda activate apperception
# OR with mamba
mamba env create -f environment.yml
mamba activate apperception

# install python dependencies
poetry install
```
### Downloading Official YOLOv4 Pre-trained in the repo

### [Deprecated] Downloading Official YOLOv4 Pre-trained in the repo

Copy and paste yolov4.weights from your downloads folder into this repository. For the Demo, we use yolov4-tiny.weights,

Expand Down
1 change: 0 additions & 1 deletion apperception/data_types/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def view_points(self, points: np.ndarray, view: np.ndarray, normalize=True) -> n
return points

def map_2d(self, view: np.ndarray = np.eye(3), normalize: bool = True) -> np.ndarray:

corners = self.view_points(self.corners(), view, normalize)[:2, :]

return corners
8 changes: 4 additions & 4 deletions apperception/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
("itemId", "TEXT"),
("cameraId", "TEXT"),
("objectType", "TEXT"),
("color", "TEXT"),
("roadTypes", "ttext"),
("trajCentroids", "tgeompoint"),
("translations", "tgeompoint"), # [(x,y,z)@today, (x2, y2,z2)@tomorrow, (x2, y2,z2)@nextweek]
("largestBbox", "stbox"),
("itemHeadings", "tfloat"),
# ("roadPolygons", "tgeompoint"),
# ("period", "period") [today, nextweek]
]

Expand Down Expand Up @@ -196,7 +196,7 @@ def _commit(self, commit=True):
self.connection.commit()

def execute(
self, query: "str | psycopg2.sql.SQL", vars: "tuple | list | None" = None
self, query: "str | psycopg2.sql.Composable", vars: "tuple | list | None" = None
) -> List[tuple]:
try:
self.cursor.execute(query, vars)
Expand All @@ -210,7 +210,7 @@ def execute(
self.connection.rollback()
raise error

def update(self, query: str, commit: bool = True) -> None:
def update(self, query: "str | psycopg2.sql.Composable", commit: bool = True) -> None:
try:
self.cursor.execute(query)
self._commit(commit)
Expand Down
1 change: 0 additions & 1 deletion apperception/legacy/world_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(self, world=None):
def connect_db(
self, host="localhost", user=None, password=None, port=25432, database_name=None
):

self.conn = psycopg2.connect(
database=database_name, user=user, password=password, host=host, port=port
)
Expand Down
2 changes: 0 additions & 2 deletions apperception/trackers/object_tracker_yolov5_deepsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def detect(opt: YoloV5Opt):

# Process detections
for det in pred: # detections per image

if det is None or not len(det):
deepsort.increment_ages()
continue
Expand All @@ -166,7 +165,6 @@ def detect(opt: YoloV5Opt):

# collect result bounding boxes
for output in outputs:

y1, x1, y2, x2, id, c = [int(o) for o in output]
bboxes = BoundingBox(x1, y1, x2, y2)
item_id = f"{names[c]}-{str(id)}"
Expand Down
5 changes: 4 additions & 1 deletion apperception/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
from .get_video_box import get_video_box
from .get_video_roi import get_video_roi
from .import_tables import import_tables
from .import_pickle import import_pickle
from .ingest_road import ingest_road
from .join import join
from .overlay_bboxes import overlay_bboxes
from .overlay_trajectory import fetch_camera_config, overlay_trajectory
from .overlay_trajectory import fetch_camera_config, fetch_camera_trajectory, overlay_trajectory
from .query_to_str import query_to_str
from .recognize import recognize
from .reformat_bbox_trajectories import reformat_bbox_trajectories
Expand All @@ -35,11 +36,13 @@
"create_transform_matrix",
"world_to_pixel",
"import_tables",
"import_pickle",
"export_tables",
"datetimes_to_framenums",
"get_video_roi",
"get_video_box",
"fetch_camera_config",
"fetch_camera_trajectory",
"join",
"transformation",
"fetch_camera",
Expand Down
1 change: 0 additions & 1 deletion apperception/utils/add_recognized_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def insert_general_trajectory(
itemHeading_list: List[int],
translation_list: List[Tuple[float, float, float]],
):

# Creating a cursor object using the cursor() method
cursor = conn.cursor()

Expand Down
35 changes: 35 additions & 0 deletions apperception/utils/import_pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import pickle

from apperception.database import Database
from apperception.data_types import Camera, CameraConfig


def import_pickle(database: "Database", data_path: str):
with open(os.path.join(data_path, "frames-compressed.pickle"), "rb") as f:
data_frames = pickle.loads(f.read())

database.reset(False)
for scene, val in data_frames.items():
scene_info = scene.split("-")
scene_id = scene_info[0] + "-" + scene_info[1]
configs = [
CameraConfig(
frame_id=frame[1],
frame_num=int(frame[2]),
filename=frame[3],
camera_translation=frame[4],
camera_rotation=frame[5],
camera_intrinsic=frame[6],
ego_translation=frame[7],
ego_rotation=frame[8],
timestamp=frame[9].timestamp(),
cameraHeading=frame[10],
egoHeading=frame[11],
)
for frame in val["frames"]
]
camera = Camera(config=configs, id=scene_id)
database.insert_cam(camera)

database._commit()
1 change: 0 additions & 1 deletion apperception/utils/import_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def import_tables(database: "Database", data_path: str):

# Import CSV
data_Cameras = pd.read_csv(os.path.join(data_path, "cameras.csv"))
df_Cameras = pd.DataFrame(data_Cameras)
Expand Down
56 changes: 42 additions & 14 deletions apperception/utils/ingest_road.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@
"""


def _remove_suffix(uid: str) -> "str | None":
if uid is None:
return None

split = uid.split("_")
assert len(split) == 2, f"cannot remove suffix: {uid}"
return split[0]


def create_polygon_table(database: "Database", polygons, drop=True):
if drop:
database.update("DROP TABLE IF EXISTS SegmentPolygon CASCADE")
Expand All @@ -148,8 +157,14 @@ def create_polygon_table(database: "Database", polygons, drop=True):
"CREATE INDEX IF NOT EXISTS segPoly_idx ON SegmentPolygon USING GiST(elementPolygon);"
)

ids = set([p["id"].split("_")[0] for p in polygons if len(p["id"].split("_")) == 1])

values = []
for poly in polygons:
i = poly["id"]
if len(i.split("_")) != 1:
assert i.split("_")[0] in ids
continue
values.append(
f"""(
'{poly['id']}',
Expand All @@ -174,8 +189,16 @@ def create_segment_table(database: "Database", segments, drop=True):
database.update(CREATE_SEGMENT_SQL)
database.update("CREATE INDEX IF NOT EXISTS element_idx ON Segment(elementId);")

ids = set(
[s["polygonId"].split("_")[0] for s in segments if len(s["polygonId"].split("_")) == 1]
)

values = []
for seg in segments:
i = seg["polygonId"]
if len(i.split("_")) != 1:
assert i.split("_")[0] in ids
continue
values.append(
f"""(
'{seg['polygonId']}',
Expand Down Expand Up @@ -216,9 +239,9 @@ def create_lanesection_table(database: "Database", laneSections, drop=True):
for lanesec in laneSections:
values.append(
f"""(
'{lanesec['id']}',
'{lanesec['laneToLeft']}',
'{lanesec['laneToRight']}',
'{_remove_suffix(lanesec['id'])}',
'{_remove_suffix(lanesec['laneToLeft'])}',
'{_remove_suffix(lanesec['laneToRight'])}',
'{lanesec['fasterLane']}',
'{lanesec['slowerLane']}',
'{lanesec['isForward']}'
Expand Down Expand Up @@ -278,7 +301,7 @@ def create_lane_lanesec_table(database: "Database", lane_lanesec, drop=True):
values.append(
f"""(
'{ll['lane']}',
'{ll['laneSec']}'
'{_remove_suffix(ll['laneSec'])}'
)"""
)

Expand Down Expand Up @@ -432,7 +455,7 @@ def create_road_roadsec_table(database: "Database", road_roadsec, drop=True):
values.append(
f"""(
'{rr['road']}',
'{rr['roadSec']}'
'{_remove_suffix(rr['roadSec'])}'
)"""
)

Expand All @@ -456,15 +479,20 @@ def create_roadsection_table(database: "Database", roadSections, drop=True):
values = []
for roadsec in roadSections:
if len(roadsec["forwardLanes"]) == 0:
roadsec["forwardLanes"] = "[]::text[]"
fl = "[]::text[]"
else:
fl = str([*map(_remove_suffix, roadsec["forwardLanes"])])

if len(roadsec["backwardLanes"]) == 0:
roadsec["backwardLanes"] = "[]::text[]"
bl = "[]::text[]"
else:
bl = str([*map(_remove_suffix, roadsec["backwardLanes"])])

values.append(
f"""(
'{roadsec['id']}',
ARRAY{roadsec['forwardLanes']},
ARRAY{roadsec['backwardLanes']}
'{_remove_suffix(roadsec['id'])}',
ARRAY{fl},
ARRAY{bl}
)"""
)

Expand Down Expand Up @@ -495,8 +523,8 @@ def create_roadsec_lanesec_table(database: "Database", roadsec_lanesec, drop=Tru
for rl in roadsec_lanesec:
values.append(
f"""(
'{rl['roadSec']}',
'{rl['laneSec']}'
'{_remove_suffix(rl['roadSec'])}',
'{_remove_suffix(rl['laneSec'])}'
)"""
)

Expand All @@ -521,7 +549,7 @@ def create_intersection_table(database: "Database", intersections, drop=True):
for intersec in intersections:
values.append(
f"""(
'{intersec['id']}',
'{_remove_suffix(intersec['id'])}',
'{intersec['road']}'
)"""
)
Expand All @@ -537,7 +565,7 @@ def create_intersection_table(database: "Database", intersections, drop=True):
)


ROAD_TYPES = {"road", "lane", "lanesection", "roadSection", "intersection"}
ROAD_TYPES = {"road", "lane", "lanesection", "roadsection", "intersection", "lanegroup"}


def add_segment_type(database: "Database"):
Expand Down
Loading