参考视频:2.1 pytorch官方demo(Lenet)_哔哩哔哩_bilibili
LeNet(1998)
笔记
-
Pytorch Tensor的通道排序:[batch,channel,height,width]
-
CIFAR10 dataset: It has the classes: ‘airplane’, ‘automobile’, ‘bird’, ‘cat’, ‘deer’, ‘dog’, ‘frog’, ‘horse’, ‘ship’, ‘truck’. The images in CIFAR-10 are of size 3x32x32, i.e. 3-channel color images of 32x32 pixels in size.
-
为什么每计算一个batch就需要调用一次optimizer.zero_grad():
-
pytorch官网:-docs可查看各个函数的用法,-tutorials可以查看示例
-
data = torch.max(outputs, dim=1)
, thendata
will be a tuple containing two tensors.data[0]
: This tensor will contain the maximum values along dimension 1 (the class dimension) of theoutputs
tensor. It will have a shape of[batch]
, wherebatch
is the number of validation images in the batch.data[1]
: This tensor will contain the indices of the maximum values along dimension 1 (the class dimension) of theoutputs
tensor. It will also have a shape of[batch]
, where each element represents the predicted class label (index) for each validation image in the batch.
-
get the size of a tensor along a specific dimension, you use the method
size()
or the propertyshape[]
.import torch # Assuming val_label is a tensor with shape [batch_size, ...] # Using size() method size_along_first_dim = val_label.size(0) # Using shape property size_along_first_dim = val_label.shape[0]