question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: 'n_workers' when trying to train

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ghostcommented, Jul 10, 2019

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!

0reactions
HareshKarnancommented, Sep 28, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyError occur when start training #958 - ultralytics/yolov5
Currently, I work on a face detection. I use the following command to train. python train.py --img 640 --batch 16 --epochs 5 --data...
Read more >
KeyError 'metrics' when trying to train a model in tensorflow
I was working off some github code where I'm training a model to recognize laughter. This particular bit of code is giving me...
Read more >
Train Deep Learning Model fails with KeyError: '0'
Solved: Hi all, I am trying to train and apply a Deep Learning model in ArcGis Pro 8.0 . I installed all the...
Read more >
Only 5 out of 6 items are loaded to training dataset
I'm trying to load 6 different items to the training dataset, ... 430 431 KeyError: Caught KeyError in DataLoader worker process 0.
Read more >
Getting KeyError: 'id' even when 'id' is present in the json file
Context: I am trying to train the VOC dataset on this few shot object detection library called FewX and in order to do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found