
pytorch学习笔记
你知道烟火吗
随时私信,欢迎技术交流
展开
-
python——enumerate的用法
seq = 'hello'for i, key in enumerate(seq): print('seq[%d]=%c',%(i,key))'''输出:seq[0]=hseq[1]=eseq[2]=lseq[3]=lseq[4]=o'''seq = ['a', 'b', 'c', 'd']for i, key in enumerate(seq[::-1]) print 'seq[%d]=%c',%(i,key)''' seq[0]=dseq[1]=cseq[2]=bse原创 2020-11-16 19:32:05 · 200 阅读 · 0 评论 -
pytorch——pytorch.nn.Linear
import torchx = torch.randn(128, 20) # 输入的维度是(128,20)m = torch.nn.Linear(20, 30) # 20,30是指维度output = m(x)print('m.weight.shape:\n ', m.weight.shape)print('m.bias.shape:\n', m.bias.shape)print('output.shape:\n', output.shape)# ans = torch.mm(inpu原创 2020-11-14 17:05:56 · 195 阅读 · 0 评论 -
pytorch——batch_size
1 定义单次训练用的样本数,通常为2^N,如32、64、1282 提出背景在batch_size概念没提出之前,神经网络的训练每一个epoch需要将所有的数据一次性加载训练,使得内存负载加大。这样会准确计算梯度方向更准确,但不同梯度值差异过大,无法确定全局的学习率。在这样的条件下,batch_size被提出来了。3 合适的batch_size训练的优点使内存利用率增大,加快训练速度使梯度方向计算更准确,收敛快...原创 2020-11-14 16:25:31 · 2424 阅读 · 0 评论 -
python——求微分
import torchdef f(x): return (x-2).pow(2)def fp(x):#f(x)的求导 return 2*(x-2)x = torch.tensor([3.0], requires_grad=True)#x=3时的导数y = f(x)y.backward()#反向传播#对比print(fp(x))print(x.grad)原创 2020-11-14 15:14:49 · 404 阅读 · 0 评论 -
python——plt.text
plt.text(0,0.5,'loss:%.4f '%loss.data.numpy(),#%.4f格式化输出,保留四位小数点 fontdict={'size': 20, 'color': 'red'}#字体尺寸20,颜色 红色) #第一和第二个参数0,0.5表示输出信息的坐标,原点坐标是(0,0)...原创 2020-11-14 15:01:06 · 1875 阅读 · 0 评论