Code can run under the CPU.And I want to convert to GPU.
def train():
net = C3D()
net.cuda()
net.load_state_dict(torch.load(‘a.pickle’))
…
criterion = torch.nn.CrossEntropyLoss().cuda()
optimizer = optim.SGD(net.parameters(), lr=0.0001, momentum=0.9, weight_decay=0.0005)
for i in range(1,30001):
img1,first,label1 = getitem(random.randint(1,7507))
X=get_sport_clip(img1,first)
X = Variable(X)
#X.cpu()
X.cuda()
label1 = Variable(label1)
#label1.cpu()
label1.cuda()
output1 = net(X)
loss_contrastive = criterion(output1,label1)
optimizer.zero_grad()
loss_contrastive.backward()
optimizer.step()
    prediction = torch.max(F.softmax(output1), 1)[1].cuda()
    pred_y = prediction.data.numpy().squeeze()

def get_sport_clip(clip_name, first , verbose=True):
…
clip = np.float32(clip)
return torch.from_numpy(clip)
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 ‘weight’