#!/usr/bin/env python# -- coding: utf-8 --# Python version: 3.6import copyimport torchimport numpy as npfrom options import args_parserfrom torch.utils.data import DataLoaderfrom torch.utils.data import Datasetfrom torchvision import datasets, transformsfrom sampling import visDrone_iid, visDrone_noniid, visDrone_noniid_unequalfrom util.dataloader import YoloDataset, yolo_dataset_collate# from sampling import cifar_iid, cifar_noniiddef get_dataset(args): """ Returns train and test datasets and a user group which is a dict where the keys are the user index and the values are the corresponding data for each of those users. """ if args.dataset=='visDrone': # data_dir = '../data/' # apply_transform = transforms.Compose( # [transforms.ToTensor(), # transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) xmlfilepath = r'./data/train/annotations_voc' saveBasePath = r"./data/train/train_namelist/" annotation_path = '2007_train.txt' mosaic = False input_shape = (416, 416) val_split = 0.1 with open(annotation_path) as f: lines = f.readlines() np.random.seed(10101) np.random.shuffle(lines) np.random.seed(None) num_val = int(len(lines) * val_split) num_train = len(lines) - num_val Batch_size = 2 train_dataset = YoloDataset(lines[:num_train], (input_shape[0], input_shape[1]), mosaic=mosaic, is_train=True) test_dataset = YoloDataset(lines[num_train:], (input_shape[0], input_shape[1]), mosaic=False, is_train=False) gen = DataLoader(train_dataset, shuffle=True, batch_size=Batch_size, num_workers=4, pin_memory=True, drop_last=True, collate_fn=yolo_dataset_collate) gen_test = DataLoader(test_dataset, shuffle=True, batch_size=Batch_size, num_workers=4, pin_memory=True, drop_last=True, collate_fn=yolo_dataset_collate) return gen, gen_testargs = args_parser()if args.gpu: torch.cuda.set_device(args.gpu)device = 'cuda' if args.gpu else 'cpu'train_dataset, test_dataset = get_dataset(args)trainloader = DataLoader(train_dataset, batch_size=64, shuffle=True)for batch_idx, (images, labels) in enumerate(trainloader): images, labels = images.to(device), labels.to(device)
为什么代码运行会出现TypeError: 'DataLoader' object is not subscriptable问题
TypeError: 'DataLoader' object is not subscriptable
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答 默认 最新
悬赏问题
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向
- ¥15 如何用python向钉钉机器人发送可以放大的图片?