Skip to content

Commit 59ea767

Browse files
committed
use torch.no_grad instead of volatile
1 parent 3363156 commit 59ea767

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

preprocess-images.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ def main():
5959
coco_ids = fd.create_dataset('ids', shape=(len(loader.dataset),), dtype='int32')
6060

6161
i = j = 0
62-
for ids, imgs in tqdm(loader):
63-
imgs = Variable(imgs.cuda(async=True), volatile=True)
64-
out = net(imgs)
65-
66-
j = i + imgs.size(0)
67-
features[i:j, :, :] = out.data.cpu().numpy().astype('float16')
68-
coco_ids[i:j] = ids.numpy().astype('int32')
69-
i = j
62+
with torch.no_grad():
63+
for ids, imgs in tqdm(loader):
64+
imgs = Variable(imgs.cuda(async=True))
65+
out = net(imgs)
66+
67+
j = i + imgs.size(0)
68+
features[i:j, :, :] = out.data.cpu().numpy().astype('float16')
69+
coco_ids[i:j] = ids.numpy().astype('int32')
70+
i = j
7071

7172

7273
if __name__ == '__main__':

0 commit comments

Comments
 (0)