Skip to content

class_weights cannot be passed via config file as a tensor is expected #2060

@robmarkcole

Description

@robmarkcole

Description

Using the Lightning CLI we can train the SemanticSegmentationTask, but cannot use class_weights without an error. Solution is to accept a list if int in addition to tensor

Steps to reproduce

In Lightning CLI Yaml:

model:
  class_path: SemanticSegmentationTask
  init_args:
    model: unet
    backbone: resnet50
    weights: null
    lr: 0.001
    in_channels: 6
    num_classes: 2
    class_weights:
      - 1
      - 50

Will result in

      Does not validate against any of the Union subtypes
      Subtypes: (<class 'torch.Tensor'>, <class 'NoneType'>)
      Errors:
        - Not a valid subclass of Tensor
          Subclass types expect one of:
          - a class path (str)
          - a dict with class_path entry
          - a dict without class_path but with init_args entry (class path given previously)
        - Expected a <class 'NoneType'>
      Given value type: <class 'list'>
      Given value: [1, 50]

Version

main

Metadata

Metadata

Assignees

No one assigned

    Labels

    scriptsTraining and evaluation scriptstrainersPyTorch Lightning trainers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions