前提
Colabでsegmentation_models.pytorchを使って、セマンティックセグメンテーションを行おうとしています。
データセットはカスタムデータセットを使っています。
https://github.com/shirokawakita/multiclass-segmentation/blob/main/example_camvid_multiclassC2_quita.ipynb
↑のコードをアレンジして、やっているところです。
しかし、最後のコードでエラーが出てしまいました。
実現したいこと
エラーメッセージを回避して、セグメンテーションできるようにする。
発生している問題・エラーメッセージ
0% 0/3 [00:09<?, ?it/s] /usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py:566: UserWarning: This DataLoader will create 4 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary. cpuset_checked)) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-42-7c12d22518cb> in <module>() 8 steps_per_epoch=len(train_loader)) 9 ---> 10 history = fit(epoch, model, train_loader, valid_loader, criterion, optimizer, sched) 3 frames /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing) 3012 if size_average is not None or reduce is not None: 3013 reduction = _Reduction.legacy_get_string(size_average, reduce) -> 3014 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) 3015 3016 IndexError: Target 255 is out of bounds.
該当のソースコード
max_lr = 1e-3 epoch = 10 weight_decay = 1e-4 criterion = nn.CrossEntropyLoss() optimizer = torch.optim.AdamW(model.parameters(), lr=max_lr, weight_decay=weight_decay) sched = torch.optim.lr_scheduler.OneCycleLR(optimizer, max_lr, epochs=epoch, steps_per_epoch=len(train_loader)) history = fit(epoch, model, train_loader, valid_loader, criterion, optimizer, sched)
補足
https://colab.research.google.com/drive/1UN_hGntu28TF8-pEK89vmcLxHpi-wmDe?usp=sharing
↑にGoogle Colabのファイルをシェアしておきたいと思います。ここから、全コードを見ていただけると、わかりやすいかもしれません。





