I have a problem that had been bothering me for some days now…
In the following code I have a model imported from lua, when I run forward with gpu=False the results are fine.
But when I use gpu=True, one of my models gives reasonable results and another one gives garbage.
Also, if I try to convert model and batch to double when I run on cpu the results are also bad.
If anyone has any idea of why this happens I would be very happy to get your help.
num_imgs = images_array.shape # convert into torch tensor tensor_array = torch.from_numpy(images_array.astype(np.float64)) tensor_array = tensor_array.transpose(3, 1).transpose(3, 2) _, ch, center_h, center_w = tensor_array.size() new_centers = torch.zeros(num_imgs, ch, int(center_w/2), int(center_h/2)) # loading model and running forward model = load_lua(model_path) if gpu: model.double() model.cuda() else: model.float() model.evaluate() # running in batches num_batches = int(num_imgs/batch_size) for i in range(0,num_imgs,batch_size): if verbose: print('batch: ',i/batch_size,'/',num_batches) if i+batch_size <= num_imgs: cur_batch = tensor_array[i:i+batch_size, :, :, :].clone() else: cur_batch = tensor_array[i:, :, :, :].clone() cur_batch = cur_batch.float() if gpu: cur_batch = cur_batch.cuda() print('forward!') result = model.forward(cur_batch) new_centers[i:i+batch_size, :, :, :] = result.cpu() # recreating output new_centers = new_centers.transpose(3, 2).transpose(3, 1) new_centers_np = new_centers.numpy() # in case of a single image reduce a dimension if len(images_array.shape) == 3: new_centers_np = np.squeeze(new_centers_np) # removing model from GPU del model return new_centers_np