https://discuss.pytorch.org/t/how-to-modify-the-final-fc-layer-based-on-the-torch-model/766/12
That’s because vgg19 doesn’t have a fc member variable. Instead, it has a
(classifier): Sequential (
(0): Dropout (p = 0.5)
(1): Linear (25088 -> 40
神经网络只是由两个或多个线性网络层叠加,并不能学到新的东西,简单地堆叠网络层,不经过非线性激活函数激活,学到的仍然是线性关系。
但是加入激活函数可以学到非线性的关系,就具有更强的能力去进行特征提取。
构造数据
import torch
import torch.nn.functional as F
from torch.autograd import Variable
import matplotlib.pyplot as plt
x = torch.linspace(-5, 5, 200)