Torch.autograd.variable()インスタンスの使用法

import numpy as np
import torch
import torch.nn

datas = np.array([[1, 2], [3, 4]])
labels = np.array([[2, 3], [4, 5]])
loss_fn = torch.nn.MSELoss()

input = torch.autograd.Variable(torch.from_numpy(datas).float(), requires_grad=True)
target = torch.autograd.Variable(torch.from_numpy(labels).float(), requires_grad=True)
print(input)
print(target)

loss = loss_fn(input, target)
print(loss)

 

おすすめ

転載: blog.csdn.net/weixin_40823740/article/details/115319975