How can I change this GPU code to CPU code?


(Smetana Moldau) #1

Hi, All.

This is my simple GPU code in PyTorch.

How can I change this in CPU code?

filename=r’/Users/dti/Desktop/PyTorch4testAccuracy/hymenoptera_data/test/bees/1.jpg’
img = skimage.io.imread(filename)

x = V(centre_crop(img).unsqueeze(0), volatile=True).cuda()

model = models.dict’resnet18’
model = torch.nn.DataParallel(model).cuda()

model = torch.load(‘model5.pth’)

logit = model(x)
print(logit)

Thanks in advance .


(Solomon K ) #2

An example:

use_cuda = torch.cuda.is_available()
if use_cuda:
        X_tensor = Variable(torch.from_numpy(x_data_np).cuda()) # Note the conversion for pytorch    
    else:
        X_tensor = Variable(torch.from_numpy(x_data_np)) # Note the conversion for pytorch

(Iacopo Poli) #3

remove the .cuda() and the torch.nn.DataParallel

filename=r’/Users/dti/Desktop/PyTorch4testAccuracy/hymenoptera_data/test/bees/1.jpg’
img = skimage.io.imread(filename)

x = V(centre_crop(img).unsqueeze(0), volatile=True)

model = models.dict['resnet18']
model = torch.load('model5.pth')

logit = model(x)
print(logit)

(Smetana Moldau) #4

Thanks, iacolippo.

It works ~!


(Smetana Moldau) #5

Thanks ~

at any rate …!