第三章 3.3 使用pytorch的数据集
1.第一章: PyTorch计算机视觉实战:目标检测、图像处理与深度学习2.《Pytorch 最全入门介绍,Pytorch入门看这一篇就够了》学习3.第二章 2.3 使用Pytorch构建神经网络4.第二章 2.3.1 定义数据集训练神经网络5.第二章 2.4使用序贯方法构建神经网络nn.Sequential() 及打印神经网络模型摘要6.第二章 2.5 保存和加载文件中Pytorch模型7.第三章 3.1 表示图像 理解灰度图、RGB图和数组的关系
8.第三章 3.3 使用pytorch的数据集
9.第三章 3.4 训练神经网络10.第三章 3.6 批大小的影响11.第三章:3.8.1 绘制各层参数分布图 hist12.第三章 3.9 在训练过程中修改学习率13.第三章 3.10 构建更深的神经网络 比较有0、1、2隐含层的神经网络14.第三章 3.12 dropout 和 正则化 克服过拟合比较复杂,可以将代码放在AI(温馨一眼)中做解读
代码:
# https://github.com/PacktPublishing/Modern-Computer-Vision-with-PyTorch # https://github.com/PacktPublishing/Modern-Computer-Vision-with-PyTorch ################### Chapter Three ####################################### # 第三章 读取数据集并显示 from torchvision import datasets import torch ######################################################################## data_folder = '~/data/FMNIST' # This can be any directory you want # to download FMNIST to fmnist = datasets.FashionMNIST(data_folder, download=False, train=True) ######################################################################## tr_images = fmnist.data #图像 tr_targets = fmnist.targets #标签 ######################################################################## #检查张量 unique_values = tr_targets.unique() print(f'train_images_shape: {tr_images.shape}') print(f'train_targets_shape: {tr_targets.shape}') print(f'train_targets_unique_values:{unique_values}') print(f'train_targets_classes: {fmnist.classes}') ######################################################################## import matplotlib.pyplot as plt #matplotlib inline import numpy as np R, C = len(tr_targets.unique()), 10 fig, ax = plt.subplots(R, C, figsize=(10,10)) for label_class, plot_row in enumerate(ax): label_x_rows = np.where(tr_targets == label_class)[0] for plot_cell in plot_row: plot_cell.grid(False); plot_cell.axis('off') ix = np.random.choice(label_x_rows) x, y = tr_images[ix], tr_targets[ix] plot_cell.imshow(x, cmap='gray') plt.tight_layout() plt.show()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)