深度学习图片分类模型总结(附部分代码)

参考视频:2.1 pytorch官方demo(Lenet)_哔哩哔哩_bilibili

LeNet(1998)

pytorch 示例

笔记

  1. Pytorch Tensor的通道排序:[batch,channel,height,width]

  2. 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.

  3. 为什么每计算一个batch就需要调用一次optimizer.zero_grad():

    1. PyTorch中在反向传播前为什么要手动将梯度清零? - 知乎
  4. pytorch官网:-docs可查看各个函数的用法,-tutorials可以查看示例

  5. data = torch.max(outputs, dim=1), then data will be a tuple containing two tensors.

    1. data[0]: This tensor will contain the maximum values along dimension 1 (the class dimension) of the outputs tensor. It will have a shape of [batch], where batch is the number of validation images in the batch.
    2. data[1]: This tensor will contain the indices of the maximum values along dimension 1 (the class dimension) of the outputs 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.
  6. get the size of a tensor along a specific dimension, you use the method size() or the property shape[].

    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]
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值