Spaces:
Sleeping
Sleeping
File size: 2,534 Bytes
c8f05dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # ============================================================
# sample_loader.py
# ============================================================
#
# ETHUKU CREATE PANNINOM?
# ββββββββββββββββββββββ
# Oru "sample" = oru nodi-la (timestamp) 6 camera-vum eduthu photo.
# camera_loader oru camera-va mattum handle pannum.
# Ithu antha 6-ai stack panni ORE tensor-a thara.
#
# MUNADI FILE ODA CONNECTION:
# ββββββββββββββββββββββββββ
# camera_loader.load_camera() -> 6 thadava call
# dataset.py ithai __getitem__-la koopidum.
#
# INNER OPERATIONS:
# ββββββββββββββββ
# CAMERAS list order-la loop -> 6 dict -> torch.stack -> batch dim add.
#
# INPUT / OUTPUT:
# ββββββββββββββ
# Input : nusc, sample_token
# Output: {"images":[6,3,224,400], "intrinsics":[6,3,3],
# "extrinsics":[6,4,4], "sample_token": str}
#
# EPADI USE AAGUM:
# βββββββββββββββ
# Model 6 camera-vum ore neram paakkanum (surround view).
# Antha 6-ai ore tensor-a kudukka ithu thevai.
#
# ============================================================
import torch
from .camera_loader import load_camera
from .constants import CAMERAS
def load_sample(nusc, sample_token: str, data_root: str) -> dict:
"""
Oru sample-oda 6 camera data-vum load panni stack pannurathu.
Args:
nusc: NuScenes object
sample_token: sample-oda unique id
data_root: dataset folder
Returns:
dict of stacked tensors (mela sonna shapes)
"""
sample = nusc.get("sample", sample_token)
images, intrinsics, extrinsics = [], [], []
# CAMERAS order MUKIYAM - ellaa sample-layum ore order irukkanum,
# illaina model "front camera" nu nenachi back photo paakkum.
for cam_name in CAMERAS:
sd_token = sample["data"][cam_name] # antha camera-oda photo id
cam = load_camera(nusc, sd_token, data_root)
images.append(cam["image"]) # [3,224,400]
intrinsics.append(cam["intrinsic"]) # [3,3]
extrinsics.append(cam["extrinsic"]) # [4,4]
# stack = pudhu dimension add pannurathu (list of 6 -> tensor with 6)
return {
"images": torch.stack(images, dim=0), # [6,3,224,400]
"intrinsics": torch.stack(intrinsics, dim=0), # [6,3,3]
"extrinsics": torch.stack(extrinsics, dim=0), # [6,4,4]
"sample_token": sample_token,
}
|