Python Examples of torch.from_numpy - ProgramCreek.com
www.programcreek.com › 101297 › torchdef run_batch(inputs, outputs_gt, model, criterion, optimizer, train): """Train or validate on a batch (inputs + outputs).""" if train: model.train() else: model.eval() val = not train inputs, outputs_gt = torch.from_numpy(inputs), torch.from_numpy(outputs_gt) inputs, outputs_gt = Variable(inputs, volatile=val), Variable(outputs_gt) if GPU >= 0: inputs = inputs.cuda(GPU) outputs_gt = outputs_gt.cuda(GPU) if train: optimizer.zero_grad() outputs_pred = model(inputs) loss = criterion(outputs ...