Skip to content

Commit efea540

Browse files
bottlerfacebook-github-bot
authored andcommitted
Fix camera clone() with torch.save
Summary: User reported that cloned cameras fail to save. The error with latest PyTorch is ``` pickle.PicklingError: Can't pickle ~T_destination: attribute lookup T_destination on torch.nn.modules.module failed ``` This fixes it. Reviewed By: btgraham Differential Revision: D39692258 fbshipit-source-id: 75bbf3b8dfa0023dc28bf7d4cc253ca96e46a64d
1 parent ce3fce4 commit efea540

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pytorch3d/renderer/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import copy
99
import inspect
1010
import warnings
11-
from typing import Any, List, Optional, Tuple, Union
11+
from typing import Any, List, Optional, Tuple, TypeVar, Union
1212

1313
import numpy as np
1414
import torch
@@ -191,7 +191,7 @@ def clone(self, other) -> "TensorProperties":
191191
"""
192192
for k in dir(self):
193193
v = getattr(self, k)
194-
if inspect.ismethod(v) or k.startswith("__"):
194+
if inspect.ismethod(v) or k.startswith("__") or type(v) is TypeVar:
195195
continue
196196
if torch.is_tensor(v):
197197
v_clone = v.clone()

tests/test_cameras.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# SOFTWARE.
3232

3333
import math
34+
import pickle
3435
import typing
3536
import unittest
3637
from itertools import product
@@ -1333,6 +1334,11 @@ def test_getitem(self):
13331334
# Check in_ndc is handled correctly
13341335
self.assertEqual(cam._in_ndc, c0._in_ndc)
13351336

1337+
def test_clone_picklable(self):
1338+
camera = PerspectiveCameras()
1339+
pickle.dumps(camera)
1340+
pickle.dumps(camera.clone())
1341+
13361342

13371343
############################################################
13381344
# FishEye Camera #

0 commit comments

Comments
 (0)