深度学习框架 Torch 7 问题笔记 1. 尝试第一个 CNN 的 torch版本, 代码如下: -- We now have 5 steps left to do in training our first torch neural network -- 1. Load and normalize data -- 2. Define Neural Network -- 3. Define Loss function -- 4. Train network on training data -
经常可以看到调用torch.view(-1,28*28)之类的调用,那么这里的-1是什么意思呢,经过查看文档view()得到了一下结果: view()返回的数据和传入的tensor一样,只是形状不同 -1在这里的意思是让电脑帮我们计算,比如下面的例子,总长度是20,我们不想自己算\(20/5=4\),就可以在不想算的位置放上-1,电脑就会自己计算对应的数字,这个在实际搭建网络的时候是很好用的 还要注意view()返回的tensor和传入的tensor共享内存,意思就是修改其中一个,数据都会变 i
import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.pyplot as plt # torch.manual_seed(1) # reproducible # make fake data n_data = torch.ones(100, 2) x0 = torch.normal(2*n_data, 1) # class0 x data (tensor
真正掌握一种算法,最实际的方法,完全手写出来. LSTM(Long Short Tem Memory)特殊递归神经网络,神经元保存历史记忆,解决自然语言处理统计方法只能考虑最近n个词语而忽略更久前词语的问题.用途:word representation(embedding)(词语向量).sequence to sequence learning(输入句子预测句子).机器翻译.语音识别等. 100多行原始python代码实现基于LSTM二进制加法器.https://iamtrask.github.
numpy.expand_dims(a, axis) Expand the shape of an array. Insert a new axis that will appear at the axis position in the expanded array shape. Parameters: a : array_like Input array. axis : int Position in the expanded axes where the new axis is place
先看看简单例子: import torch import torch.autograd as autograd import torch.nn as nn import torch.nn.functional as F import torch.optim as optim torch.manual_seed(1) 1 2 3 4 5 6 7 用torch.tensor让list成为tensor: # Create a 3D tensor of size 2x2x2. T_data = [[[1