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.py b/src/Car_Perception_Automatic_Sensing/data.py new file mode 100644 index 0000000000..6d2fd3587d --- /dev/null +++ b/src/Car_Perception_Automatic_Sensing/data.py @@ -0,0 +1,15 @@ +""" +数据模块(data) +负责自动驾驶感知任务的数据集加载、图像预处理、数据增强等功能 +支持KITTI、Waymo、COCO等自动驾驶数据集 +""" + +# 导出核心类和函数 +from .data_loader import AutoDriveDataset, build_dataloader +from .preprocess_utils import load_image_rgb + +__all__ = [ + "AutoDriveDataset", + "build_dataloader", + "load_image_rgb" +] \ 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 index eba4500e65..5ed9a7620b 100644 --- a/src/Car_Perception_Automatic_Sensing/data_loader.py +++ b/src/Car_Perception_Automatic_Sensing/data_loader.py @@ -3,7 +3,10 @@ 负责自动驾驶感知任务的数据集加载、数据预处理分发等功能 支持图像类数据集(如KITTI、COCO自动驾驶子集)的加载 """ + +import os import numpy as np +import cv2 # 新增:导入opencv用于图像读取 import torch from torch.utils.data import Dataset, DataLoader @@ -13,6 +16,7 @@ class AutoDriveDataset(Dataset): 自动驾驶感知数据集基类 所有自定义数据集需继承此类并实现抽象方法 """ + def __init__(self, data_root: str, split: str = "train", transform=None): """ 初始化数据集 @@ -34,6 +38,25 @@ def _load_sample_list(self): """ raise NotImplementedError("子类必须实现 _load_sample_list 方法") + def _load_image(self, img_path: str) -> np.ndarray: + """ + 封装图像读取函数 + :param img_path: 图像文件路径 + :return: 读取后的RGB格式图像(np.ndarray) + """ + # 检查图像路径是否存在 + if not os.path.exists(img_path): + raise FileNotFoundError(f"图像文件不存在:{img_path}") + + # 读取图像(cv2默认读取为BGR格式) + img = cv2.imread(img_path) + if img is None: + raise ValueError(f"无法读取图像文件:{img_path}(可能是文件损坏或格式不支持)") + + # 转换为RGB格式(符合大多数深度学习框架的输入要求) + img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + return img_rgb + def __len__(self): """ 返回数据集样本总数