DingYuan0118.github.io

Pytorch学习笔记

dataloader与dataset

CUDA的使用

Batchnormal层的使用

具体原理参考Juliuszh的高赞文章

ResNet解析

Performance Tuning Guide

参考pytorch tutorial

Parameters与Buffer的区别

二者均记录至model.state_dict()方法中,state_dict()返回一个OrderedDict,其中存储着模型的所有参数.

常用画图函数

import matplotlib.pyplot as plt
def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
    if not isinstance(imgs[0], list):
        # Make a 2d grid even if there's just 1 row
        imgs = [imgs]

    num_rows = len(imgs)
    num_cols = len(imgs[0]) + with_orig
    fig, axs = plt.subplots(nrows=num_rows, ncols=num_cols, squeeze=False)
    for row_idx, row in enumerate(imgs):
        row = [orig_img] + row if with_orig else row
        for col_idx, img in enumerate(row):
            ax = axs[row_idx, col_idx]
            ax.imshow(np.asarray(img), **imshow_kwargs)
            ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])

    if with_orig:
        axs[0, 0].set(title='Original image')
        axs[0, 0].title.set_size(8)
    if row_title is not None:
        for row_idx in range(num_rows):
            axs[row_idx, 0].set(ylabel=row_title[row_idx])

    plt.tight_layout()

如何快速对模型指定层进行操作?

通过将funcmodel.apply 方法联合使用,可以达到对网络中同一类别的层进行指定操作。