diff --git a/data/__init__.py b/data/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000000..38e12241aa --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,41 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +# Quality gate. Will fail the CI/CD pipeline if any condition is not met +# severityThresholds - configures maximum thresholds for different problem severities +# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code +# Code Coverage is available in Ultimate and Ultimate Plus plans +#failureConditions: +# severityThresholds: +# any: 15 +# critical: 5 +# testCoverageThresholds: +# fresh: 70 +# total: 50 + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-:2025.2 diff --git a/src/Car_Perception_Automatic_Sensing/data/data_loader.py b/src/Car_Perception_Automatic_Sensing/data/data_loader.py new file mode 100644 index 0000000000..c3b550c992 --- /dev/null +++ b/src/Car_Perception_Automatic_Sensing/data/data_loader.py @@ -0,0 +1,58 @@ +""" +数据加载器核心模块 +支持自动驾驶数据集的加载、样本管理与批次分发 +""" +import os +import numpy as np +import torch +from torch.utils.data import Dataset, DataLoader +from typing import Optional, List + + +class AutoDriveDataset(Dataset): + """自动驾驶感知数据集基类(所有自定义数据集需继承此类)""" + def __init__(self, data_root: str, split: str = "train", transform: Optional[object] = None): + self.data_root = os.path.abspath(data_root) + self.split = split + self.transform = transform + self.sample_paths: List[str] = [] # 存储所有样本路径 + self._load_sample_paths() # 加载样本列表 + + def _load_sample_paths(self): + """加载样本路径(抽象方法,子类实现)""" + raise NotImplementedError("请在子类中实现 _load_sample_paths 方法") + + def __len__(self) -> int: + """返回样本总数""" + return len(self.sample_paths) + + def __getitem__(self, idx: int): + """获取单个样本(抽象方法,子类实现)""" + raise NotImplementedError("请在子类中实现 __getitem__ 方法") + + +def build_dataloader( + dataset: Dataset, + batch_size: int, + shuffle: bool = True, + num_workers: int = 4, + drop_last: bool = False +) -> DataLoader: + """构建PyTorch DataLoader(跨系统兼容)""" + # Windows系统默认关闭多进程 + if os.name == "nt": + num_workers = 0 + + return DataLoader( + dataset=dataset, + batch_size=batch_size, + shuffle=shuffle, + num_workers=num_workers, + pin_memory=True, + drop_last=drop_last + ) + + +if __name__ == "__main__": + # 框架测试 + pass \ No newline at end of file diff --git a/src/Car_Perception_Automatic_Sensing/data_loader.py b/src/Car_Perception_Automatic_Sensing/data_loader.py deleted file mode 100644 index eba4500e65..0000000000 --- a/src/Car_Perception_Automatic_Sensing/data_loader.py +++ /dev/null @@ -1,73 +0,0 @@ -""" -数据加载器模块 -负责自动驾驶感知任务的数据集加载、数据预处理分发等功能 -支持图像类数据集(如KITTI、COCO自动驾驶子集)的加载 -""" -import numpy as np -import torch -from torch.utils.data import Dataset, DataLoader - - -class AutoDriveDataset(Dataset): - """ - 自动驾驶感知数据集基类 - 所有自定义数据集需继承此类并实现抽象方法 - """ - def __init__(self, data_root: str, split: str = "train", transform=None): - """ - 初始化数据集 - :param data_root: 数据集根目录路径 - :param split: 数据集划分(train/val/test) - :param transform: 数据增强/预处理变换 - """ - self.data_root = data_root - self.split = split - self.transform = transform - self.sample_list = [] # 存储样本路径/索引的列表 - - # 后续将实现:加载样本列表 - self._load_sample_list() - - def _load_sample_list(self): - """ - 加载数据集样本列表(抽象方法,需子类实现) - """ - raise NotImplementedError("子类必须实现 _load_sample_list 方法") - - def __len__(self): - """ - 返回数据集样本总数 - """ - return len(self.sample_list) - - def __getitem__(self, idx: int): - """ - 根据索引获取单个样本(抽象方法,需子类实现) - :param idx: 样本索引 - :return: 处理后的图像和标注数据 - """ - raise NotImplementedError("子类必须实现 __getitem__ 方法") - - -def build_dataloader(dataset: Dataset, batch_size: int, shuffle: bool = True, num_workers: int = 4): - """ - 构建数据加载器 - :param dataset: 实例化的 Dataset 对象 - :param batch_size: 批次大小 - :param shuffle: 是否打乱样本顺序 - :param num_workers: 数据加载进程数 - :return: DataLoader 对象 - """ - dataloader = DataLoader( - dataset=dataset, - batch_size=batch_size, - shuffle=shuffle, - num_workers=num_workers, - pin_memory=True # 加速GPU数据传输 - ) - return dataloader - - -if __name__ == "__main__": - # 测试代码框架(后续可完善) - pass \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000000..e69de29bb2