You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In latest version of RegionProperties class, getattr is implemented. This function goes into recursive call when it is serialized and deserialized. while deserializing, setstate is called before init. Since setstate is not available, getattr is called, and since init has not yet been called, _extra_properties attribute is not defined which ends up calling getattr multiple times until recursion limit is reached.
Way to reproduce
importnumpyasnpimportosfromskimageimportmeasureimportpickledefcreate_fake_label_image():
all_ones=np.full((5,5), 1, dtype=int)
all_twos=np.full((5,5), 2, dtype=int)
all_zero=np.full((5,5), 0, dtype=int)
returnnp.concatenate((all_ones, all_zero, all_twos))
defregionProp_serialization_demo():
#generate region props from fake datalabel_img=create_fake_label_image()
regions=measure.regionprops(label_img)
#pickle and unpicklepickled=pickle.dumps(regions[0])
un_pickled=pickle.loads(pickled) #RecursionError hereif__name__=="__main__":
regionProp_serialization_demo()
Output
File "array_reader.py", line 32, in <module>
regionProp_serialization_demo()
File "array_reader.py", line 26, in regionProp_serialization_demo
un_pickled = pickle.loads(pickled) #RecursionError here
File "/usr/local/lib/python3.8/site-packages/skimage/measure/_regionprops.py", line 323, in __getattr__
if attr in self._extra_properties:
File "/usr/local/lib/python3.8/site-packages/skimage/measure/_regionprops.py", line 323, in __getattr__
if attr in self._extra_properties:
File "/usr/local/lib/python3.8/site-packages/skimage/measure/_regionprops.py", line 323, in __getattr__
if attr in self._extra_properties:
[Previous line repeated 994 more times]
RecursionError: maximum recursion depth exceeded
Workaround solution
This is the workaround I am thinking to use for now. I am new to python, can someone please review and let me know if this is the best way or if there is any other better way. A cleaner solution in the package would be the best.
Create a derived class that does not allow recursive call in getattr and use the derived class in client code
Sorry for the late response @anirudh44 and thank you for reporting this. You write-up and supplied code was very helpful! I can reproduce this.
While your suggested solution might do the trick I think a simpler solution is to use object.__getattribute__(self, "_extra_properties) instead of self._extra_properties. That way we can keep the fix to the actual function and don't need to track the state of an additional attribute. To be safe, object.__getattribute__ should probably be used for each access of instance attributes in that function.
Hey, there hasn't been any activity on this issue for more than 180 days. For now, we have marked it as "dormant" until there is some new activity. You are welcome to reach out to people by mentioning them here or on our forum if you need more feedback! If you think that this issue is no longer relevant, you may close it by yourself; otherwise, we may do it at some point (either way, it will be done manually). In any case, thank you for your contributions so far!
Description
In latest version of RegionProperties class, getattr is implemented. This function goes into recursive call when it is serialized and deserialized. while deserializing, setstate is called before init. Since setstate is not available, getattr is called, and since init has not yet been called, _extra_properties attribute is not defined which ends up calling getattr multiple times until recursion limit is reached.
Way to reproduce
Output
Workaround solution
This is the workaround I am thinking to use for now. I am new to python, can someone please review and let me know if this is the best way or if there is any other better way. A cleaner solution in the package would be the best.
Create a derived class that does not allow recursive call in getattr and use the derived class in client code
Version information
The text was updated successfully, but these errors were encountered: