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

fix: AugmentedTensor clone method #191

Merged
merged 1 commit into from
Jul 5, 2022
Merged

fix: AugmentedTensor clone method #191

merged 1 commit into from
Jul 5, 2022

Conversation

jsalotti
Copy link
Contributor

Problem

Some mutable attributes of the original tensor were not deeply copied to the clone tensor. Therefore a modification of these attributes in the clone tensor was also applied to the original tensor.
Attributes : _property_list, _children_list, _child_property

Exemple

Adding a child to the cloned tensor modifies the original tensor, which cannot be cloned again.

f = Frame(torch.ones((2, 5, 5)))
clone1 = f.clone()
clone1.add_child("childname", SpatialAugmentedTensor(torch.ones((2, 5, 5)), names=("C", "H", "W")))
clone2 = f.clone()

results in this error :

Traceback (most recent call last):
  File "_sandbox/clone.py", line 7, in <module>
    clone2 = f.clone()
  File "/home/julien/dev/aloception/aloscene/tensors/augmented_tensor.py", line 321, in clone
    n_frame = super().clone(*args, **kwargs)
  File "/home/julien/dev/aloception/aloscene/tensors/augmented_tensor.py", line 586, in __torch_function__
    setattr(tensor, name, getattr(self, name))
  File "/home/julien/dev/aloception/aloscene/tensors/augmented_tensor.py", line 1027, in __getattribute__
    return super().__getattribute__(name)
AttributeError: 'Frame' object has no attribute 'childname'

Solution

Make a deep copy of the attributes instead of a shallow one

@jsalotti jsalotti added bug Something isn't working aloscene aloscene labels Jun 15, 2022
@jsalotti jsalotti requested a review from thibo73800 June 15, 2022 14:07
@jsalotti jsalotti self-assigned this Jun 15, 2022
@thibo73800 thibo73800 merged commit 91db508 into master Jul 5, 2022
@thibo73800 thibo73800 deleted the fix_clone branch July 5, 2022 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aloscene aloscene bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants