打卡目标检测
- 数据集准备
“”“python
create_data_lists
“””
from utils import create_data_lists
if name == ‘main’:
# voc07_path,voc12_path为我们训练测试所需要用到的数据集,output_folder为我们生成构建dataloader所需文件的路径
# 参数中涉及的路径以个人实际路径为准,建议将数据集放到dataset目录下,和教程保持一致
create_data_lists(voc07_path=’…/…/…/dataset/VOCdevkit/VOC2007’,
voc12_path=’…/…/…/dataset/VOCdevkit/VOC2012’,
output_folder=’…/…/…/dataset/VOCdevkit’)
-
构建dataloader
#train_dataset和train_loader的实例化
train_dataset = PascalVOCDataset(data_folder,
split=‘train’,
keep_difficult=keep_difficult)
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, shuffle=True,
collate_fn=train_dataset.collate_fn, num_workers=workers,
pin_memory=True) # note that we’re passing the collate function here -
关于数据增强
image, boxes, labels, difficulties = transform(image, boxes, labels, difficulties, split=self.split) -
最后,构建DataLoader
“”“python
DataLoader
“””
#参数说明:
#在train时一般设置shufle=True打乱数据顺序,增强模型的鲁棒性
#num_worker表示读取数据时的线程数,一般根据自己设备配置确定(如果是windows系统,建议设默认值0,防止出错)
#pin_memory,在计算机内存充足的时候设置为True可以加快内存中的tensor转换到GPU的速度,具体原因可以百度哈~
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, shuffle=True,
collate_fn=train_dataset.collate_fn, num_workers=workers,
pin_memory=True) # note that we’re passing the collate function here