Skip to content

Commit 82149c9

Browse files
committed
Replace torch Variable with torch tensor
Variable has been deprecated since PyTorch 0.4 (2018). We should use tensors directly.
1 parent 1dbea87 commit 82149c9

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

fmpose3d/animals/common/utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import numpy as np
1717
import torch
18-
from torch.autograd import Variable
1918

2019

2120
def mpjpe_cal(predicted, target):
@@ -225,13 +224,11 @@ def get_varialbe(split, target):
225224
var = []
226225
if split == "train":
227226
for i in range(num):
228-
temp = (
229-
Variable(target[i], requires_grad=False).contiguous().type(torch.cuda.FloatTensor)
230-
)
227+
temp = target[i].requires_grad_(False).contiguous().type(torch.cuda.FloatTensor)
231228
var.append(temp)
232229
else:
233230
for i in range(num):
234-
temp = Variable(target[i]).contiguous().cuda().type(torch.cuda.FloatTensor)
231+
temp = target[i].contiguous().cuda().type(torch.cuda.FloatTensor)
235232
var.append(temp)
236233

237234
return var

fmpose3d/common/utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import numpy as np
1717
import torch
18-
from torch.autograd import Variable
1918

2019
def deterministic_random(min_value, max_value, data):
2120
digest = hashlib.sha256(data.encode()).digest()
@@ -191,15 +190,11 @@ def get_varialbe(split, target):
191190
var = []
192191
if split == "train":
193192
for i in range(num):
194-
temp = (
195-
Variable(target[i], requires_grad=False)
196-
.contiguous()
197-
.type(torch.cuda.FloatTensor)
198-
)
193+
temp = target[i].requires_grad_(False).contiguous().type(torch.cuda.FloatTensor)
199194
var.append(temp)
200195
else:
201196
for i in range(num):
202-
temp = Variable(target[i]).contiguous().cuda().type(torch.cuda.FloatTensor)
197+
temp = target[i].contiguous().cuda().type(torch.cuda.FloatTensor)
203198
var.append(temp)
204199

205200
return var

0 commit comments

Comments
 (0)