基于ResNet-152模型的172种食物图像分类

2024-01-24 19:20

本文主要是介绍基于ResNet-152模型的172种食物图像分类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载自AI Studio 项目链接

https://aistudio.baidu.com/aistudio/projectdetail/3395323?contributionType=1&shared=1

一、项目背景和项目创意

  • 由于计算机视觉技术在监控摄像头、医疗保健等许多领域的应用越来越多。食品识别是其中一个重要的领域,由于其现实意义和科学挑战,值得进一步研究。
  • 最近,卷积神经网络(CNN)被用于食品识别。食物识别方法使用CNN模型提取食物图像特征,计算食物图像特征的相似度,并使用分类技术训练分类器来完成食物识别。
  • 此项目利用了VireoFood-172 数据集,其中包含了来自172个类别的110241张食品图片,并根据353种配料手工标注,以此来进行训练和测试。

二、项目搭建

Step1:准备数据

(1)数据集介绍

  • 本项目基于paddlepaddle,利用VireoFood-172 数据集进行相关开发,此数据集将食品分为172个大类,每大类中有200-1k张从从百度和谷歌图像搜索中抓取的食品图片,基本覆盖日常生活中的绝大多数食品种类。数据集数量庞大,质量较高,能够满足深度学习的训练要求。

(2)对数据集进行解压

!unzip -q -o data/data124758/splitedDataset.zip

(3)对数据集进行处理

  • 拿到数据集之后首先对数据集进行处理,按8:2的比例切割数据集之后进行随机打乱

(4)引入项目必须的模块

import paddle
import numpy as np
import os

(5)利用生成器获得训练集和测试集

  • 引入自己编写的生成器代码FoodDataset
  • 训练集:train_dataset = FoodDataset(train_data)
  • 测试集:eval_dataset = FoodDataset(validation_data)
  • train大小: 88192
  • eval大小: 22049
  • 符合按8:2的比例切割数据集
from dataset import FoodDataset
train_data = './train_data1.txt'
validation_data = './valida_data1.txt'train_dataset = FoodDataset(train_data)
eval_dataset = FoodDataset(validation_data)print('train大小:', train_dataset.__len__())
print('eval大小:', eval_dataset.__len__())# for data, label in train_dataset:
#     print(data)
#     print(np.array(data).shape)
#     print(label)
#     break
train大小: 88192
eval大小: 22049
class DenseFoodModel(paddle.nn.Layer):def __init__(self):super(DenseFoodModel, self).__init__()self.num_labels = 172def dense_block(self, x, blocks, name):for i in range(blocks):x = self.conv_block(x, 32, name=name + '_block' + str(i + 1))return xdef transition_block(self, x, reduction, name):bn_axis = 3x = paddle.nn.BatchNorm2D(num_features=x.shape[1], epsilon=1.001e-5)(x)x = paddle.nn.ELU(name=name + '_elu')(x)x = paddle.nn.Conv2D(in_channels=x.shape[1], out_channels=int(x.shape[1] * reduction),kernel_size=1, bias_attr=False)(x)x = paddle.nn.MaxPool2D(kernel_size=2, stride=2, name=name + '_pool')(x)return xdef conv_block(self, x, growth_rate, name):bn_axis = 3x1 = paddle.nn.BatchNorm2D(num_features=x.shape[1], epsilon=1.001e-5)(x)x1 = paddle.nn.ELU(name=name + '_0_elu')(x1)x1 = paddle.nn.Conv2D(in_channels=x1.shape[1], out_channels=4 * growth_rate, kernel_size= 1, bias_attr=False)(x1)x1 = paddle.nn.BatchNorm2D(num_features=x1.shape[1], epsilon=1.001e-5)(x1)x1 = paddle.nn.ELU(name=name + '_1_elu')(x1)x1 = paddle.nn.Conv2D(in_channels=x1.shape[1], out_channels=growth_rate, kernel_size=3, padding='SAME',bias_attr=False)(x1)# x = np.concatenate(([x, x1]), axis=1)# x = paddle.to_tensor(x)x = paddle.concat(x=[x, x1], axis=1)return xdef forward(self, input):# img_input = paddle.reshape(input, shape=[-1, 3, 224, 224])  # 转换维读bn_axis = 3x = paddle.nn.Conv2D(in_channels=3, out_channels=64, kernel_size=7, stride=2, bias_attr=False, padding=3)(input)x = paddle.nn.BatchNorm2D(num_features=64, epsilon=1.001e-5)(x)x = paddle.nn.ELU(name='conv1/elu')(x)x = paddle.nn.MaxPool2D(kernel_size=3, stride=2, name='pool1', padding=1)(x)x = self.dense_block(x, 6, name='conv2')x = self.transition_block(x, 0.5, name='pool2')x = self.dense_block(x, 12, name='conv3')x = self.transition_block(x, 0.5, name='pool3')x = self.dense_block(x, 24, name='conv4')x = self.transition_block(x, 0.5, name='pool4')x = self.dense_block(x, 16, name='conv5')x = paddle.nn.BatchNorm2D(num_features=x.shape[1], epsilon=1.001e-5)(x)x = paddle.nn.ELU(name='elu')(x)x = paddle.nn.AdaptiveAvgPool2D(output_size=1)(x)x = paddle.squeeze(x, axis=[2, 3])x = paddle.nn.Linear(in_features=1024, out_features=173)(x)x = F.softmax(x)return x
import paddle.nn.functional as Fmodel = paddle.Model(DenseFoodModel())
model.summary((-1, ) + tuple([3, 224, 224]))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/norm.py:653: UserWarning: When training, we now always track global mean and variance."When training, we now always track global mean and variance.")----------------------------------------------------------------------------Layer (type)       Input Shape          Output Shape         Param #    
============================================================================
DenseFoodModel-1  [[1, 3, 224, 224]]        [1, 173]              0       
============================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
----------------------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 0.00
Params size (MB): 0.00
Estimated Total Size (MB): 0.58
----------------------------------------------------------------------------{'total_params': 0, 'trainable_params': 0}

Step2.网络配置

(1)网络搭建

  • 此项目采用paddlepaddle自带的ResNet残差网络模型,ResNet残差模型快如下图所示:

  • x为残差块的输入,然后复制成两部分,一部分输入到层(weight layer)之中,进行层间的运算(相当于将x输入到一个函数中做映射),结果为f(x);另一部分作为分支结构,输出还是原本的x,最后将分别两部分的输出进行叠加:f(x) + x,再通过激活函数。这便是整个残差块的基本结构。

  • 下图是每种ResNet的具体结构:

  • 这里介绍一下ResNet152,152是指152次卷积。

  • 其中block共有3+8+36+3 = 50个,每个block是由3层卷积构成的,共150个卷积,最开始的一个卷积是将3通道的图片提取特征,最后一层是自适应平均池化,输出维度为1。

  • 一开始选用的是ResNet50图像分类模型,但是在进行了100多轮迭代训练后,正确率只能维持在88%左右,因此我们尝试变换模型重新进行训练,选用了ResNet101模型和ResNet152模型分别进行100轮迭代训练,最终,ResNet101模型的训练集正确率88%,测试集正确率80%,ResNet152模型训练集正确率达到了92%,测试集正确率达到了82%。

network = paddle.vision.models.resnet152(num_classes=173, pretrained=True)
model = paddle.Model(network)
model.summary((-1, ) + tuple([3, 224, 224]))
100%|██████████| 355826/355826 [00:09<00:00, 38920.04it/s]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py:1441: UserWarning: Skip loading for fc.weight. fc.weight receives a shape [2048, 1000], but the expected shape is [2048, 173].warnings.warn(("Skip loading for {}. ".format(key) + str(err)))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py:1441: UserWarning: Skip loading for fc.bias. fc.bias receives a shape [1000], but the expected shape is [173].warnings.warn(("Skip loading for {}. ".format(key) + str(err)))-------------------------------------------------------------------------------Layer (type)         Input Shape          Output Shape         Param #    
===============================================================================Conv2D-1        [[1, 3, 224, 224]]   [1, 64, 112, 112]        9,408     BatchNorm2D-1    [[1, 64, 112, 112]]   [1, 64, 112, 112]         256      ReLU-1        [[1, 64, 112, 112]]   [1, 64, 112, 112]          0       MaxPool2D-1     [[1, 64, 112, 112]]    [1, 64, 56, 56]           0       Conv2D-3        [[1, 64, 56, 56]]     [1, 64, 56, 56]         4,096     BatchNorm2D-3     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      ReLU-2         [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       Conv2D-4        [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     BatchNorm2D-4     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      Conv2D-5        [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     BatchNorm2D-5     [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     Conv2D-2        [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     BatchNorm2D-2     [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     BottleneckBlock-1   [[1, 64, 56, 56]]     [1, 256, 56, 56]          0       Conv2D-6        [[1, 256, 56, 56]]    [1, 64, 56, 56]        16,384     BatchNorm2D-6     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      ReLU-3         [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       Conv2D-7        [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     BatchNorm2D-7     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      Conv2D-8        [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     BatchNorm2D-8     [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     BottleneckBlock-2   [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       Conv2D-9        [[1, 256, 56, 56]]    [1, 64, 56, 56]        16,384     BatchNorm2D-9     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      ReLU-4         [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       Conv2D-10       [[1, 64, 56, 56]]     [1, 64, 56, 56]        36,864     BatchNorm2D-10     [[1, 64, 56, 56]]     [1, 64, 56, 56]          256      Conv2D-11       [[1, 64, 56, 56]]     [1, 256, 56, 56]       16,384     BatchNorm2D-11     [[1, 256, 56, 56]]    [1, 256, 56, 56]        1,024     BottleneckBlock-3   [[1, 256, 56, 56]]    [1, 256, 56, 56]          0       Conv2D-13       [[1, 256, 56, 56]]    [1, 128, 56, 56]       32,768     BatchNorm2D-13     [[1, 128, 56, 56]]    [1, 128, 56, 56]         512      ReLU-5         [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-14       [[1, 128, 56, 56]]    [1, 128, 28, 28]       147,456    BatchNorm2D-14     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-15       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-15     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     Conv2D-12       [[1, 256, 56, 56]]    [1, 512, 28, 28]       131,072    BatchNorm2D-12     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-4   [[1, 256, 56, 56]]    [1, 512, 28, 28]          0       Conv2D-16       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-16     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-6         [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-17       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-17     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-18       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-18     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-5   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-19       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-19     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-7         [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-20       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-20     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-21       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-21     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-6   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-22       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-22     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-8         [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-23       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-23     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-24       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-24     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-7   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-25       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-25     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-9         [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-26       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-26     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-27       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-27     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-8   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-28       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-28     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-10        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-29       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-29     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-30       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-30     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     BottleneckBlock-9   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-31       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-31     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-11        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-32       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-32     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-33       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-33     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-10   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-34       [[1, 512, 28, 28]]    [1, 128, 28, 28]       65,536     BatchNorm2D-34     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      ReLU-12        [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-35       [[1, 128, 28, 28]]    [1, 128, 28, 28]       147,456    BatchNorm2D-35     [[1, 128, 28, 28]]    [1, 128, 28, 28]         512      Conv2D-36       [[1, 128, 28, 28]]    [1, 512, 28, 28]       65,536     BatchNorm2D-36     [[1, 512, 28, 28]]    [1, 512, 28, 28]        2,048     
BottleneckBlock-11   [[1, 512, 28, 28]]    [1, 512, 28, 28]          0       Conv2D-38       [[1, 512, 28, 28]]    [1, 256, 28, 28]       131,072    BatchNorm2D-38     [[1, 256, 28, 28]]    [1, 256, 28, 28]        1,024     ReLU-13       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-39       [[1, 256, 28, 28]]    [1, 256, 14, 14]       589,824    BatchNorm2D-39     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-40       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-40    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     Conv2D-37       [[1, 512, 28, 28]]   [1, 1024, 14, 14]       524,288    BatchNorm2D-37    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-12   [[1, 512, 28, 28]]   [1, 1024, 14, 14]          0       Conv2D-41      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-41     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-14       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-42       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-42     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-43       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-43    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-13  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-44      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-44     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-15       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-45       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-45     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-46       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-46    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-14  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-47      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-47     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-16       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-48       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-48     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-49       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-49    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-15  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-50      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-50     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-17       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-51       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-51     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-52       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-52    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-16  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-53      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-53     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-18       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-54       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-54     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-55       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-55    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-17  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-56      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-56     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-19       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-57       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-57     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-58       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-58    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-18  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-59      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-59     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-20       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-60       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-60     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-61       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-61    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-19  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-62      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-62     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-21       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-63       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-63     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-64       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-64    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-20  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-65      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-65     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-22       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-66       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-66     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-67       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-67    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-21  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-68      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-68     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-23       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-69       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-69     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-70       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-70    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-22  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-71      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-71     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-24       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-72       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-72     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-73       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-73    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-23  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-74      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-74     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-25       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-75       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-75     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-76       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-76    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-24  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-77      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-77     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-26       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-78       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-78     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-79       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-79    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-25  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-80      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-80     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-27       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-81       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-81     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-82       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-82    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-26  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-83      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-83     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-28       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-84       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-84     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-85       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-85    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-27  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-86      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-86     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-29       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-87       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-87     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-88       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-88    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-28  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-89      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-89     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-30       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-90       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-90     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-91       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-91    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-29  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-92      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-92     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-31       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-93       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-93     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-94       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-94    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-30  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-95      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-95     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-32       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-96       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-96     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-97       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-97    [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-31  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-98      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-98     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-33       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-99       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-99     [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-100       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-100   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-32  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-101      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-101    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-34       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-102       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-102    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-103       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-103   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-33  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-104      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-104    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-35       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-105       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-105    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-106       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-106   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-34  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-107      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-107    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-36       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-108       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-108    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-109       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-109   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-35  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-110      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-110    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-37       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-111       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-111    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-112       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-112   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-36  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-113      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-113    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-38       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-114       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-114    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-115       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-115   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-37  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-116      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-116    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-39       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-117       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-117    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-118       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-118   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-38  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-119      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-119    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-40       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-120       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-120    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-121       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-121   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-39  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-122      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-122    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-41       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-123       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-123    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-124       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-124   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-40  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-125      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-125    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-42       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-126       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-126    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-127       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-127   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-41  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-128      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-128    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-43       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-129       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-129    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-130       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-130   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-42  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-131      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-131    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-44       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-132       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-132    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-133       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-133   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-43  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-134      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-134    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-45       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-135       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-135    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-136       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-136   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-44  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-137      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-137    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-46       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-138       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-138    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-139       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-139   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-45  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-140      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-140    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-47       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-141       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-141    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-142       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-142   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-46  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-143      [[1, 1024, 14, 14]]    [1, 256, 14, 14]       262,144    BatchNorm2D-143    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     ReLU-48       [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-144       [[1, 256, 14, 14]]    [1, 256, 14, 14]       589,824    BatchNorm2D-144    [[1, 256, 14, 14]]    [1, 256, 14, 14]        1,024     Conv2D-145       [[1, 256, 14, 14]]   [1, 1024, 14, 14]       262,144    BatchNorm2D-145   [[1, 1024, 14, 14]]   [1, 1024, 14, 14]        4,096     
BottleneckBlock-47  [[1, 1024, 14, 14]]   [1, 1024, 14, 14]          0       Conv2D-147      [[1, 1024, 14, 14]]    [1, 512, 14, 14]       524,288    BatchNorm2D-147    [[1, 512, 14, 14]]    [1, 512, 14, 14]        2,048     ReLU-49        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       Conv2D-148       [[1, 512, 14, 14]]     [1, 512, 7, 7]       2,359,296   BatchNorm2D-148     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     Conv2D-149        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   BatchNorm2D-149    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     Conv2D-146      [[1, 1024, 14, 14]]    [1, 2048, 7, 7]       2,097,152   BatchNorm2D-146    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-48  [[1, 1024, 14, 14]]    [1, 2048, 7, 7]           0       Conv2D-150       [[1, 2048, 7, 7]]      [1, 512, 7, 7]       1,048,576   BatchNorm2D-150     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     ReLU-50        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       Conv2D-151        [[1, 512, 7, 7]]      [1, 512, 7, 7]       2,359,296   BatchNorm2D-151     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     Conv2D-152        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   BatchNorm2D-152    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-49   [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       Conv2D-153       [[1, 2048, 7, 7]]      [1, 512, 7, 7]       1,048,576   BatchNorm2D-153     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     ReLU-51        [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       Conv2D-154        [[1, 512, 7, 7]]      [1, 512, 7, 7]       2,359,296   BatchNorm2D-154     [[1, 512, 7, 7]]      [1, 512, 7, 7]         2,048     Conv2D-155        [[1, 512, 7, 7]]     [1, 2048, 7, 7]       1,048,576   BatchNorm2D-155    [[1, 2048, 7, 7]]     [1, 2048, 7, 7]         8,192     
BottleneckBlock-50   [[1, 2048, 7, 7]]     [1, 2048, 7, 7]           0       
AdaptiveAvgPool2D-1  [[1, 2048, 7, 7]]     [1, 2048, 1, 1]           0       Linear-1           [[1, 2048]]            [1, 173]           354,477    
===============================================================================
Total params: 58,649,709
Trainable params: 58,346,861
Non-trainable params: 302,848
-------------------------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 552.42
Params size (MB): 223.73
Estimated Total Size (MB): 776.72
-------------------------------------------------------------------------------{'total_params': 58649709, 'trainable_params': 58346861}

(2)定义损失函数和准确率

  • 这次使用的是交叉熵损失函数,该函数在分类任务上比较常用。
  • 定义了一个损失函数之后,还有对它求平均值,因为定义的是一个Batch的损失值。
  • 同时我们还可以定义一个准确率函数,这个可以在我们训练的时候输出分类的准确率。

(3)定义优化方法

  • 这次我们使用的是Adam优化方法,同时指定学习率为0.001

Step3.训练模型与训练评估

分为三段式来训练样本:

  1. 0-19epoch 学习率0.01
  • 训练集:loss迅速下降,正确率经过二十轮迭代上升至0.80929

  • 测试集:loss迅速下降,正确率迅速上升至0.7384

  1. 从0-19的16开始断点续训14个epoch,学习率为0.001
  • 训练集:loss震荡下降,正确率从0.80929上升至0.85714

  • loss震荡,正确率从0.7384上升至0.7592

  1. 选取16+14=30的数据,断点续训11个epoch,学习率为0.0001
  • 训练集:loss震荡下降,正确率从0.85714上升至0.92927

  • 测试集:正确率趋于平稳,正确率取最高值0.82684,即第7个epoch

考虑到训练集持续上升而测试集接近收敛,继续训练会导致过拟合,故训练到此结束。

model.prepare(optimizer=paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters()),loss=paddle.nn.CrossEntropyLoss(),metrics=paddle.metric.Accuracy())# 训练可视化VisualDL工具的回调函数
visualdl = paddle.callbacks.VisualDL(log_dir='visualdl_log')# 启动模型全流程训练
model.fit(train_dataset,  # 训练数据集eval_dataset,  # 评估数据集epochs=20,  # 总的训练轮次batch_size=64,  # 批次计算的样本量大小shuffle=True,  # 是否打乱样本集verbose=1,  # 日志展示格式save_dir='0_20_resnet152_0.001',  # 分阶段的训练模型存储路径callbacks=[visualdl])     # 回调函数使用
The loss value printed in the log is the current step, and the metric is the average value of previous steps.
Epoch 1/20
step 1378/1378 [==============================] - loss: 2.0446 - acc: 0.2861 - 538ms/step         
save checkpoint at /home/aistudio/0_20_resnet152_0.001/0
Eval begin...
step 345/345 [==============================] - loss: 1.2795 - acc: 0.3776 - 256ms/step         
Eval samples: 22049
Epoch 2/20
step 1378/1378 [==============================] - loss: 1.5286 - acc: 0.5133 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/1
Eval begin...
step 345/345 [==============================] - loss: 0.7893 - acc: 0.5104 - 239ms/step         
Eval samples: 22049
Epoch 3/20
step 1378/1378 [==============================] - loss: 1.1590 - acc: 0.5851 - 524ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/2
Eval begin...
step 345/345 [==============================] - loss: 0.6739 - acc: 0.5879 - 240ms/step         
Eval samples: 22049
Epoch 4/20
step 1378/1378 [==============================] - loss: 1.1931 - acc: 0.6275 - 522ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/3
Eval begin...
step 345/345 [==============================] - loss: 0.2853 - acc: 0.6071 - 237ms/step         
Eval samples: 22049
Epoch 5/20
step 1378/1378 [==============================] - loss: 1.3321 - acc: 0.6558 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/4
Eval begin...
step 345/345 [==============================] - loss: 0.5777 - acc: 0.6388 - 242ms/step         
Eval samples: 22049
Epoch 6/20
step 1378/1378 [==============================] - loss: 1.4460 - acc: 0.6820 - 524ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/5
Eval begin...
step 345/345 [==============================] - loss: 0.5820 - acc: 0.6541 - 244ms/step         
Eval samples: 22049
Epoch 7/20
step 1378/1378 [==============================] - loss: 1.0251 - acc: 0.6960 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/6
Eval begin...
step 345/345 [==============================] - loss: 0.3825 - acc: 0.6865 - 239ms/step         
Eval samples: 22049
Epoch 8/20
step 1378/1378 [==============================] - loss: 0.8302 - acc: 0.7145 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/7
Eval begin...
step 345/345 [==============================] - loss: 0.0702 - acc: 0.6644 - 240ms/step         
Eval samples: 22049
Epoch 9/20
step 1378/1378 [==============================] - loss: 1.0031 - acc: 0.7274 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/8
Eval begin...
step 345/345 [==============================] - loss: 0.3258 - acc: 0.6950 - 240ms/step         
Eval samples: 22049
Epoch 10/20
step 1378/1378 [==============================] - loss: 0.9562 - acc: 0.7366 - 522ms/step         
save checkpoint at /home/aistudio/0_20_resnet152_0.001/9
Eval begin...
step 345/345 [==============================] - loss: 0.2758 - acc: 0.7111 - 240ms/step         
Eval samples: 22049
Epoch 11/20
step 1378/1378 [==============================] - loss: 0.9920 - acc: 0.7492 - 524ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/10
Eval begin...
step 345/345 [==============================] - loss: 0.1771 - acc: 0.7077 - 240ms/step         
Eval samples: 22049
Epoch 12/20
step 1378/1378 [==============================] - loss: 0.8259 - acc: 0.7558 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/11
Eval begin...
step 345/345 [==============================] - loss: 0.1928 - acc: 0.7075 - 241ms/step         
Eval samples: 22049
Epoch 13/20
step 1378/1378 [==============================] - loss: 0.8234 - acc: 0.7649 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/12
Eval begin...
step 345/345 [==============================] - loss: 0.4049 - acc: 0.7215 - 243ms/step         
Eval samples: 22049
Epoch 14/20
step 1378/1378 [==============================] - loss: 0.7254 - acc: 0.7730 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/13
Eval begin...
step 345/345 [==============================] - loss: 0.3297 - acc: 0.7173 - 239ms/step         
Eval samples: 22049
Epoch 15/20
step 1378/1378 [==============================] - loss: 0.7475 - acc: 0.7817 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/14
Eval begin...
step 345/345 [==============================] - loss: 0.1445 - acc: 0.7199 - 240ms/step         
Eval samples: 22049
Epoch 16/20
step 1378/1378 [==============================] - loss: 0.7856 - acc: 0.7905 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/15
Eval begin...
step 345/345 [==============================] - loss: 0.3110 - acc: 0.7332 - 238ms/step         
Eval samples: 22049
Epoch 17/20
step 1378/1378 [==============================] - loss: 1.0853 - acc: 0.7945 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/16
Eval begin...
step 345/345 [==============================] - loss: 0.2105 - acc: 0.7461 - 240ms/step         
Eval samples: 22049
Epoch 18/20
step 1378/1378 [==============================] - loss: 1.1084 - acc: 0.8027 - 523ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/17
Eval begin...
step 345/345 [==============================] - loss: 0.1809 - acc: 0.7313 - 241ms/step         
Eval samples: 22049
Epoch 19/20
step 1378/1378 [==============================] - loss: 1.1126 - acc: 0.8079 - 525ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/18
Eval begin...
step 345/345 [==============================] - loss: 0.0287 - acc: 0.7268 - 241ms/step         
Eval samples: 22049
Epoch 20/20
step 1378/1378 [==============================] - loss: 0.6276 - acc: 0.8125 - 524ms/step        
save checkpoint at /home/aistudio/0_20_resnet152_0.001/19
Eval begin...
step 345/345 [==============================] - loss: 0.2583 - acc: 0.7326 - 240ms/step         
Eval samples: 22049
save checkpoint at /home/aistudio/0_20_resnet152_0.001/final
# visualdl --logdir=visualdl_log/ --port=8040
# 终端运行此代码
  File "/tmp/ipykernel_101/1350602942.py", line 1visualdl --logdir=visualdl_log/ --port=8080^
SyntaxError: can't assign to operator
model.save('infer/mnist',training=False)  # 保存模型
---------------------------------------------------------------------------RuntimeError                              Traceback (most recent call last)/tmp/ipykernel_129/3232998588.py in <module>
----> 1 model.save('infer/mnist',training=False)  # 保存模型/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in save(self, path, training)1234         if ParallelEnv().local_rank == 0:1235             if not training:
-> 1236                 self._save_inference_model(path)1237             else:1238                 self._adapter.save(path)/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in _save_inference_model(self, path)1981                 if self._input_info is None:  # No provided or inferred1982                     raise RuntimeError(
-> 1983                         "Saving inference model needs 'inputs' or running before saving. Please specify 'inputs' in Model initialization or input training data and perform a training for shape derivation."1984                     )1985                 if self._is_shape_inferred:RuntimeError: Saving inference model needs 'inputs' or running before saving. Please specify 'inputs' in Model initialization or input training data and perform a training for shape derivation.

Step5.模型预测

  1. 读取模型参数
  2. 对预测图片进行预处理
  3. 开始预测
from PIL import Image
import paddle.vision.transforms as Tmodel_state_dict = paddle.load('50epoches_chk/final.pdparams')  # 读取模型
model = paddle.vision.models.resnet50(num_classes=173)
model.set_state_dict(model_state_dict)
model.eval()image_file = './splitedDataset/train/108/5_41.jpg'
# image_file = './splitedDataset/Yu-Shiang Shredded Pork.webp'
# braised pork in brown sauce.jfif \ 1.webp \ rice.jfif \ Yu-Shiang Shredded Pork.webp
transforms = T.Compose([T.RandomResizedCrop((224, 224)),  # 随机裁剪大小,裁剪地方不同等于间接增加了数据样本 300*300-224*224T.ToTensor(),  # 数据的格式转换和标准化 HWC => CHWT.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])  # 图像归一化
])
img = Image.open(image_file)  # 读取图片
if img.mode != 'RGB':img = img.convert('RGB')
img = transforms(img)
img = paddle.unsqueeze(img, axis=0)foodLabel = './FoodList.txt'
foodList = []
with open(foodLabel) as f:for line in f.readlines():info = line.split('\t')if len(info) > 0:foodList.append(info)ceshi = model(img)  # 测试
print('预测的结果为:', np.argmax(ceshi.numpy()), foodList[np.argmax(ceshi.numpy())-1])  # 获取值
Image.open(image_file)  # 显示图片
预测的结果为: 108 ['Four-Joy Meatballs\n']

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gnfdVBa3-1646533414153)(output_20_1.png)]

断点续训:

在训练初期,希望训练速度快,使用0.01的学习率。在此基础上需要更小的学习率继续训练,以获得更准确的正确率。

  1. 读取模型参数
  2. 读取优化器参数
  3. 对预测图片进行预处理
  4. 开始预测
import paddle.vision.transforms as T
import paddle
from dataset import FoodDatasettrain_data = './train_data1.txt'
validation_data = './valida_data1.txt'
train_dataset = FoodDataset(train_data)
eval_dataset = FoodDataset(validation_data)network = paddle.vision.models.resnet101(num_classes=173)
params_dict = paddle.load('15_15_resnet101_0.0001/final.pdparams')
network.set_state_dict(params_dict)
model = paddle.Model(network)opt = paddle.optimizer.Adam(learning_rate=0.0001, parameters=model.parameters())
opt_dict = paddle.load('15_15_resnet101_0.0001/final.pdopt')
opt.set_state_dict(opt_dict)model.prepare(optimizer=opt,loss=paddle.nn.CrossEntropyLoss(),metrics=paddle.metric.Accuracy())# 训练可视化VisualDL工具的回调函数
visualdl = paddle.callbacks.VisualDL(log_dir='visualdl_log')# 启动模型全流程训练
model.fit(train_dataset,  # 训练数据集eval_dataset,  # 评估数据集epochs=25,  # 总的训练轮次batch_size=64,  # 批次计算的样本量大小shuffle=True,  # 是否打乱样本集verbose=1,  # 日志展示格式save_dir='30_25_resnet101',  # 分阶段的训练模型存储路径batch_size=64,  # 批次计算的样本量大小shuffle=True,  # 是否打乱样本集verbose=1,  # 日志展示格式save_dir='30_25_resnet101',  # 分阶段的训练模型存储路径callbacks=[visualdl])     # 回调函数使用
W0129 23:08:45.468212  6682 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0129 23:08:45.472950  6682 device_context.cc:465] device: 0, cuDNN Version: 7.6.The loss value printed in the log is the current step, and the metric is the average value of previous steps.
Epoch 1/25/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop workingreturn (isinstance(seq, collections.Sequence) and
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/norm.py:653: UserWarning: When training, we now always track global mean and variance."When training, we now always track global mean and variance.")step   30/1378 [..............................] - loss: 0.4691 - acc: 0.8672 - ETA: 10:18 - 459ms/st

三、项目总结

  1. 实验结果
    本次实验基于paddlepaddle,利用VireoFood-172 数据集来实现食品识别。网络模型采用的是paddlepaddle自带的ResNet网络模型,可以解决深层网络梯度消失的问题。
    项目分为三段式来训练样本,第一段为0-19epoch 学习率为0.01,第二段为从0-19的16开始断点续训14个epoch,学习率为0.001,第三段选取16+14=30的数据,断点续训11个epoch,学习率为0.0001,训练结束时测试集正确率达到0.82684,训练集正确率达到0.92927。
  2. 实验分析
    项目一开始选用的是ResNet50模型,但是效果并不理想,因此我们尝试变换模型增加模型深度重新进行训练,选用了ResNet101模型和ResNet152模型,发现随着模型深度加深,训练集和测试集的正确率确实有明显的提升。
  3. 后续计划
    此项目测试集的最高正确率也只能达到0.82684,因此在后续的工作中,尝试使用其他的网络模型,或者继续调节网络模型的超参数,以此来提高训练集和测试集的正确率,这是后续的工作计划。

这篇关于基于ResNet-152模型的172种食物图像分类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/640729

相关文章

Golang的CSP模型简介(最新推荐)

《Golang的CSP模型简介(最新推荐)》Golang采用了CSP(CommunicatingSequentialProcesses,通信顺序进程)并发模型,通过goroutine和channe... 目录前言一、介绍1. 什么是 CSP 模型2. Goroutine3. Channel4. Channe

基于WinForm+Halcon实现图像缩放与交互功能

《基于WinForm+Halcon实现图像缩放与交互功能》本文主要讲述在WinForm中结合Halcon实现图像缩放、平移及实时显示灰度值等交互功能,包括初始化窗口的不同方式,以及通过特定事件添加相应... 目录前言初始化窗口添加图像缩放功能添加图像平移功能添加实时显示灰度值功能示例代码总结最后前言本文将

Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)

《Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)》:本文主要介绍Python基于火山引擎豆包大模型搭建QQ机器人详细的相关资料,包括开通模型、配置APIKEY鉴权和SD... 目录豆包大模型概述开通模型付费安装 SDK 环境配置 API KEY 鉴权Ark 模型接口Prompt

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

Andrej Karpathy最新采访:认知核心模型10亿参数就够了,AI会打破教育不公的僵局

夕小瑶科技说 原创  作者 | 海野 AI圈子的红人,AI大神Andrej Karpathy,曾是OpenAI联合创始人之一,特斯拉AI总监。上一次的动态是官宣创办一家名为 Eureka Labs 的人工智能+教育公司 ,宣布将长期致力于AI原生教育。 近日,Andrej Karpathy接受了No Priors(投资博客)的采访,与硅谷知名投资人 Sara Guo 和 Elad G

Retrieval-based-Voice-Conversion-WebUI模型构建指南

一、模型介绍 Retrieval-based-Voice-Conversion-WebUI(简称 RVC)模型是一个基于 VITS(Variational Inference with adversarial learning for end-to-end Text-to-Speech)的简单易用的语音转换框架。 具有以下特点 简单易用:RVC 模型通过简单易用的网页界面,使得用户无需深入了

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

图神经网络模型介绍(1)

我们将图神经网络分为基于谱域的模型和基于空域的模型,并按照发展顺序详解每个类别中的重要模型。 1.1基于谱域的图神经网络         谱域上的图卷积在图学习迈向深度学习的发展历程中起到了关键的作用。本节主要介绍三个具有代表性的谱域图神经网络:谱图卷积网络、切比雪夫网络和图卷积网络。 (1)谱图卷积网络 卷积定理:函数卷积的傅里叶变换是函数傅里叶变换的乘积,即F{f*g}