Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid first argument to register(). ForwardRef('PredictedInstance') is not a class. #968

Closed
talmo opened this issue Sep 20, 2022 Discussed in #966 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@talmo
Copy link
Collaborator

talmo commented Sep 20, 2022

In Python 3.9+, it looks like cattrs breaks when structuring forward references. At the moment this only affects M1 Macs which will use Python 3.9 environments by default, but will be an issue across all platforms in the future.

This crops up when loading a project that has an instance created from predictions such that the Instance.from_predicted field is not None (i.e., set to a PredictedInstance). Here's where this is handled:

sleap/sleap/instance.py

Lines 1228 to 1249 in be89412

# Function to determine object type for objects being structured.
def structure_instances_list(x, type):
inst_list = []
for inst_data in x:
if "score" in inst_data.keys():
inst = converter.structure(inst_data, PredictedInstance)
else:
inst = converter.structure(inst_data, Instance)
inst_list.append(inst)
return inst_list
converter.register_structure_hook(
Union[List[Instance], List[PredictedInstance]], structure_instances_list
)
# Structure forward reference for PredictedInstance for the Instance.from_predicted
# attribute.
converter.register_structure_hook(
ForwardRef("PredictedInstance"),
lambda x, _: converter.structure(x, PredictedInstance),
)

This can be worked around using the approach described in python-attrs/cattrs#206.

See below for original user post that reported this.

Discussed in #966

Originally posted by gaojundong September 20, 2022
Hi Team,

When I try to save the skeleton instance as a new project, a window suddenly popped up to remind me:

An error occured when attempting to save:
Invalid first argument to register(). ForwardRef('PredictedInstance') is not a class.
Try saving your project with a different filename or in a different format.

I try to modify the file name as label.slp and label.v001.slp, but it still doesn't work. this is my software version:
Software versions:
SLEAP: 1.2.8
TensorFlow: 2.9.2
Numpy: 1.22.3
Python: 3.9.13
OS: macOS-12.5.1-arm64-arm-64bit

In this software, I can save skeleton node and edges and export video, but I don't know where is the problem when I save the whole project. Can you give me some hints about this. Thank you very much.

All the best,
Gaojun

@talmo talmo added bug Something isn't working fixed in future release Fix or feature is merged into develop and will be available in future release. labels Sep 20, 2022
@roomrys roomrys closed this as completed Nov 11, 2022
@roomrys roomrys removed the fixed in future release Fix or feature is merged into develop and will be available in future release. label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants