Skip to content

Commit

Permalink
Update th.py to works with python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
pythoscorpion authored Jul 14, 2023
1 parent 954592b commit b9f15e6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mit_semseg/lib/utils/th.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
def as_variable(obj):
if isinstance(obj, Variable):
return obj
if isinstance(obj, collections.Sequence):
if isinstance(obj, collections.abc.Sequence):
return [as_variable(v) for v in obj]
elif isinstance(obj, collections.Mapping):
elif isinstance(obj, collections.abc.Mapping):
return {k: as_variable(v) for k, v in obj.items()}
else:
return Variable(obj)

def as_numpy(obj):
if isinstance(obj, collections.Sequence):
if isinstance(obj, collections.abc.Sequence):
return [as_numpy(v) for v in obj]
elif isinstance(obj, collections.Mapping):
elif isinstance(obj, collections.abc.Mapping):
return {k: as_numpy(v) for k, v in obj.items()}
elif isinstance(obj, Variable):
return obj.data.cpu().numpy()
Expand All @@ -33,9 +33,9 @@ def mark_volatile(obj):
if isinstance(obj, Variable):
obj.no_grad = True
return obj
elif isinstance(obj, collections.Mapping):
elif isinstance(obj, collections.abc.Mapping):
return {k: mark_volatile(o) for k, o in obj.items()}
elif isinstance(obj, collections.Sequence):
elif isinstance(obj, collections.abc.Sequence):
return [mark_volatile(o) for o in obj]
else:
return obj

0 comments on commit b9f15e6

Please sign in to comment.