Repository navigation
数据结构 :创建 data/ 目录,编写 data_loader.py 空框架 #3992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0f9b297
1
lj2302 5a338a4
Merge branch 'OpenHUTB:main' into main
lj2302 5808e48
1
lj2302 541c063
无人车动态障碍物避障算法
lj2302 369b66f
Merge remote-tracking branch 'origin/main'
lj2302 426fe49
提交选题
lj2302 d58a1bb
Merge branch 'main' of https://github.com/lj2302/nn2
lj2302 3cabf9e
删除多余的.idea文件,更改项目名
lj2302 c924f07
Merge branch 'OpenHUTB:main' into main
lj2302 5a2c700
创建 requirements.txt,列出依赖库(numpy、torch、opencv 等)
lj2302 cf8b30b
Merge branch 'main' of https://github.com/lj2302/nn2
lj2302 0d378c6
Merge branch 'OpenHUTB:main' into main
lj2302 0f21da3
[env] add requirements.txt for dependencies
lj2302 7c93572
Merge branch 'OpenHUTB:main' into main
lj2302 47aac2b
Mergebranch 'main' of https://github.com/lj2302/nn2
lj2302 253c385
[env] add requirements.txt for dependencies
lj2302 25a85db
[data] create data_loader.py skeleton
lj2302 8bc6c8a
Merge branch 'OpenHUTB:main' into main
lj2302 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| @" | ||
| """ | ||
| 数据加载器模块 | ||
| 负责自动驾驶感知任务的数据集加载、数据预处理分发等功能 | ||
| 支持图像类数据集(如KITTI、COCO自动驾驶子集)的加载 | ||
| """ | ||
|
|
||
| import os | ||
| 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 | ||
| "@ | Out-File -FilePath data_loader.py -Encoding utf8 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一行不是代码吧