我正在研究图像中的衣服检测。为此,我在 python 上使用包 TorchVision,我想从一个预训练模型开始,并为我的课程(不同种类的衣服)微调它。我的图像在一个 zip 文件中。当我运行函数 train_one_epoch 时,我收到此错误:
IOError: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "<ipython-input-16-4557e2f6ca8b>", line 51, in __getitem__ img = Image.open(img_path).convert("RGB") File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2530, in open fp = builtins.open(filename, "rb") IOError: [Errno 20] Not a directory: 'gdrive/My Drive/donnees_kaggle_iMaterialist/train.zip/062fc2042f49d10fa625151cb652c3da.jpg'
这是我的代码的一部分:
python
num_classes = 46 + 1
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
dataset_train = FashionDataset('gdrive/My Drive/donnees_kaggle_iMaterialist/train.zip/', # "../input/imaterialist-fashion-2019-FGVC6/train/",
'gdrive/My Drive/donnees_kaggle_iMaterialist/train.csv.zip', #"../input/imaterialist-fashion-2019-FGVC6/train.csv",
256,
256,
transforms=get_transform(train=True))
model_ft = get_instance_segmentation_model(num_classes)
model_ft.to(device)
data_loader = torch.utils.data.DataLoader(
dataset_train, batch_size=4, shuffle=True, num_workers=8,
collate_fn=lambda x: tuple(zip(*x)))
params = [p for p in model_ft.parameters() if p.requires_grad]
optimizer = torch.optim.SGD(params, lr=0.001,
momentum=0.9, weight_decay=0.0005)
lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer,
step_size=5,
gamma=0.1)
num_epochs = 10
for epoch in range(num_epochs):
train_one_epoch(model_ft, optimizer, data_loader, device, epoch, print_freq=10)
lr_scheduler.step()
torch.save(model_ft.state_dict(), "model.bin")