facebookresearch / facebookresearch/foundpose
NameError: name 'asdict' is not defined
- Dominant language
- Python
- Stars
- 139
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
When running the inference script, I encounter an error in utils/misc.py on the line `asdict(obj).items()`. The error message indicates that asdict is not defined. I realized that the asdict function from the dataclasses module was not imported. I added dataclasses.asdict(obj).items() at the beginning to resolve this.
However, as mentioned in the previous comment, this solution does not work for NamedTuple instances. Therefore, I modified the code to differentiate between dataclass and NamedTuple instances. The final code looks like this:
```
if isinstance(obj, Mapping):
return ty((k, map_fields(func, v, only_type)) for (k, v) in obj.items())
elif dataclasses.is_dataclass(obj):
# Dataclass
return ty(
**{k: map_fields(func, v, only_type) for (k, v) in dataclasses.asdict(obj).items()}
)
else:
# NamedTuple
return ty(
**{k: map_fields(func, v, only_type) for (k, v) in obj._asdict().items()}
)
```
Contributor guide
Assessment
This issue has not been assessed yet.