主要用于本人学习机器学习模型
学了很多神经网络模型,但是只知道大体框架,具体的实现细节在复制粘贴中也无法明晰
故以下试用tensor,并观察其内部在卷积时的变化
import torch
import numpy as np
import pandas as pd
b = np.array([[1,2,3],[4,5,6],[7,8,9]])
b_torch = torch.from_numpy(b)
print(b_torch)
tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], dtype=torch.int32)
然后为了试验卷积随机生成一个稍微大些的array转化为tensor
这里要注意c作为array的维数,否则在作卷积的时候会出现维数差异;并且为方便卷积,生成tensor时将其float()化
c = np.random.random_integers(1,20,size=(1,15,15))
c_torch = torch.from_numpy(c).float()
print(c_torch)
tensor([[[18., 14., 8., 5., 13., 16., 3., 13., 5., 10., 1., 4., 19., 13.,
18.],
[11., 18., 4., 13., 4., 20., 6., 11., 5., 12., 15., 7., 1., 19.,
3.],
[14., 8., 18.,