meetps / pytorch-semseg

Semantic Segmentation Architectures Implemented in PyTorch
https://meetshah.dev/semantic-segmentation/deep-learning/pytorch/visdom/2017/06/01/semantic-segmentation-over-the-years.html
MIT License
3.39k stars 798 forks source link

KeyError: 'n_workers' when trying to train #221

Closed ghost closed 5 years ago

ghost commented 5 years ago

Tried to run the train.py for ICNet using the README guide with Cityscapes dataset. Windows 10 CUDA 10.1 GPU: Nvidia GEFORCE GTX 1050Ti Using the Conda virtual environment. Issued the following command to train on the cityscapes dataset: python train.py --config configs\icnet_cityscapes.yml The output from the PowerShell window

train.py:217: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  cfg = yaml.load(fp)
RUNDIR: runs\icnet_cityscapes\83671
Found 2975 train images
Found 500 val images
Traceback (most recent call last):
  File "train.py", line 229, in <module>
    train(cfg, writer, logger)
  File "train.py", line 63, in train
    num_workers=cfg["training"]["n_workers"],
KeyError: 'n_workers'

The config file

model:
    arch: icnet
data:
    dataset: cityscapes
    train_split: train
    val_split: val
    img_rows: 512
    img_cols: 1024
    path: D:\Workspace\datasets\nn\cityscapes
training:
    train_iters: 85000
    batch_size: 2
    val_interval: 500
    print_interval: 25
    optimizer:
        lr: 1.0e-2
    l_rate: 1.0e-2
    l_schedule:
    momentum: 0.99
    weight_decay: 0.0005
    resume: icnet_cityscapes_best_model.pkl
    visdom: False
    loss:
        name: cross_entropy
keishatsai commented 5 years ago

Hi @reaktr4 Could you share the solution?I also encounter this issue. Thank you.

ghost commented 5 years ago

Hi @reaktr4 Could you share the solution?I also encounter this issue. Thank you.

Hi @keishatsai I solved it by specifying n_workers under the training section of the yaml file. Here is the sample config

model:
    arch: icnet
data:
    dataset: cityscapes
    train_split: train
    val_split: val
    img_rows: 512
    img_cols: 1024
    path: D:\Workspace\datasets\nn\cityscapes
training:
    train_iters: 85000
    batch_size: 2
    n_workers: 2 # a sample value
    val_interval: 500
    print_interval: 25
    optimizer:
        lr: 1.0e-2
    l_rate: 1.0e-2
    l_schedule:
    momentum: 0.99
    weight_decay: 0.0005
    resume: icnet_cityscapes_best_model.pkl
    visdom: False
    loss:
        name: cross_entropy

Hope this helps!

keishatsai commented 5 years ago

That is the big help. Thank you.

Now I got another error to fix.

ghost commented 5 years ago

That is the big help. Thank you.

Now I got another error to fix.

Glad to be of help! Did you manage to solve all the issues?

HareshKarnan commented 5 years ago

does using cross_entropy as the loss while training icnet work for you ?