dymaxionlabs/unetseg

unetseg 0.2.3: fails when importing train module

Closed this issue · 6 comments

Using the current unetseg version, attempts to import functions from the train module fail with:

ValueError: mutable default <class 'list'> for field class_weights is not allowed: use default_factory

Example:

https://colab.research.google.com/drive/1lQj2Kib94tUuOuN4zibg72F0Rc8LOcb6?usp=sharing

It's an update on pydantic library. default_factory is an optional argument now and default argument is mandatory, so it should be:

class Example(BaseModel):
    custom: Dict[str, Any] = Field(default={})

@munshkr Is it easy to resolve?

Hello everyone, I have the same error, how can I solve it?

Hi I saw the code example in colab file shared by @bitsandbricks . The problem seems to be with the class TrainConfig in https://github.com/dymaxionlabs/unetseg/blob/main/unetseg/train.py#L34-L53

I thought you were using pydantic, but instead you are using dataclasses from python, then the recommended way should be to use field function for default complex values like list and dicts, so the code could be refactored as:

@dataclass
class TrainConfig:
    images_path: str
    ....
    ....
    class_weights: List[float] = field(default_factory=list)

Also it's possible (but i'm not sure) that this error happens in some versions of python and not in others, I tested on python 3.8.
Finally, field function requires a factory function for mutable values, because that list is used as function and not as a call like list()

Hi ! indeed that fixed the error. I just updated the code in github and soon it will be in python as well
Thanks!

Good job! Closing the issue