提交 ec2ee103 编写于 作者: S Shaojie Bai

update for pytorch 1.0 with nograd

上级 a13a6b82
......@@ -100,6 +100,7 @@ def train(epoch):
def evaluate():
model.eval()
with torch.no_grad():
output = model(X_test)
test_loss = F.mse_loss(output, Y_test)
print('\nTest set: Average loss: {:.6f}\n'.format(test_loss.item()))
......
......@@ -85,6 +85,7 @@ optimizer = getattr(optim, args.optim)(model.parameters(), lr=lr)
def evaluate():
model.eval()
with torch.no_grad():
out = model(test_x.unsqueeze(1).contiguous())
loss = criterion(out.view(-1, n_classes), test_y.view(-1))
pred = out.view(-1, n_classes).data.max(1, keepdim=True)[1]
......
......@@ -88,6 +88,7 @@ def evaluate(data_source):
total_loss = 0
processed_data_size = 0
correct = 0
with torch.no_grad():
for i in range(len(data_source)):
data, targets = torch.LongTensor(data_source[i]).view(1, -1), torch.LongTensor([data_source[i][-1]]).view(1, -1)
data, targets = Variable(data), Variable(targets)
......
......@@ -97,6 +97,7 @@ def test():
model.eval()
test_loss = 0
correct = 0
with torch.no_grad():
for data, target in test_loader:
if args.cuda:
data, target = data.cuda(), target.cuda()
......
......@@ -68,6 +68,7 @@ def evaluate(X_data, name='Eval'):
eval_idx_list = np.arange(len(X_data), dtype="int32")
total_loss = 0.0
count = 0
with torch.no_grad():
for idx in eval_idx_list:
data_line = X_data[idx]
x, y = Variable(data_line[:-1]), Variable(data_line[1:])
......
......@@ -92,6 +92,7 @@ def evaluate(data_source):
model.eval()
total_loss = 0
processed_data_size = 0
with torch.no_grad():
for i in range(0, data_source.size(1) - 1, args.validseqlen):
if i + args.seq_len - args.validseqlen >= data_source.size(1) - 1:
continue
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册