这是本文档旧的修订版!
import torch # 导入 PyTorch 库,用于张量操作
import torch.nn.functional as F # 导入 PyTorch 的函数式 API,包含各种神经网络函数
import numpy as np # 导入 NumPy 库,用于数值计算
import matplotlib as mpl # 导入 Matplotlib 库的主模块
import matplotlib.pyplot as plt # 导入 Matplotlib 的绘图模块,用于显示图像
import imageio.v2 as imageio # 导入 imageio 库,用于读取图片文件
mpl.rcParams['figure.figsize'] = (12, 8) # 设置 Matplotlib 图表默认尺寸为 12x8 英寸
img = torch.FloatTensor(imageio.imread('imgs/hills_2.png')/255) # 读取图片,像素值归一化到[0,1],转为 PyTorch 浮点张量
print(type(img))
plt.imshow(img) # 使用 Matplotlib 显示图片
plt.show()