I have a code in which following line is written but when I ran it, some warnings occurred quoting use no_grad.
What should I do for this command? Please tell the alternate.
def batchrun(image_batch, model):
image_batch = torch.FloatTensor(image_batch).cuda()
image_batch = torch.autograd.Variable(image_batch, volatile=True)
feats = model(image_batch)
feats = feats.data.cpu().clone().numpy()
return feats
albanD
(Alban D)
December 28, 2020, 5:23pm
2
Hi, you should change it to:
def batchrun(image_batch, model):
image_batch = torch.tensor(image_batch, dtype=torch.float32, device="cuda")
with torch.no_grad():
feats = model(image_batch)
feats = feats.detach().cpu().clone().numpy()
return feats
1 Like
Just to be sure the code was like this, so the alternate you gave according to mine is correct?
def batchrun(image_batch, model):
image_batch = torch.FloatTensor(image_batch).cuda()
image_batch = torch.autograd.Variable(image_batch, volatile=True)
feats = model(image_batch)
feats = feats.data.cpu().clone().numpy()
return feats
albanD
(Alban D)
December 30, 2020, 10:24am
4
Yes that’s the same code as above no? So the alternative is still the same.
1 Like
Thanks a lot! It is working.