一起读《动手学深度学习(PyTorch版)》- 线性神经网络 - 数据集处理
<div class='showpostmsg'><article data-content="[{"type":"block","id":"3060-1621846615933","name":"paragraph","data":{},"nodes":[{"type":"text","id":"p5PQ-1621846617594","leaves":[{"text":"协变量(covariate)、特征(feature)","marks":[]}]}],"state":{}},{"type":"block","id":"ETn1-1728396638234","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"M8JH-1728396638232","leaves":[{"text":"-> 特征的加权和或这说由权重组成的这种关系决定了目标怎么到达","marks":[]}]}],"state":{}},{"type":"block","id":"sR3b-1728396723109","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"WfS6-1728396723102","leaves":[{"text":"-> 权重决定了每个特征对于预测值的影响,更倾向于那种特征,像谁一点?","marks":[]}]}],"state":{}},{"type":"block","id":"kHfu-1728396768758","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"xV1s-1728396768751","leaves":[{"text":"-> 权重,是一组模型参数,需要质量的度量方式和提高模型预测质量的方法来寻找最佳参数","marks":[]}]}],"state":{}},{"type":"block","id":"b5WN-1728396926901","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"qSZV-1728396926894","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"bMbH-1728396928023","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"BToo-1728396928022","leaves":[{"text":"度量方式:损失函数(loss function)","marks":[]}]}],"state":{}},{"type":"block","id":"5p62-1728396952160","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"D0Qp-1728396952159","leaves":[{"text":"-> 量化目标实际和预测之间的差距,一般为非负数","marks":[]}]}],"state":{}},{"type":"block","id":"Lpp5-1728397015564","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"cX7y-1728397015557","leaves":[{"text":"-> 回归问题损失函数一般用平方误差函数","marks":[]}]}],"state":{}},{"type":"block","id":"54Io-1728397080521","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"YT3G-1728397080514","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Dul3-1728397081243","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"f8M7-1728397081242","leaves":[{"text":"提高方法:随机梯度下降","marks":[]}]}],"state":{}},{"type":"block","id":"Haus-1728397096506","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"YwTs-1728397096505","leaves":[{"text":"-> 随机抽取小批量样本,不断地在损失函数递减地方向上更新参数减小误差","marks":[]}]}],"state":{}},{"type":"block","id":"kdYc-1728397763099","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"LfSK-1728397763092","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"NWse-1728397764181","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"aaWF-1728397764180","leaves":[{"text":"超参数(hyperparamter),都是训练时固定的参数","marks":[]}]}],"state":{}},{"type":"block","id":"AHrK-1728397805748","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"prNu-1728397805747","leaves":[{"text":"-> 批量大小(batch size),每次小批量的样本数","marks":[]}]}],"state":{}},{"type":"block","id":"8D5f-1728397849875","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"Fy3p-1728397849868","leaves":[{"text":"-> 学习率(learning rate),每次更新的系数","marks":[]}]}],"state":{}},{"type":"block","id":"Yjw1-1728397926667","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"Q840-1728397926665","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"RHm5-1728397927391","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"izIT-1728397927389","leaves":[{"text":"泛化(generalization)","marks":[]}]}],"state":{}},{"type":"block","id":"84p5-1728397944029","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"FzEk-1728397944028","leaves":[{"text":"-> 一组能够在从未见过的数据上预测且误差较小的参数","marks":[]}]}],"state":{}},{"type":"block","id":"CPmM-1728398015384","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"B55l-1728398015382","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"k5FR-1728398016246","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"13iR-1728398016244","leaves":[{"text":"预测(prediction)和推断(inference)","marks":[]}]}],"state":{}},{"type":"block","id":"IGBI-1728398198977","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"JYQy-1728398198976","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"GfyJ-1728398199679","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"B9eV-1728398199678","leaves":[{"text":"神经网络图","marks":[]}]}],"state":{}},{"type":"block","id":"B6xm-1728398205595","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"MUSC-1728398205594","leaves":[{"text":"-> 输入层的输入数可以称为特征维度(feature dimensionality)","marks":[]}]}],"state":{}},{"type":"block","id":"5ILN-1728398310192","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"Zgg6-1728398310191","leaves":[{"text":"-> 当每个输入都和每个输出连接,称为全连接层(fully-connected layer)或者稠密层(dense layer)","marks":[]}]}],"state":{}},{"type":"block","id":"LqZ0-1728918457174","name":"paragraph","data":{"style":{"textIndent":28}},"nodes":[{"type":"text","id":"BX38-1728918457171","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"6xlB-1728918457286","name":"heading","data":{"level":"h3","style":{"textIndent":0}},"nodes":[{"type":"text","id":"07uS-1728918457285","leaves":[{"text":"softmax实践","marks":[]}]}],"state":{}},{"type":"block","id":"mJQP-1728918468538","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"Fwnk-1728918468537","leaves":[{"text":"使用FasionMNIST数据集,显示样本","marks":[]}]}],"state":{}}]"><p>协变量(covariate)、特征(feature)</p>
<p> -> 特征的加权和或这说由权重组成的这种关系决定了目标怎么到达</p>
<p> -> 权重决定了每个特征对于预测值的影响,更倾向于那种特征,像谁一点?</p>
<p> -> 权重,是一组模型参数,需要质量的度量方式和提高模型预测质量的方法来寻找最佳参数</p>
<p>度量方式:损失函数(loss function)</p>
<p> -> 量化目标实际和预测之间的差距,一般为非负数</p>
<p> -> 回归问题损失函数一般用平方误差函数</p>
<p>提高方法:随机梯度下降</p>
<p> -> 随机抽取小批量样本,不断地在损失函数递减地方向上更新参数减小误差</p>
<p>超参数(hyperparamter),都是训练时固定的参数</p>
<p> -> 批量大小(batch size),每次小批量的样本数</p>
<p> -> 学习率(learning rate),每次更新的系数</p>
<p>泛化(generalization)</p>
<p> -> 一组能够在从未见过的数据上预测且误差较小的参数</p>
<p>预测(prediction)和推断(inference)</p>
<p>神经网络图</p>
<p> -> 输入层的输入数可以称为特征维度(feature dimensionality)</p>
<p> -> 当每个输入都和每个输出连接,称为全连接层(fully-connected layer)或者稠密层(dense layer)</p>
<p>softmax实践</p>
<p>使用FasionMNIST数据集,显示样本</p>
<pre>
<code>import torch
import torchvision
from torch.utils import data
from torchvision import transforms
import matplotlib.pyplot as plt
trans = transforms.ToTensor()
mnist_train = torchvision.datasets.FashionMNIST(root = "./data", train=True, transform=trans, download=True)
mnist_test = torchvision.datasets.FashionMNIST(root = "./data", train=True, transform=trans, download=True)
# print(len(mnist_train), len(mnist_test), mnist_train, mnist_train)
print(mnist_train.shape)
def get_fasion_mnist_labels(labels):
# labels is num dict
text_lables = ['t-shirt', 'trouser', 'pullover', "dress", "coat", "sandal", "shirt", "sneaker", "bag", "ankle boot"]
return for i in labels]
print(get_fasion_mnist_labels())
def show_images(imgs, num_rows, num_cols, titles=None, scale=1.5):
figsize = (num_cols * scale, num_rows * scale)
_, axes = plt.subplots(num_rows, num_cols, figsize=figsize)
# axes is n*m to 1*nm
axes = axes.flatten()
for i, (ax, img) in enumerate(zip(axes, imgs)):
if torch.is_tensor(img):
ax.imshow(img.numpy())
else:
ax.imshow(img)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
if titles:
ax.set_title(titles)
plt.show()
return axes
X, y = next(iter(data.DataLoader(mnist_train, batch_size=18)))
show_images(X.reshape(18,28,28), 2, 9 ,titles=get_fasion_mnist_labels(y))
</code></pre>
<p> </p>
<article data-content="[{"type":"block","id":"tice-1728919427709","name":"paragraph","data":{},"nodes":[{"type":"text","id":"kAm5-1728919427710","leaves":[{"text":"使用内置的数据迭代器,进行随机读取小批量","marks":[]}]}],"state":{}}]">
<p>使用内置的数据迭代器,进行随机读取小批量</p>
<pre>
<code>train_iter = data.DataLoader(mnist_train, batch_size, shuffle=True, num_workers=get_dataloader_workers())
X1, y1 = next(iter(train_iter))
show_images(X1.reshape(batch_size, 28, 28), 16, 16, titles=get_fasion_mnist_labels(y1))</code></pre>
<p>运行1次</p>
<article _blank="" data-content="[{"type":"block","name":"image","data":{"version":1,"url":"<a target=">
<p> </p>
<article data-content="[{"type":"block","id":"UzjH-1728919412224","name":"paragraph","data":{"style":{"textIndent":0}},"nodes":[{"type":"text","id":"I4kt-1728919412223","leaves":[{"text":"再运行1次,和上一次的结果时不一样的","marks":[]}]}],"state":{}}]">
<p>再运行1次,和上一次的结果时不一样的</p>
<p> </p>
</article>
</article>
</article>
</article>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]