Spaces:
Paused
Paused
Deploy Sensorflow Studio
Browse filesFiles changed (10)
- app_backend.py+9-3
- data/README.mdAdded+8
- sensorflow/adapters/local_adapter.py+32-12
- sensorflow/av_media_filter.pyAdded+286
- sensorflow/execution_ops.py+40-8
- sensorflow/pipeline_artifacts.py+52-19
- static/app.js+47-5
- static/index.html+1
- tests/test_pipeline/test_av_media_filter.pyAdded+140
- tests/test_pipeline/test_pipeline_browse.py+15-16
2446 unmodified lines24472448244924502451245224532454245524562446 unmodified lines@app.get("/api/dataset/browse")def dataset_browse(source_path: str = "data", limit: int = 48):"""Validate Images Path by listing browsable local frames."""from sensorflow import pipeline_artifacts as artifactsreturn artifacts.scan_source_images(source_path, limit=limit)@app.get("/api/mitl/queue")2446 unmodified lines24472448244924502451245224532454245524562457245824592460246124622446 unmodified lines@app.get("/api/dataset/browse")def dataset_browse(source_path: str = "data",limit: int = 48,dataset_type: Optional[str] = None,):"""Validate Images Path by listing browsable local driving-relevant frames."""from sensorflow import pipeline_artifacts as artifactsdtype = dataset_type or load_config().dataset_typereturn artifacts.scan_source_images(source_path, limit=limit, dataset_type=dtype)@app.get("/api/mitl/queue")
12345678# Local data folder
This folder may contain ad-hoc test assets. **Dataset browse and load filters** excludenon-driving media (README assets, logos, generic `test.jpg` files, docs paths, and filesthat do not match AV camera-frame layout when an official dataset type is selected).
Place real camera frames under a nested path such as `data/images/train/` or`data/camera/front/` for Validate & Browse and Local ingest to pick them up.22 unmodified lines232425262728293031323334353637383940414243444546474849505159 unmodified lines11111211311411511611722 unmodified linesDEFAULT_MAX_FRAMES = 10_000def discover_media(path: Path) -> Tuple[List[Path], List[Path]]:"""Return (image_files, video_files) under path (file or directory)."""if path.is_file():ext = path.suffix.lower()if ext in IMAGE_EXTS:return [path], []if ext in VIDEO_EXTS:return [], [path]return [], []if not path.is_dir():return [], []images: List[Path] = []videos: List[Path] = []for p in sorted(path.rglob("*")):if not p.is_file():continueext = p.suffix.lower()if ext in IMAGE_EXTS:images.append(p)elif ext in VIDEO_EXTS:videos.append(p)return images, videos59 unmodified lines"or a video file, then re-run ingest with Local enabled.")images, videos = discover_media(path)frame_images = list(images)decode_dir = Path("runs/pipeline") / sequence_id / "decoded_frames"22 unmodified lines2324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707159 unmodified lines13113213313413513613722 unmodified linesDEFAULT_MAX_FRAMES = 10_000def discover_media(path: Path,*,dataset_type: Optional[str] = None,) -> Tuple[List[Path], List[Path]]:"""Return (image_files, video_files) under path (file or directory)."""from sensorflow.av_media_filter import (IMAGE_EXTS as AV_IMAGE_EXTS,VIDEO_EXTS as AV_VIDEO_EXTS,partition_media_files,)if path.is_file():ext = path.suffix.lower()if ext in AV_IMAGE_EXTS:images, _ = partition_media_files([path], root=path.parent, dataset_type=dataset_type)return images, []if ext in AV_VIDEO_EXTS:_, excluded = partition_media_files([path], root=path.parent, dataset_type=dataset_type, allow_videos=True)return [], [] if excluded else [path]return [], []if not path.is_dir():return [], []raw_images: List[Path] = []raw_videos: List[Path] = []for p in sorted(path.rglob("*")):if not p.is_file():continueext = p.suffix.lower()if ext in AV_IMAGE_EXTS:raw_images.append(p)elif ext in AV_VIDEO_EXTS:raw_videos.append(p)images, _ = partition_media_files(raw_images, root=path, dataset_type=dataset_type)videos, _ = partition_media_files(raw_videos,root=path,dataset_type=dataset_type,allow_videos=True,)return images, videos59 unmodified lines"or a video file, then re-run ingest with Local enabled.")images, videos = discover_media(path, dataset_type=source.get("dataset_type"))frame_images = list(images)decode_dir = Path("runs/pipeline") / sequence_id / "decoded_frames"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286"""Heuristic filters for driving / AV pipeline image and video discovery."""
from __future__ import annotations
import refrom pathlib import Pathfrom typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
IMAGE_EXTS = {".jpg", ".jpeg", ".png", ".bmp", ".webp", ".tif", ".tiff"}VIDEO_EXTS = {".mp4", ".avi", ".mov", ".mkv", ".webm", ".m4v"}
# Path segments that almost never contain drivable-scene media.EXCLUDED_DIR_SEGMENTS = { ".git", ".github", ".venv", "venv", "__pycache__", "node_modules", "dist", "build", "docs", "doc", "documentation", "marketing", "assets", "static/icons", "icons", "badges", "screenshots",}
# Filename stems that are commonly README / branding / test junk.JUNK_NAME_STEMS = { "logo", "icon", "favicon", "avatar", "profile", "readme", "banner", "badge", "placeholder", "sample", "example", "demo", "test", "screenshot", "thumbnail", "thumb",}
# Substrings in relative paths that suggest AV camera frames.AV_PATH_MARKERS = ( "camera", "cameras", "images", "frames", "frame", "front", "rear", "left", "right", "rgb", "video", "sequence", "segment", "train", "val", "training", "validation", "lidar", "sensor", "recording", "drive", "driving", "scene",)
OFFICIAL_AV_DATASETS = frozenset({"alpamayo", "waymo", "a2d2"})
MIN_DRIVING_IMAGE_BYTES = 10 * 1024 # icons / tiny README assets
EXCLUSION_CATEGORIES = ( "wrong_extension", "excluded_path", "junk_filename", "too_small", "non_av_layout",)
def _normalize_parts(path: Path) -> Tuple[str, ...]: return tuple(part.lower() for part in path.parts)
def _relative_to_root(path: Path, root: Optional[Path]) -> Path: if root is None: return path try: return path.resolve().relative_to(root.resolve()) except ValueError: return path
def _has_excluded_dir(path: Path) -> bool: parts = _normalize_parts(path) for i, part in enumerate(parts): if part in EXCLUDED_DIR_SEGMENTS: return True if part == "assets" and i + 1 < len(parts) and parts[i + 1] in { "marketing", "branding", "icons", "logos", }: return True return False
def _junk_filename(path: Path) -> bool: stem = path.stem.lower() if stem in JUNK_NAME_STEMS: return True if re.match(r"^(logo|icon|favicon|readme|banner|badge)[-_]?\d*$", stem): return True return False
def _looks_like_av_layout(relative: Path) -> bool: rel_str = str(relative).lower().replace("\\", "/") if any(marker in rel_str for marker in AV_PATH_MARKERS): return True # Nested structure (e.g. data/sequences/001/front.jpg) — not a loose root file. return len(relative.parts) >= 2
def classify_media_file( path: Path, *, root: Optional[Path] = None, dataset_type: Optional[str] = None, allow_videos: bool = True,) -> Tuple[bool, Optional[str]]: """Return (accepted, exclusion_category).""" if not path.is_file(): return False, "non_media"
ext = path.suffix.lower() allowed = IMAGE_EXTS | (VIDEO_EXTS if allow_videos else set()) if ext not in allowed: return False, "wrong_extension"
if _has_excluded_dir(path): return False, "excluded_path"
if _junk_filename(path): return False, "junk_filename"
if ext in IMAGE_EXTS: try: size = path.stat().st_size except OSError: return False, "non_media" if size < MIN_DRIVING_IMAGE_BYTES: return False, "too_small"
relative = _relative_to_root(path, root) dtype = (dataset_type or "local").lower() if dtype in OFFICIAL_AV_DATASETS and not _looks_like_av_layout(relative): return False, "non_av_layout"
return True, None
def partition_media_files( paths: Iterable[Path], *, root: Optional[Path] = None, dataset_type: Optional[str] = None, allow_videos: bool = True,) -> Tuple[List[Path], List[Dict[str, Any]]]: """Split paths into accepted driving media and excluded entries with reasons.""" accepted: List[Path] = [] excluded: List[Dict[str, Any]] = [] for path in paths: ok, reason = classify_media_file( path, root=root, dataset_type=dataset_type, allow_videos=allow_videos, ) if ok: accepted.append(path) else: excluded.append( { "path": str(path), "name": path.name, "reason": reason or "excluded_path", } ) accepted.sort(key=lambda p: str(p).lower()) return accepted, excluded
def iter_candidate_files( root: Path, *, allow_videos: bool = True,) -> List[Path]: """Collect image/video candidates under root before AV heuristics.""" exts = set(IMAGE_EXTS) if allow_videos: exts |= VIDEO_EXTS
if root.is_file(): return [root] if root.suffix.lower() in exts else []
if not root.is_dir(): return []
out: List[Path] = [] for p in root.rglob("*"): if p.is_file() and p.suffix.lower() in exts: out.append(p) return out
def scan_driving_media( source_path: str | Path, *, dataset_type: Optional[str] = None, allow_videos: bool = True, limit: Optional[int] = None,) -> Dict[str, Any]: """Scan a path and return accepted media plus exclusion breakdown.""" root = Path(source_path) if not root.is_absolute(): root = Path.cwd() / root
if not root.exists(): return { "source_path": str(source_path), "exists": False, "accepted": [], "excluded": [], "count": 0, "excluded_count": 0, "excluded_by_reason": {}, }
candidates = iter_candidate_files(root, allow_videos=allow_videos) scan_root = root if root.is_dir() else root.parent accepted, excluded = partition_media_files( candidates, root=scan_root, dataset_type=dataset_type, allow_videos=allow_videos, )
if limit is not None: accepted = accepted[:limit]
by_reason: Dict[str, int] = {} for item in excluded: reason = item.get("reason") or "excluded_path" by_reason[reason] = by_reason.get(reason, 0) + 1
return { "source_path": str(source_path), "exists": True, "accepted": accepted, "excluded": excluded, "count": len(accepted), "excluded_count": len(excluded), "excluded_by_reason": by_reason, }
def summarize_exclusions(excluded: Sequence[Dict[str, Any]]) -> Dict[str, int]: counts: Dict[str, int] = {} for item in excluded: reason = item.get("reason") or "excluded_path" counts[reason] = counts.get(reason, 0) + 1 return counts21 unmodified lines22232425262728292 unmodified lines3233343536377 unmodified lines45464748495051525354555 unmodified lines616263646566676869707172737483 unmodified lines15815916016116216311 unmodified lines17517617717817918018148 unmodified lines23023123223323423521 unmodified linesreturn pdef discover_images(source_path: str, *, max_scan: int = 100_000) -> Dict[str, Any]:"""Discover images under a path; report corrupt/unreadable files."""root = _resolve(source_path)result: Dict[str, Any] = {"source_path": str(root),2 unmodified lines"images_discovered": 0,"images_readable": 0,"images_corrupt": 0,"annotations_discovered": 0,"annotation_objects": 0,"class_ids": [],7 unmodified linesresult["errors"].append(f"Path does not exist: {source_path}")return resultimages: List[Path] = []labels: List[Path] = []if root.is_file():if root.suffix.lower() in IMAGE_EXTS:images = [root]elif root.suffix.lower() in LABEL_EXTS:labels = [root]else:5 unmodified linescontinuesuf = p.suffix.lower()if suf in IMAGE_EXTS:images.append(p)elif suf in LABEL_EXTS:labels.append(p)if len(images) + len(labels) >= max_scan:result["warnings"].append(f"Scan capped at {max_scan} files")breakimages = sorted(images)labels = sorted(labels)result["images_discovered"] = len(images)result["annotations_discovered"] = len(labels)83 unmodified lines"images_discovered": discovery.get("images_discovered"),"images_readable": discovery.get("images_readable"),"images_corrupt": discovery.get("images_corrupt"),"annotations_discovered": discovery.get("annotations_discovered"),"annotation_objects": discovery.get("annotation_objects"),"class_ids": discovery.get("class_ids"),11 unmodified linesdataset_type: str = "local",) -> Dict[str, Any]:"""Real Load & Preprocess: discovery + optional YAML semantic checks."""discovery = discover_images(source_path)yaml_report = Noneif yaml_path:ypath = Path(yaml_path)48 unmodified lines"images_discovered": discovery["images_discovered"],"images_readable": discovery["images_readable"],"images_corrupt": discovery["images_corrupt"],"annotations_discovered": discovery["annotations_discovered"],"annotation_objects": discovery["annotation_objects"],"loaded_pct_of_discovered": loaded_pct,21 unmodified lines2223242526272829303132333435362 unmodified lines3940414243444546477 unmodified lines55565758596061626364655 unmodified lines717273747576777879808182838485868788899091929394959697989910010183 unmodified lines18518618718818919019119219311 unmodified lines20520620720820921021148 unmodified lines26026126226326426526626721 unmodified linesreturn pdef discover_images(source_path: str,*,max_scan: int = 100_000,dataset_type: Optional[str] = None,) -> Dict[str, Any]:"""Discover driving-relevant images under a path; report corrupt/unreadable files."""from sensorflow.av_media_filter import partition_media_filesroot = _resolve(source_path)result: Dict[str, Any] = {"source_path": str(root),2 unmodified lines"images_discovered": 0,"images_readable": 0,"images_corrupt": 0,"images_excluded": 0,"excluded_by_reason": {},"excluded_samples": [],"annotations_discovered": 0,"annotation_objects": 0,"class_ids": [],7 unmodified linesresult["errors"].append(f"Path does not exist: {source_path}")return resultraw_images: List[Path] = []labels: List[Path] = []if root.is_file():if root.suffix.lower() in IMAGE_EXTS:raw_images = [root]elif root.suffix.lower() in LABEL_EXTS:labels = [root]else:5 unmodified linescontinuesuf = p.suffix.lower()if suf in IMAGE_EXTS:raw_images.append(p)elif suf in LABEL_EXTS:labels.append(p)if len(raw_images) + len(labels) >= max_scan:result["warnings"].append(f"Scan capped at {max_scan} files")breakscan_root = root if root.is_dir() else root.parentimages, excluded = partition_media_files(raw_images,root=scan_root,dataset_type=dataset_type,allow_videos=False,)result["images_excluded"] = len(excluded)result["excluded_by_reason"] = {reason: sum(1 for e in excluded if e.get("reason") == reason)for reason in sorted({e.get("reason", "excluded_path") for e in excluded})}result["excluded_samples"] = excluded[:50]if excluded:result["warnings"].append(f"{len(excluded)} file(s) excluded as non-driving media "f"({', '.join(f'{k}: {v}' for k, v in result['excluded_by_reason'].items())})")labels = sorted(labels)result["images_discovered"] = len(images)result["annotations_discovered"] = len(labels)83 unmodified lines"images_discovered": discovery.get("images_discovered"),"images_readable": discovery.get("images_readable"),"images_corrupt": discovery.get("images_corrupt"),"images_excluded": discovery.get("images_excluded"),"excluded_by_reason": discovery.get("excluded_by_reason"),"excluded_samples": discovery.get("excluded_samples"),"annotations_discovered": discovery.get("annotations_discovered"),"annotation_objects": discovery.get("annotation_objects"),"class_ids": discovery.get("class_ids"),11 unmodified linesdataset_type: str = "local",) -> Dict[str, Any]:"""Real Load & Preprocess: discovery + optional YAML semantic checks."""discovery = discover_images(source_path, dataset_type=dataset_type)yaml_report = Noneif yaml_path:ypath = Path(yaml_path)48 unmodified lines"images_discovered": discovery["images_discovered"],"images_readable": discovery["images_readable"],"images_corrupt": discovery["images_corrupt"],"images_excluded": discovery.get("images_excluded", 0),"excluded_by_reason": discovery.get("excluded_by_reason", {}),"annotations_discovered": discovery["annotations_discovered"],"annotation_objects": discovery["annotation_objects"],"loaded_pct_of_discovered": loaded_pct,
252 unmodified lines2532542552562572582592602612 unmodified lines2642652662672682692702712722732742752762772782792802812821 unmodified line2842852862872882892902912922932942952962972982992 unmodified lines3023033043053063071 unmodified line309310311312313252 unmodified linesreturn resolved, media_type or "application/octet-stream"def scan_source_images(source_path: str, limit: int = 48) -> Dict[str, Any]:"""List local images under Dataset Configuration Images Path for validation."""path = Path(source_path)if not path.exists():return {"status": "ok",2 unmodified lines"browsable": False,"count": 0,"images": [],"empty_reason": f"Path does not exist: {source_path}",}images: List[Path] = []if path.is_file() and path.suffix.lower() in IMAGE_EXTS:images = [path]elif path.is_dir():for p in sorted(path.rglob("*")):if p.is_file() and p.suffix.lower() in IMAGE_EXTS:images.append(p)if len(images) >= max(limit, 1):breakelse:return {"status": "ok","source_path": source_path,1 unmodified line"browsable": False,"count": 0,"images": [],"empty_reason": "Not an image file or directory of images.",}# Full count for directories (cap walk cost for huge trees by reusing discovered list when small)total = len(images)if path.is_dir() and total >= limit:total = sum(1 for p in path.rglob("*") if p.is_file() and p.suffix.lower() in IMAGE_EXTS)previews = []for img in images[:limit]:previews.append({"name": img.name,2 unmodified lines})return {"status": "ok","source_path": source_path,1 unmodified line"browsable": total > 0,"count": total,"images": previews,"empty_reason": None if total else "No images found under this path.",}252 unmodified lines2532542552562572582592602612622632642652662672682692702712 unmodified lines2742752762772782792802812822832842852861 unmodified line2882892902912922932942952962972982993003013023033043053063073083093103112 unmodified lines3143153163173183193203213223233243253263273283293303313323333343353361 unmodified line338339340341342343344345346252 unmodified linesreturn resolved, media_type or "application/octet-stream"def scan_source_images(source_path: str,limit: int = 48,*,dataset_type: Optional[str] = None,) -> Dict[str, Any]:"""List local driving-relevant images under Dataset Configuration Images Path."""from sensorflow.av_media_filter import OFFICIAL_AV_DATASETS, scan_driving_mediapath = Path(source_path)if not path.is_absolute():path = Path.cwd() / pathif not path.exists():return {"status": "ok",2 unmodified lines"browsable": False,"count": 0,"images": [],"excluded_count": 0,"excluded": [],"excluded_by_reason": {},"empty_reason": f"Path does not exist: {source_path}",}if path.is_file() and path.suffix.lower() not in IMAGE_EXTS:return {"status": "ok","source_path": source_path,1 unmodified line"browsable": False,"count": 0,"images": [],"excluded_count": 0,"excluded": [],"excluded_by_reason": {},"empty_reason": "Not an image file or directory of driving media.",}scan = scan_driving_media(path,dataset_type=dataset_type,allow_videos=False,)accepted = scan["accepted"]excluded = scan["excluded"]total = scan["count"]dtype = (dataset_type or "local").lower()previews = []for img in accepted[:limit]:previews.append({"name": img.name,2 unmodified lines})empty_reason = Noneif total == 0:if excluded:empty_reason = (f"No driving-relevant images found under {source_path} "f"({len(excluded)} file(s) excluded as non-AV media).")else:empty_reason = "No driving-relevant images found under this path."warnings: List[str] = []if dtype in OFFICIAL_AV_DATASETS and excluded:warnings.append(f"Browsed path does not match typical {dtype} layout; ""point Images Path at downloaded camera frames or enable Local ingest.")return {"status": "ok","source_path": source_path,1 unmodified line"browsable": total > 0,"count": total,"images": previews,"excluded_count": scan["excluded_count"],"excluded": excluded[:200],"excluded_by_reason": scan["excluded_by_reason"],"warnings": warnings,"empty_reason": empty_reason,}
921 unmodified lines9229239249259269279289299309319329339347 unmodified lines942943944945946947948949950951952953954955956957958959960961921 unmodified linesif (btnBrowseSource) {btnBrowseSource.addEventListener('click', async () => {const sourcePath = datasetSourcePath?.value || document.getElementById('input-source')?.value || 'data';const statusEl = document.getElementById('source-browse-status');const gallery = document.getElementById('source-browse-gallery');btnBrowseSource.disabled = true;btnBrowseSource.textContent = 'Scanning…';if (statusEl) statusEl.textContent = `Validating ${sourcePath}…`;try {const res = await fetch(`${API_BASE}/api/dataset/browse?source_path=${encodeURIComponent(sourcePath)}&limit=48`);const data = await res.json();if (gallery) {gallery.innerHTML = '';7 unmodified lines});}if (statusEl) {statusEl.textContent = data.browsable? `Browsable: ${data.count} image(s) under ${data.source_path}`: (data.empty_reason || 'Nothing browsable at this path.');}const badge = document.getElementById('ds-meta-badge');if (badge) {if (data.browsable) {badge.textContent = `${data.count} images browsable on disk`;badge.style.background = 'rgba(0, 255, 170, 0.15)';badge.style.color = '#00ffaa';badge.style.border = '1px solid rgba(0, 255, 170, 0.3)';document.getElementById('ds-kpi-loaded-rows').textContent = data.count;} else {badge.textContent = 'Not browsable — path empty or missing';badge.style.background = 'rgba(255, 68, 68, 0.12)';badge.style.color = '#ff8888';badge.style.border = '1px solid rgba(255, 68, 68, 0.35)';921 unmodified lines9229239249259269279289299309319329339349359369379389399409419429437 unmodified lines9519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003921 unmodified linesif (btnBrowseSource) {btnBrowseSource.addEventListener('click', async () => {const sourcePath = datasetSourcePath?.value || document.getElementById('input-source')?.value || 'data';const datasetType = selectDatasetType?.value || 'local';const statusEl = document.getElementById('source-browse-status');const excludedEl = document.getElementById('source-browse-excluded');const gallery = document.getElementById('source-browse-gallery');btnBrowseSource.disabled = true;btnBrowseSource.textContent = 'Scanning…';if (statusEl) statusEl.textContent = `Validating ${sourcePath}…`;if (excludedEl) {excludedEl.style.display = 'none';excludedEl.innerHTML = '';}try {const res = await fetch(`${API_BASE}/api/dataset/browse?source_path=${encodeURIComponent(sourcePath)}`+ `&limit=48&dataset_type=${encodeURIComponent(datasetType)}`);const data = await res.json();if (gallery) {gallery.innerHTML = '';7 unmodified lines});}if (statusEl) {let msg = data.browsable? `Browsable: ${data.count} driving-relevant image(s) under ${data.source_path}`: (data.empty_reason || 'Nothing browsable at this path.');if (Array.isArray(data.warnings) && data.warnings.length) {msg += ` — ${data.warnings[0]}`;}statusEl.textContent = msg;}if (excludedEl && data.excluded_count > 0) {excludedEl.style.display = 'block';const summary = document.createElement('div');summary.textContent = `${data.excluded_count} file(s) excluded (not driving media)`;const toggle = document.createElement('button');toggle.type = 'button';toggle.className = 'btn btn-secondary';toggle.style.marginTop = '8px';toggle.style.fontSize = '12px';toggle.textContent = 'Show excluded files';const list = document.createElement('ul');list.style.display = 'none';list.style.marginTop = '8px';list.style.fontSize = '12px';list.style.color = 'var(--text-muted)';(data.excluded || []).forEach((item) => {const li = document.createElement('li');li.textContent = `${item.name || item.path} (${item.reason || 'excluded'})`;list.appendChild(li);});toggle.addEventListener('click', () => {const open = list.style.display === 'none';list.style.display = open ? 'block' : 'none';toggle.textContent = open ? 'Hide excluded files' : 'Show excluded files';});excludedEl.appendChild(summary);excludedEl.appendChild(toggle);excludedEl.appendChild(list);}const badge = document.getElementById('ds-meta-badge');if (badge) {if (data.browsable) {badge.textContent = `${data.count} driving images browsable on disk`;badge.style.background = 'rgba(0, 255, 170, 0.15)';badge.style.color = '#00ffaa';badge.style.border = '1px solid rgba(0, 255, 170, 0.3)';document.getElementById('ds-kpi-loaded-rows').textContent = data.count;} else {badge.textContent = 'Not browsable — no driving media at path';badge.style.background = 'rgba(255, 68, 68, 0.12)';badge.style.color = '#ff8888';badge.style.border = '1px solid rgba(255, 68, 68, 0.35)';
152 unmodified lines153154155156157158152 unmodified lines</div><div id="config-exec-status" class="config-exec-status" style="margin-top:10px;font-size:12px;color:var(--text-muted);"></div><div id="source-browse-status" class="status-box" style="margin-top:12px;"></div><div id="source-browse-gallery" class="output-browse-gallery" style="margin-top:12px;"></div><div class="evidence-card" id="evidence-dataset" data-stage="dataset"><h4>What actually happened?</h4>152 unmodified lines153154155156157158159152 unmodified lines</div><div id="config-exec-status" class="config-exec-status" style="margin-top:10px;font-size:12px;color:var(--text-muted);"></div><div id="source-browse-status" class="status-box" style="margin-top:12px;"></div><div id="source-browse-excluded" class="status-box" style="margin-top:8px;display:none;"></div><div id="source-browse-gallery" class="output-browse-gallery" style="margin-top:12px;"></div><div class="evidence-card" id="evidence-dataset" data-stage="dataset"><h4>What actually happened?</h4>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140"""Tests for AV driving-media browse filtering."""
from __future__ import annotations
import importlibimport shutilfrom pathlib import Path
import pytestfrom fastapi.testclient import TestClient
def _png_bytes() -> bytes: return bytes.fromhex( "89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c489" "0000000a49444154789c63000100000500010d0a2db40000000049454e44ae426082" )
def _large_png_bytes(min_bytes: int = 11 * 1024) -> bytes: """Valid PNG header with zero padding so size heuristics accept it in tests.""" base = _png_bytes() if len(base) >= min_bytes: return base return base + b"\x00" * (min_bytes - len(base))
def _write_driving_frame(root: Path, rel: str = "images/train/frame.png") -> Path: path = root / rel path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(_large_png_bytes()) return path
@pytest.fixturedef client(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) import app_backend
importlib.reload(app_backend) return TestClient(app_backend.app)
def test_browse_excludes_junk_test_file_for_alpamayo(client, tmp_path): data_dir = tmp_path / "data" data_dir.mkdir() (data_dir / "test.jpg").write_bytes(_large_png_bytes()) # wrong ext still image-like size _write_driving_frame(data_dir, "camera/front/scene_001.jpg").write_bytes(_large_png_bytes())
res = client.get( "/api/dataset/browse?source_path=data&dataset_type=alpamayo" ) assert res.status_code == 200 body = res.json() assert body["count"] == 1 assert body["browsable"] is True assert body["excluded_count"] >= 1 names = {img["name"] for img in body["images"]} assert "scene_001.jpg" in names assert "test.jpg" not in names reasons = {e["reason"] for e in body["excluded"]} assert "junk_filename" in reasons or "non_av_layout" in reasons
def test_browse_excludes_docs_and_logo_paths(client, tmp_path): root = tmp_path / "data" _write_driving_frame(root, "frames/road.png") logo = root / "docs" / "logo.png" logo.parent.mkdir(parents=True) logo.write_bytes(_large_png_bytes()) icon = root / "assets" / "icon.png" icon.parent.mkdir(parents=True) icon.write_bytes(_large_png_bytes())
res = client.get("/api/dataset/browse?source_path=data&dataset_type=local") body = res.json() assert body["count"] == 1 assert body["excluded_count"] == 2 assert all(e["reason"] == "excluded_path" for e in body["excluded"])
def test_browse_excludes_tiny_icons(client, tmp_path): root = tmp_path / "data" _write_driving_frame(root, "images/train/big.png") tiny = root / "images" / "train" / "favicon.png" tiny.write_bytes(_png_bytes()) # < 10KB and junk name
res = client.get("/api/dataset/browse?source_path=data&dataset_type=local") body = res.json() assert body["count"] == 1 assert body["excluded_count"] == 1 assert body["excluded"][0]["reason"] in {"too_small", "junk_filename"}
def test_browse_lists_valid_driving_media(client, tmp_path): root = tmp_path / "data" _write_driving_frame(root, "camera/front/a.png")
res = client.get("/api/dataset/browse?source_path=data&dataset_type=local") assert res.status_code == 200 body = res.json() assert body["browsable"] is True assert body["count"] == 1 assert body["images"][0]["preview_url"].startswith("/api/pipeline/file?")
def test_load_reports_images_excluded(client, tmp_path): root = tmp_path / "data" _write_driving_frame(root, "images/train/good.png") (root / "sample.jpg").write_bytes(_large_png_bytes())
res = client.post( "/api/dataset/load", json={"source_path": str(root), "dataset_type": "local"}, ) data = res.json() assert data["metrics"]["images_discovered"] == 1 assert data["metrics"]["images_excluded"] == 1 assert data["discovery"]["excluded_by_reason"]
def test_repo_data_test_jpg_excluded_when_alpamayo_selected(client, tmp_path, monkeypatch): """Regression: loose data/test.jpg must not appear for official AV dataset types.""" repo_data = Path(__file__).resolve().parents[2] / "data" if not (repo_data / "test.jpg").exists(): pytest.skip("repo data/test.jpg not present")
monkeypatch.chdir(tmp_path) shutil.copytree(repo_data, tmp_path / "data")
import app_backend
importlib.reload(app_backend) c = TestClient(app_backend.app) res = c.get("/api/dataset/browse?source_path=data&dataset_type=alpamayo") body = res.json() assert body["count"] == 0 assert body["browsable"] is False assert body["excluded_count"] >= 1 assert not body["images"]5 unmodified lines67891011106 unmodified lines11811912012112212312412512612712812913013142 unmodified lines1741751761771781791801811821831841851861875 unmodified linesfrom fastapi.testclient import TestClient@pytest.fixturedef client(tmp_path, monkeypatch):monkeypatch.chdir(tmp_path)106 unmodified linesdef test_load_all_local_real_when_path_has_images(client, tmp_path):data_dir = tmp_path / "data"data_dir.mkdir()(data_dir / "a.png").write_bytes(bytes.fromhex("89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c489""0000000a49444154789c63000100000500010d0a2db40000000049454e44ae426082"))res = client.post("/api/dataset/load-all",json={42 unmodified linesdef test_dataset_browse_lists_images(client, tmp_path):data_dir = tmp_path / "data"data_dir.mkdir()(data_dir / "a.png").write_bytes(bytes.fromhex("89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c489""0000000a49444154789c63000100000500010d0a2db40000000049454e44ae426082"))res = client.get("/api/dataset/browse?source_path=data")assert res.status_code == 200body = res.json()5 unmodified lines678910111213141516171819106 unmodified lines12612712812913013113213313413542 unmodified lines1781791801811821831841851865 unmodified linesfrom fastapi.testclient import TestClientdef _large_png_bytes(min_bytes: int = 11 * 1024) -> bytes:base = bytes.fromhex("89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c489""0000000a49444154789c63000100000500010d0a2db40000000049454e44ae426082")return base if len(base) >= min_bytes else base + b"\x00" * (min_bytes - len(base))@pytest.fixturedef client(tmp_path, monkeypatch):monkeypatch.chdir(tmp_path)106 unmodified linesdef test_load_all_local_real_when_path_has_images(client, tmp_path):data_dir = tmp_path / "data" / "images" / "train"data_dir.mkdir(parents=True)png = _large_png_bytes()(data_dir / "a.png").write_bytes(png)res = client.post("/api/dataset/load-all",json={42 unmodified linesdef test_dataset_browse_lists_images(client, tmp_path):data_dir = tmp_path / "data" / "camera" / "front"data_dir.mkdir(parents=True)(data_dir / "a.png").write_bytes(_large_png_bytes())res = client.get("/api/dataset/browse?source_path=data")assert res.status_code == 200body = res.json()
app_backend.py+9-3
data/README.mdAdded+8
sensorflow/adapters/local_adapter.py+32-12
sensorflow/av_media_filter.pyAdded+286
sensorflow/execution_ops.py+40-8
sensorflow/pipeline_artifacts.py+52-19
static/app.js+47-5
static/index.html+1
tests/test_pipeline/test_av_media_filter.pyAdded+140
tests/test_pipeline/test_pipeline_browse.py+15-16