keras_retinanet 目标检测——自定义图片数据集的模型训练步骤

最近在学习 keras_retinanet ,下面就记录下用自己的数据集进行的模型训练。

大致分为以下几步:

  • 自定义训练数据
  • 图片目标标注
  • 生成用于训练的图片名称、目标标注位置及目标类别的.csv文件
  • 开始训练模型(注意参数调整)
  • 转换训练好的模型
  • 用转换后的模型进行目标检测

下面就一步一步介绍吧:

目录

1.下载包,安装环境。

2.准备数据集

3.训练模型

4.目标检测


由于我之前已经安装了vs2015、Anaconda和Pycharm,就不在此赘述了。

本机配置:

  • GTX 1060 3G       
  • Win10 64              
  • vs2015                    
  • Anaconda3 5.1.0  
  • Pycharm                  

1.下载包,安装环境。

  • 从Github上下载Github ——> keras-retinanet这个仓库
  • 确保你的环境里有tensorflow、numpy、keras
  • 切换到当前目录下运行
    pip install . --user

    或者直接从克隆的仓库中运行代码,但是需要运行python setup.py build_ext --inplace来首先编译Cython代码。

  • 如果还不行就把keras_retinanet这整个目录拷贝到你自己环境的D:\Anaconda3-5.0.1\envs\tf-gpu\Lib\site-packages下

测试准备:点击测试模型下载,将用于测试的模型resnet50_coco_best_v2.1.0.h5放在snapshots目录下

下面就可以在jupyter notebook运行examples里的ResNet50RetinaNet.ipynb进行测试,当然也可以在jupyter notebook中将文件保存成.py格式的在pycharm里运行。

2.准备数据集

  • retinanet模型训练的数据是按照VOC2007格式处理的,所以你也需要将自己的数据准备成VOC2007的格式
  1. 准备如图三个文件夹,JPEGImages放你自己准备训练模型的图片,图片名称最好是按1.jpg,2.jpg这种类型;
  2. Annotations放图片目标的位置和类型标注的.xml文件,这个可以用Github——>labellmgkeras_retinanet 目标检测——自定义图片数据集的模型训练步骤_第1张图片里的生成目标标注的工具自动生成.xml的文件(注意使用时将保存路径改到Annotations文件夹);
  3. ImageSets里的子文件夹Main里放按比例随机抽样切分的训练集、验证集、测试集样本下标值的txt文件,这个可以用如下gen_main_txt.py自动生成
    import os
    import random
    
    trainval_percent = 0.8  # 自定义用于训练模型的数据(训练数据和交叉验证数据之和)占全部数据的比例
    train_percent = 0.8  # 自定义训练数据占训练数据交叉验证数据之和的比例
    xmlfilepath = 'Annotations'
    txtsavepath = 'ImageSets\Main'
    total_xml = os.listdir(xmlfilepath)
    
    num = len(total_xml)
    list = range(num)
    tv = int(num * trainval_percent)
    tr = int(tv * train_percent)
    trainval = random.sample(list, tv)
    train = random.sample(trainval, tr)
    
    ftrainval = open('ImageSets/Main/trainval.txt', 'w')
    ftest = open('ImageSets/Main/test.txt', 'w')
    ftrain = open('ImageSets/Main/train.txt', 'w')
    fval = open('ImageSets/Main/val.txt', 'w')
    
    for i in list:
        name = total_xml[i][:-4]+'\n'
        if i in trainval:
            ftrainval.write(name)
            if i in train:
                ftrain.write(name)
            else:
                fval.write(name)
        else:
            ftest.write(name)
    
    ftrainval.close()
    ftrain.close()
    fval.close()
    ftest .close()

     

  4. 生成包含文件名、目标位置、目标类型的annotations.csv文件和类别标签的classes.csv文件,这个可以用gen_csv.py自动生成
    import csv
    import os
    import glob
    import sys
    
    class PascalVOC2CSV(object):
        def __init__(self, xml=[], ann_path='./annotations.csv', classes_path='./classes.csv'):
            '''
            :param xml: 所有Pascal VOC的xml文件路径组成的列表
            :param ann_path: ann_path
            :param classes_path: classes_path
            '''
            self.xml = xml
            self.ann_path = ann_path
            self.classes_path = classes_path
            self.label = []
            self.annotations = []
    
            self.data_transfer()
            self.write_file()
    
        def data_transfer(self):
            for num, xml_file in enumerate(self.xml):
                try:
                    # print(xml_file)
                    # 进度输出
                    sys.stdout.write('\r>> Converting image %d/%d' % (
                        num + 1, len(self.xml)))
                    sys.stdout.flush()
    
                    with open(xml_file, 'r') as fp:
                        for p in fp:
                            if '' in p:
                                self.filen_ame = p.split('>')[1].split('<')[0]
    
                            if '' in p:
                                # 类别
                                d = [next(fp).split('>')[1].split('<')[0] for _ in range(9)]
                                self.supercategory = d[0]
                                if self.supercategory not in self.label:
                                    self.label.append(self.supercategory)
    
                                # 边界框
                                x1 = int(d[-4]);
                                y1 = int(d[-3]);
                                x2 = int(d[-2]);
                                y2 = int(d[-1])
    
                                self.annotations.append(
                                    [os.path.join('JPEGImages', self.filen_ame), x1, y1, x2, y2, self.supercategory])
                except:
                    continue
    
            sys.stdout.write('\n')
            sys.stdout.flush()
    
        def write_file(self, ):
            with open(self.ann_path, 'w', newline='') as fp:
                csv_writer = csv.writer(fp, dialect='excel')
                csv_writer.writerows(self.annotations)
    
            class_name = sorted(self.label)
            class_ = []
            for num, name in enumerate(class_name):
                class_.append([name, num])
            with open(self.classes_path, 'w', newline='') as fp:
                csv_writer = csv.writer(fp, dialect='excel')
                csv_writer.writerows(class_)
    
    if __name__ == "__main__":
        xml_file = glob.glob('./Annotations/*.xml')
        PascalVOC2CSV(xml_file) 

     

  5. 用keras-retinanet-master\keras_retinanet\bin目录下的debug.py测试数据集是否生成成功,这个程序需要在命令行执行
    python D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/keras_retinanet/bin/debug.py csv  D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/examples/annotations.csv  D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/examples/classes.csv

    弹出你标注的图片说明数据准备成功。

  6. 3.训练模型

    • 用keras-retinanet-master\keras_retinanet\bin目录下的train.py来训练模型,需要修改文件里import的相对路径
      from keras_retinanet import layers  # noqa: F401
      from keras_retinanet import losses
      from keras_retinanet import models
      from keras_retinanet.callbacks import RedirectModel
      from keras_retinanet.callbacks.eval import Evaluate
      from keras_retinanet.models.retinanet import retinanet_bbox
      from keras_retinanet.preprocessing.csv_generator import CSVGenerator
      from keras_retinanet.preprocessing.kitti import KittiGenerator
      from keras_retinanet.preprocessing.open_images import OpenImagesGenerator
      from keras_retinanet.preprocessing.pascal_voc import PascalVocGenerator
      from keras_retinanet.utils.anchors import make_shapes_callback
      from keras_retinanet.utils.config import read_config_file, parse_anchor_parameters
      from keras_retinanet.utils.keras_version import check_keras_version
      from keras_retinanet.utils.model import freeze as freeze_model
      from keras_retinanet.utils.transform import random_transform_generator

       

    • 根据你自己GPU的性能微调参数,如果报tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[1,256,100,100]错误说明你的GPU内存不够用,可以通过降低batch-size、将image-min-side,image-max-side改小、改小网络结构等方式解决
      tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[1,256,100,100] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
               [[{{node training/Adam/gradients/classification_submodel/pyramid_classification_3/convolution_grad/Conv2DBackpropInput}} = Conv2DBackpropInput[T=DT_FLOAT, _class=["loc:@training/Adam/cond_85/Switch_2"], data_format="NCHW", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](training/Adam/gradients/classification_submodel/pyramid_classification_3/convolution_grad/ShapeN, pyramid_classification_3/kernel/read, training/Adam/gradients/classification_submodel/pyramid_classification_3/Relu_grad/ReluGrad)]]
      Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

      参数调整:

    keras_retinanet 目标检测——自定义图片数据集的模型训练步骤_第2张图片

    • 修改workers参数(不知道为什么多线程会出错,就暂且不开启吧)

    • 在命令行运行train.py文件
      python D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/keras_retinanet/bin/train.py csv  D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/examples/annotations.csv  D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/examples/classes.csv

      创建模型,网络结构如下 

    Creating model, this may take a second...
    __________________________________________________________________________________________________
    Layer (type)                    Output Shape         Param #     Connected to
    ==================================================================================================
    input_1 (InputLayer)            (None, None, None, 3 0
    __________________________________________________________________________________________________
    padding_conv1 (ZeroPadding2D)   (None, None, None, 3 0           input_1[0][0]
    __________________________________________________________________________________________________
    conv1 (Conv2D)                  (None, None, None, 6 9408        padding_conv1[0][0]
    __________________________________________________________________________________________________
    bn_conv1 (BatchNormalization)   (None, None, None, 6 256         conv1[0][0]
    __________________________________________________________________________________________________
    conv1_relu (Activation)         (None, None, None, 6 0           bn_conv1[0][0]
    __________________________________________________________________________________________________
    pool1 (MaxPooling2D)            (None, None, None, 6 0           conv1_relu[0][0]
    __________________________________________________________________________________________________
    res2a_branch2a (Conv2D)         (None, None, None, 6 4096        pool1[0][0]
    __________________________________________________________________________________________________
    bn2a_branch2a (BatchNormalizati (None, None, None, 6 256         res2a_branch2a[0][0]
    __________________________________________________________________________________________________
    res2a_branch2a_relu (Activation (None, None, None, 6 0           bn2a_branch2a[0][0]
    __________________________________________________________________________________________________
    padding2a_branch2b (ZeroPadding (None, None, None, 6 0           res2a_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res2a_branch2b (Conv2D)         (None, None, None, 6 36864       padding2a_branch2b[0][0]
    __________________________________________________________________________________________________
    bn2a_branch2b (BatchNormalizati (None, None, None, 6 256         res2a_branch2b[0][0]
    __________________________________________________________________________________________________
    res2a_branch2b_relu (Activation (None, None, None, 6 0           bn2a_branch2b[0][0]
    __________________________________________________________________________________________________
    res2a_branch2c (Conv2D)         (None, None, None, 2 16384       res2a_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    res2a_branch1 (Conv2D)          (None, None, None, 2 16384       pool1[0][0]
    __________________________________________________________________________________________________
    bn2a_branch2c (BatchNormalizati (None, None, None, 2 1024        res2a_branch2c[0][0]
    __________________________________________________________________________________________________
    bn2a_branch1 (BatchNormalizatio (None, None, None, 2 1024        res2a_branch1[0][0]
    __________________________________________________________________________________________________
    res2a (Add)                     (None, None, None, 2 0           bn2a_branch2c[0][0]
                                                                     bn2a_branch1[0][0]
    __________________________________________________________________________________________________
    res2a_relu (Activation)         (None, None, None, 2 0           res2a[0][0]
    __________________________________________________________________________________________________
    res2b_branch2a (Conv2D)         (None, None, None, 6 16384       res2a_relu[0][0]
    __________________________________________________________________________________________________
    bn2b_branch2a (BatchNormalizati (None, None, None, 6 256         res2b_branch2a[0][0]
    __________________________________________________________________________________________________
    res2b_branch2a_relu (Activation (None, None, None, 6 0           bn2b_branch2a[0][0]
    __________________________________________________________________________________________________
    padding2b_branch2b (ZeroPadding (None, None, None, 6 0           res2b_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res2b_branch2b (Conv2D)         (None, None, None, 6 36864       padding2b_branch2b[0][0]
    __________________________________________________________________________________________________
    bn2b_branch2b (BatchNormalizati (None, None, None, 6 256         res2b_branch2b[0][0]
    __________________________________________________________________________________________________
    res2b_branch2b_relu (Activation (None, None, None, 6 0           bn2b_branch2b[0][0]
    __________________________________________________________________________________________________
    res2b_branch2c (Conv2D)         (None, None, None, 2 16384       res2b_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn2b_branch2c (BatchNormalizati (None, None, None, 2 1024        res2b_branch2c[0][0]
    __________________________________________________________________________________________________
    res2b (Add)                     (None, None, None, 2 0           bn2b_branch2c[0][0]
                                                                     res2a_relu[0][0]
    __________________________________________________________________________________________________
    res2b_relu (Activation)         (None, None, None, 2 0           res2b[0][0]
    __________________________________________________________________________________________________
    res2c_branch2a (Conv2D)         (None, None, None, 6 16384       res2b_relu[0][0]
    __________________________________________________________________________________________________
    bn2c_branch2a (BatchNormalizati (None, None, None, 6 256         res2c_branch2a[0][0]
    __________________________________________________________________________________________________
    res2c_branch2a_relu (Activation (None, None, None, 6 0           bn2c_branch2a[0][0]
    __________________________________________________________________________________________________
    padding2c_branch2b (ZeroPadding (None, None, None, 6 0           res2c_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res2c_branch2b (Conv2D)         (None, None, None, 6 36864       padding2c_branch2b[0][0]
    __________________________________________________________________________________________________
    bn2c_branch2b (BatchNormalizati (None, None, None, 6 256         res2c_branch2b[0][0]
    __________________________________________________________________________________________________
    res2c_branch2b_relu (Activation (None, None, None, 6 0           bn2c_branch2b[0][0]
    __________________________________________________________________________________________________
    res2c_branch2c (Conv2D)         (None, None, None, 2 16384       res2c_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn2c_branch2c (BatchNormalizati (None, None, None, 2 1024        res2c_branch2c[0][0]
    __________________________________________________________________________________________________
    res2c (Add)                     (None, None, None, 2 0           bn2c_branch2c[0][0]
                                                                     res2b_relu[0][0]
    __________________________________________________________________________________________________
    res2c_relu (Activation)         (None, None, None, 2 0           res2c[0][0]
    __________________________________________________________________________________________________
    res3a_branch2a (Conv2D)         (None, None, None, 1 32768       res2c_relu[0][0]
    __________________________________________________________________________________________________
    bn3a_branch2a (BatchNormalizati (None, None, None, 1 512         res3a_branch2a[0][0]
    __________________________________________________________________________________________________
    res3a_branch2a_relu (Activation (None, None, None, 1 0           bn3a_branch2a[0][0]
    __________________________________________________________________________________________________
    padding3a_branch2b (ZeroPadding (None, None, None, 1 0           res3a_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res3a_branch2b (Conv2D)         (None, None, None, 1 147456      padding3a_branch2b[0][0]
    __________________________________________________________________________________________________
    bn3a_branch2b (BatchNormalizati (None, None, None, 1 512         res3a_branch2b[0][0]
    __________________________________________________________________________________________________
    res3a_branch2b_relu (Activation (None, None, None, 1 0           bn3a_branch2b[0][0]
    __________________________________________________________________________________________________
    res3a_branch2c (Conv2D)         (None, None, None, 5 65536       res3a_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    res3a_branch1 (Conv2D)          (None, None, None, 5 131072      res2c_relu[0][0]
    __________________________________________________________________________________________________
    bn3a_branch2c (BatchNormalizati (None, None, None, 5 2048        res3a_branch2c[0][0]
    __________________________________________________________________________________________________
    bn3a_branch1 (BatchNormalizatio (None, None, None, 5 2048        res3a_branch1[0][0]
    __________________________________________________________________________________________________
    res3a (Add)                     (None, None, None, 5 0           bn3a_branch2c[0][0]
                                                                     bn3a_branch1[0][0]
    __________________________________________________________________________________________________
    res3a_relu (Activation)         (None, None, None, 5 0           res3a[0][0]
    __________________________________________________________________________________________________
    res3b_branch2a (Conv2D)         (None, None, None, 1 65536       res3a_relu[0][0]
    __________________________________________________________________________________________________
    bn3b_branch2a (BatchNormalizati (None, None, None, 1 512         res3b_branch2a[0][0]
    __________________________________________________________________________________________________
    res3b_branch2a_relu (Activation (None, None, None, 1 0           bn3b_branch2a[0][0]
    __________________________________________________________________________________________________
    padding3b_branch2b (ZeroPadding (None, None, None, 1 0           res3b_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res3b_branch2b (Conv2D)         (None, None, None, 1 147456      padding3b_branch2b[0][0]
    __________________________________________________________________________________________________
    bn3b_branch2b (BatchNormalizati (None, None, None, 1 512         res3b_branch2b[0][0]
    __________________________________________________________________________________________________
    res3b_branch2b_relu (Activation (None, None, None, 1 0           bn3b_branch2b[0][0]
    __________________________________________________________________________________________________
    res3b_branch2c (Conv2D)         (None, None, None, 5 65536       res3b_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn3b_branch2c (BatchNormalizati (None, None, None, 5 2048        res3b_branch2c[0][0]
    __________________________________________________________________________________________________
    res3b (Add)                     (None, None, None, 5 0           bn3b_branch2c[0][0]
                                                                     res3a_relu[0][0]
    __________________________________________________________________________________________________
    res3b_relu (Activation)         (None, None, None, 5 0           res3b[0][0]
    __________________________________________________________________________________________________
    res3c_branch2a (Conv2D)         (None, None, None, 1 65536       res3b_relu[0][0]
    __________________________________________________________________________________________________
    bn3c_branch2a (BatchNormalizati (None, None, None, 1 512         res3c_branch2a[0][0]
    __________________________________________________________________________________________________
    res3c_branch2a_relu (Activation (None, None, None, 1 0           bn3c_branch2a[0][0]
    __________________________________________________________________________________________________
    padding3c_branch2b (ZeroPadding (None, None, None, 1 0           res3c_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res3c_branch2b (Conv2D)         (None, None, None, 1 147456      padding3c_branch2b[0][0]
    __________________________________________________________________________________________________
    bn3c_branch2b (BatchNormalizati (None, None, None, 1 512         res3c_branch2b[0][0]
    __________________________________________________________________________________________________
    res3c_branch2b_relu (Activation (None, None, None, 1 0           bn3c_branch2b[0][0]
    __________________________________________________________________________________________________
    res3c_branch2c (Conv2D)         (None, None, None, 5 65536       res3c_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn3c_branch2c (BatchNormalizati (None, None, None, 5 2048        res3c_branch2c[0][0]
    __________________________________________________________________________________________________
    res3c (Add)                     (None, None, None, 5 0           bn3c_branch2c[0][0]
                                                                     res3b_relu[0][0]
    __________________________________________________________________________________________________
    res3c_relu (Activation)         (None, None, None, 5 0           res3c[0][0]
    __________________________________________________________________________________________________
    res3d_branch2a (Conv2D)         (None, None, None, 1 65536       res3c_relu[0][0]
    __________________________________________________________________________________________________
    bn3d_branch2a (BatchNormalizati (None, None, None, 1 512         res3d_branch2a[0][0]
    __________________________________________________________________________________________________
    res3d_branch2a_relu (Activation (None, None, None, 1 0           bn3d_branch2a[0][0]
    __________________________________________________________________________________________________
    padding3d_branch2b (ZeroPadding (None, None, None, 1 0           res3d_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res3d_branch2b (Conv2D)         (None, None, None, 1 147456      padding3d_branch2b[0][0]
    __________________________________________________________________________________________________
    bn3d_branch2b (BatchNormalizati (None, None, None, 1 512         res3d_branch2b[0][0]
    __________________________________________________________________________________________________
    res3d_branch2b_relu (Activation (None, None, None, 1 0           bn3d_branch2b[0][0]
    __________________________________________________________________________________________________
    res3d_branch2c (Conv2D)         (None, None, None, 5 65536       res3d_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn3d_branch2c (BatchNormalizati (None, None, None, 5 2048        res3d_branch2c[0][0]
    __________________________________________________________________________________________________
    res3d (Add)                     (None, None, None, 5 0           bn3d_branch2c[0][0]
                                                                     res3c_relu[0][0]
    __________________________________________________________________________________________________
    res3d_relu (Activation)         (None, None, None, 5 0           res3d[0][0]
    __________________________________________________________________________________________________
    res4a_branch2a (Conv2D)         (None, None, None, 2 131072      res3d_relu[0][0]
    __________________________________________________________________________________________________
    bn4a_branch2a (BatchNormalizati (None, None, None, 2 1024        res4a_branch2a[0][0]
    __________________________________________________________________________________________________
    res4a_branch2a_relu (Activation (None, None, None, 2 0           bn4a_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4a_branch2b (ZeroPadding (None, None, None, 2 0           res4a_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4a_branch2b (Conv2D)         (None, None, None, 2 589824      padding4a_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4a_branch2b (BatchNormalizati (None, None, None, 2 1024        res4a_branch2b[0][0]
    __________________________________________________________________________________________________
    res4a_branch2b_relu (Activation (None, None, None, 2 0           bn4a_branch2b[0][0]
    __________________________________________________________________________________________________
    res4a_branch2c (Conv2D)         (None, None, None, 1 262144      res4a_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    res4a_branch1 (Conv2D)          (None, None, None, 1 524288      res3d_relu[0][0]
    __________________________________________________________________________________________________
    bn4a_branch2c (BatchNormalizati (None, None, None, 1 4096        res4a_branch2c[0][0]
    __________________________________________________________________________________________________
    bn4a_branch1 (BatchNormalizatio (None, None, None, 1 4096        res4a_branch1[0][0]
    __________________________________________________________________________________________________
    res4a (Add)                     (None, None, None, 1 0           bn4a_branch2c[0][0]
                                                                     bn4a_branch1[0][0]
    __________________________________________________________________________________________________
    res4a_relu (Activation)         (None, None, None, 1 0           res4a[0][0]
    __________________________________________________________________________________________________
    res4b_branch2a (Conv2D)         (None, None, None, 2 262144      res4a_relu[0][0]
    __________________________________________________________________________________________________
    bn4b_branch2a (BatchNormalizati (None, None, None, 2 1024        res4b_branch2a[0][0]
    __________________________________________________________________________________________________
    res4b_branch2a_relu (Activation (None, None, None, 2 0           bn4b_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4b_branch2b (ZeroPadding (None, None, None, 2 0           res4b_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4b_branch2b (Conv2D)         (None, None, None, 2 589824      padding4b_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4b_branch2b (BatchNormalizati (None, None, None, 2 1024        res4b_branch2b[0][0]
    __________________________________________________________________________________________________
    res4b_branch2b_relu (Activation (None, None, None, 2 0           bn4b_branch2b[0][0]
    __________________________________________________________________________________________________
    res4b_branch2c (Conv2D)         (None, None, None, 1 262144      res4b_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn4b_branch2c (BatchNormalizati (None, None, None, 1 4096        res4b_branch2c[0][0]
    __________________________________________________________________________________________________
    res4b (Add)                     (None, None, None, 1 0           bn4b_branch2c[0][0]
                                                                     res4a_relu[0][0]
    __________________________________________________________________________________________________
    res4b_relu (Activation)         (None, None, None, 1 0           res4b[0][0]
    __________________________________________________________________________________________________
    res4c_branch2a (Conv2D)         (None, None, None, 2 262144      res4b_relu[0][0]
    __________________________________________________________________________________________________
    bn4c_branch2a (BatchNormalizati (None, None, None, 2 1024        res4c_branch2a[0][0]
    __________________________________________________________________________________________________
    res4c_branch2a_relu (Activation (None, None, None, 2 0           bn4c_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4c_branch2b (ZeroPadding (None, None, None, 2 0           res4c_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4c_branch2b (Conv2D)         (None, None, None, 2 589824      padding4c_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4c_branch2b (BatchNormalizati (None, None, None, 2 1024        res4c_branch2b[0][0]
    __________________________________________________________________________________________________
    res4c_branch2b_relu (Activation (None, None, None, 2 0           bn4c_branch2b[0][0]
    __________________________________________________________________________________________________
    res4c_branch2c (Conv2D)         (None, None, None, 1 262144      res4c_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn4c_branch2c (BatchNormalizati (None, None, None, 1 4096        res4c_branch2c[0][0]
    __________________________________________________________________________________________________
    res4c (Add)                     (None, None, None, 1 0           bn4c_branch2c[0][0]
                                                                     res4b_relu[0][0]
    __________________________________________________________________________________________________
    res4c_relu (Activation)         (None, None, None, 1 0           res4c[0][0]
    __________________________________________________________________________________________________
    res4d_branch2a (Conv2D)         (None, None, None, 2 262144      res4c_relu[0][0]
    __________________________________________________________________________________________________
    bn4d_branch2a (BatchNormalizati (None, None, None, 2 1024        res4d_branch2a[0][0]
    __________________________________________________________________________________________________
    res4d_branch2a_relu (Activation (None, None, None, 2 0           bn4d_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4d_branch2b (ZeroPadding (None, None, None, 2 0           res4d_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4d_branch2b (Conv2D)         (None, None, None, 2 589824      padding4d_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4d_branch2b (BatchNormalizati (None, None, None, 2 1024        res4d_branch2b[0][0]
    __________________________________________________________________________________________________
    res4d_branch2b_relu (Activation (None, None, None, 2 0           bn4d_branch2b[0][0]
    __________________________________________________________________________________________________
    res4d_branch2c (Conv2D)         (None, None, None, 1 262144      res4d_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn4d_branch2c (BatchNormalizati (None, None, None, 1 4096        res4d_branch2c[0][0]
    __________________________________________________________________________________________________
    res4d (Add)                     (None, None, None, 1 0           bn4d_branch2c[0][0]
                                                                     res4c_relu[0][0]
    __________________________________________________________________________________________________
    res4d_relu (Activation)         (None, None, None, 1 0           res4d[0][0]
    __________________________________________________________________________________________________
    res4e_branch2a (Conv2D)         (None, None, None, 2 262144      res4d_relu[0][0]
    __________________________________________________________________________________________________
    bn4e_branch2a (BatchNormalizati (None, None, None, 2 1024        res4e_branch2a[0][0]
    __________________________________________________________________________________________________
    res4e_branch2a_relu (Activation (None, None, None, 2 0           bn4e_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4e_branch2b (ZeroPadding (None, None, None, 2 0           res4e_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4e_branch2b (Conv2D)         (None, None, None, 2 589824      padding4e_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4e_branch2b (BatchNormalizati (None, None, None, 2 1024        res4e_branch2b[0][0]
    __________________________________________________________________________________________________
    res4e_branch2b_relu (Activation (None, None, None, 2 0           bn4e_branch2b[0][0]
    __________________________________________________________________________________________________
    res4e_branch2c (Conv2D)         (None, None, None, 1 262144      res4e_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn4e_branch2c (BatchNormalizati (None, None, None, 1 4096        res4e_branch2c[0][0]
    __________________________________________________________________________________________________
    res4e (Add)                     (None, None, None, 1 0           bn4e_branch2c[0][0]
                                                                     res4d_relu[0][0]
    __________________________________________________________________________________________________
    res4e_relu (Activation)         (None, None, None, 1 0           res4e[0][0]
    __________________________________________________________________________________________________
    res4f_branch2a (Conv2D)         (None, None, None, 2 262144      res4e_relu[0][0]
    __________________________________________________________________________________________________
    bn4f_branch2a (BatchNormalizati (None, None, None, 2 1024        res4f_branch2a[0][0]
    __________________________________________________________________________________________________
    res4f_branch2a_relu (Activation (None, None, None, 2 0           bn4f_branch2a[0][0]
    __________________________________________________________________________________________________
    padding4f_branch2b (ZeroPadding (None, None, None, 2 0           res4f_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res4f_branch2b (Conv2D)         (None, None, None, 2 589824      padding4f_branch2b[0][0]
    __________________________________________________________________________________________________
    bn4f_branch2b (BatchNormalizati (None, None, None, 2 1024        res4f_branch2b[0][0]
    __________________________________________________________________________________________________
    res4f_branch2b_relu (Activation (None, None, None, 2 0           bn4f_branch2b[0][0]
    __________________________________________________________________________________________________
    res4f_branch2c (Conv2D)         (None, None, None, 1 262144      res4f_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn4f_branch2c (BatchNormalizati (None, None, None, 1 4096        res4f_branch2c[0][0]
    __________________________________________________________________________________________________
    res4f (Add)                     (None, None, None, 1 0           bn4f_branch2c[0][0]
                                                                     res4e_relu[0][0]
    __________________________________________________________________________________________________
    res4f_relu (Activation)         (None, None, None, 1 0           res4f[0][0]
    __________________________________________________________________________________________________
    res5a_branch2a (Conv2D)         (None, None, None, 5 524288      res4f_relu[0][0]
    __________________________________________________________________________________________________
    bn5a_branch2a (BatchNormalizati (None, None, None, 5 2048        res5a_branch2a[0][0]
    __________________________________________________________________________________________________
    res5a_branch2a_relu (Activation (None, None, None, 5 0           bn5a_branch2a[0][0]
    __________________________________________________________________________________________________
    padding5a_branch2b (ZeroPadding (None, None, None, 5 0           res5a_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res5a_branch2b (Conv2D)         (None, None, None, 5 2359296     padding5a_branch2b[0][0]
    __________________________________________________________________________________________________
    bn5a_branch2b (BatchNormalizati (None, None, None, 5 2048        res5a_branch2b[0][0]
    __________________________________________________________________________________________________
    res5a_branch2b_relu (Activation (None, None, None, 5 0           bn5a_branch2b[0][0]
    __________________________________________________________________________________________________
    res5a_branch2c (Conv2D)         (None, None, None, 2 1048576     res5a_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    res5a_branch1 (Conv2D)          (None, None, None, 2 2097152     res4f_relu[0][0]
    __________________________________________________________________________________________________
    bn5a_branch2c (BatchNormalizati (None, None, None, 2 8192        res5a_branch2c[0][0]
    __________________________________________________________________________________________________
    bn5a_branch1 (BatchNormalizatio (None, None, None, 2 8192        res5a_branch1[0][0]
    __________________________________________________________________________________________________
    res5a (Add)                     (None, None, None, 2 0           bn5a_branch2c[0][0]
                                                                     bn5a_branch1[0][0]
    __________________________________________________________________________________________________
    res5a_relu (Activation)         (None, None, None, 2 0           res5a[0][0]
    __________________________________________________________________________________________________
    res5b_branch2a (Conv2D)         (None, None, None, 5 1048576     res5a_relu[0][0]
    __________________________________________________________________________________________________
    bn5b_branch2a (BatchNormalizati (None, None, None, 5 2048        res5b_branch2a[0][0]
    __________________________________________________________________________________________________
    res5b_branch2a_relu (Activation (None, None, None, 5 0           bn5b_branch2a[0][0]
    __________________________________________________________________________________________________
    padding5b_branch2b (ZeroPadding (None, None, None, 5 0           res5b_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res5b_branch2b (Conv2D)         (None, None, None, 5 2359296     padding5b_branch2b[0][0]
    __________________________________________________________________________________________________
    bn5b_branch2b (BatchNormalizati (None, None, None, 5 2048        res5b_branch2b[0][0]
    __________________________________________________________________________________________________
    res5b_branch2b_relu (Activation (None, None, None, 5 0           bn5b_branch2b[0][0]
    __________________________________________________________________________________________________
    res5b_branch2c (Conv2D)         (None, None, None, 2 1048576     res5b_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn5b_branch2c (BatchNormalizati (None, None, None, 2 8192        res5b_branch2c[0][0]
    __________________________________________________________________________________________________
    res5b (Add)                     (None, None, None, 2 0           bn5b_branch2c[0][0]
                                                                     res5a_relu[0][0]
    __________________________________________________________________________________________________
    res5b_relu (Activation)         (None, None, None, 2 0           res5b[0][0]
    __________________________________________________________________________________________________
    res5c_branch2a (Conv2D)         (None, None, None, 5 1048576     res5b_relu[0][0]
    __________________________________________________________________________________________________
    bn5c_branch2a (BatchNormalizati (None, None, None, 5 2048        res5c_branch2a[0][0]
    __________________________________________________________________________________________________
    res5c_branch2a_relu (Activation (None, None, None, 5 0           bn5c_branch2a[0][0]
    __________________________________________________________________________________________________
    padding5c_branch2b (ZeroPadding (None, None, None, 5 0           res5c_branch2a_relu[0][0]
    __________________________________________________________________________________________________
    res5c_branch2b (Conv2D)         (None, None, None, 5 2359296     padding5c_branch2b[0][0]
    __________________________________________________________________________________________________
    bn5c_branch2b (BatchNormalizati (None, None, None, 5 2048        res5c_branch2b[0][0]
    __________________________________________________________________________________________________
    res5c_branch2b_relu (Activation (None, None, None, 5 0           bn5c_branch2b[0][0]
    __________________________________________________________________________________________________
    res5c_branch2c (Conv2D)         (None, None, None, 2 1048576     res5c_branch2b_relu[0][0]
    __________________________________________________________________________________________________
    bn5c_branch2c (BatchNormalizati (None, None, None, 2 8192        res5c_branch2c[0][0]
    __________________________________________________________________________________________________
    res5c (Add)                     (None, None, None, 2 0           bn5c_branch2c[0][0]
                                                                     res5b_relu[0][0]
    __________________________________________________________________________________________________
    res5c_relu (Activation)         (None, None, None, 2 0           res5c[0][0]
    __________________________________________________________________________________________________
    C5_reduced (Conv2D)             (None, None, None, 2 524544      res5c_relu[0][0]
    __________________________________________________________________________________________________
    P5_upsampled (UpsampleLike)     (None, None, None, 2 0           C5_reduced[0][0]
                                                                     res4f_relu[0][0]
    __________________________________________________________________________________________________
    C4_reduced (Conv2D)             (None, None, None, 2 262400      res4f_relu[0][0]
    __________________________________________________________________________________________________
    P4_merged (Add)                 (None, None, None, 2 0           P5_upsampled[0][0]
                                                                     C4_reduced[0][0]
    __________________________________________________________________________________________________
    P4_upsampled (UpsampleLike)     (None, None, None, 2 0           P4_merged[0][0]
                                                                     res3d_relu[0][0]
    __________________________________________________________________________________________________
    C3_reduced (Conv2D)             (None, None, None, 2 131328      res3d_relu[0][0]
    __________________________________________________________________________________________________
    P6 (Conv2D)                     (None, None, None, 2 4718848     res5c_relu[0][0]
    __________________________________________________________________________________________________
    P3_merged (Add)                 (None, None, None, 2 0           P4_upsampled[0][0]
                                                                     C3_reduced[0][0]
    __________________________________________________________________________________________________
    C6_relu (Activation)            (None, None, None, 2 0           P6[0][0]
    __________________________________________________________________________________________________
    P3 (Conv2D)                     (None, None, None, 2 590080      P3_merged[0][0]
    __________________________________________________________________________________________________
    P4 (Conv2D)                     (None, None, None, 2 590080      P4_merged[0][0]
    __________________________________________________________________________________________________
    P5 (Conv2D)                     (None, None, None, 2 590080      C5_reduced[0][0]
    __________________________________________________________________________________________________
    P7 (Conv2D)                     (None, None, None, 2 590080      C6_relu[0][0]
    __________________________________________________________________________________________________
    regression_submodel (Model)     (None, None, 4)      2443300     P3[0][0]
                                                                     P4[0][0]
                                                                     P5[0][0]
                                                                     P6[0][0]
                                                                     P7[0][0]
    __________________________________________________________________________________________________
    classification_submodel (Model) (None, None, 1)      2381065     P3[0][0]
                                                                     P4[0][0]
                                                                     P5[0][0]
                                                                     P6[0][0]
                                                                     P7[0][0]
    __________________________________________________________________________________________________
    regression (Concatenate)        (None, None, 4)      0           regression_submodel[1][0]
                                                                     regression_submodel[2][0]
                                                                     regression_submodel[3][0]
                                                                     regression_submodel[4][0]
                                                                     regression_submodel[5][0]
    __________________________________________________________________________________________________
    classification (Concatenate)    (None, None, 1)      0           classification_submodel[1][0]
                                                                     classification_submodel[2][0]
                                                                     classification_submodel[3][0]
                                                                     classification_submodel[4][0]
                                                                     classification_submodel[5][0]
    ==================================================================================================
    Total params: 36,382,957
    Trainable params: 36,276,717
    Non-trainable params: 106,240
    ______________________________________________________________________________________________

          开始训练

    ____
    None
    Epoch 1/30
    2019-03-13 13:03:36.209789: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.07GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.266466: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.07GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.275037: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.25GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.288299: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.26GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.315962: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.651783: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.660588: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.680880: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.689715: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    2019-03-13 13:03:36.698370: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.26GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
    100/100 [==============================] - 20s 204ms/step - loss: 0.7675 - regression_loss: 0.4491 - classification_loss: 0.3185
    
    Epoch 00001: saving model to ./snapshots\resnet50_csv_01.h5
    Epoch 2/30
    100/100 [==============================] - 18s 177ms/step - loss: 1.1027 - regression_loss: 0.4177 - classification_loss: 0.6850
    
    Epoch 00002: saving model to ./snapshots\resnet50_csv_02.h5
    Epoch 3/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9961 - regression_loss: 0.3917 - classification_loss: 0.6044
    
    Epoch 00003: saving model to ./snapshots\resnet50_csv_03.h5
    
    Epoch 00003: ReduceLROnPlateau reducing learning rate to 9.999999747378752e-07.
    Epoch 4/30
    100/100 [==============================] - 16s 161ms/step - loss: 1.0841 - regression_loss: 0.3990 - classification_loss: 0.6850
    
    Epoch 00004: saving model to ./snapshots\resnet50_csv_04.h5
    Epoch 5/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9457 - regression_loss: 0.3413 - classification_loss: 0.6044
    
    Epoch 00005: saving model to ./snapshots\resnet50_csv_05.h5
    
    Epoch 00005: ReduceLROnPlateau reducing learning rate to 9.999999974752428e-08.
    Epoch 6/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0741 - regression_loss: 0.3891 - classification_loss: 0.6850
    
    Epoch 00006: saving model to ./snapshots\resnet50_csv_06.h5
    Epoch 7/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9355 - regression_loss: 0.3311 - classification_loss: 0.6044
    
    Epoch 00007: saving model to ./snapshots\resnet50_csv_07.h5
    
    Epoch 00007: ReduceLROnPlateau reducing learning rate to 1.0000000116860975e-08.
    Epoch 8/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0721 - regression_loss: 0.3871 - classification_loss: 0.6850
    
    Epoch 00008: saving model to ./snapshots\resnet50_csv_08.h5
    Epoch 9/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9348 - regression_loss: 0.3304 - classification_loss: 0.6044
    
    Epoch 00009: saving model to ./snapshots\resnet50_csv_09.h5
    
    Epoch 00009: ReduceLROnPlateau reducing learning rate to 9.999999939225292e-10.
    Epoch 10/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0737 - regression_loss: 0.3887 - classification_loss: 0.6850
    
    Epoch 00010: saving model to ./snapshots\resnet50_csv_10.h5
    Epoch 11/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9367 - regression_loss: 0.3322 - classification_loss: 0.6044
    
    Epoch 00011: saving model to ./snapshots\resnet50_csv_11.h5
    
    Epoch 00011: ReduceLROnPlateau reducing learning rate to 9.999999717180686e-11.
    Epoch 12/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0711 - regression_loss: 0.3860 - classification_loss: 0.6850
    
    Epoch 00012: saving model to ./snapshots\resnet50_csv_12.h5
    Epoch 13/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9347 - regression_loss: 0.3303 - classification_loss: 0.6044
    
    Epoch 00013: saving model to ./snapshots\resnet50_csv_13.h5
    
    Epoch 00013: ReduceLROnPlateau reducing learning rate to 9.99999943962493e-12.
    Epoch 14/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0722 - regression_loss: 0.3872 - classification_loss: 0.6850
    
    Epoch 00014: saving model to ./snapshots\resnet50_csv_14.h5
    Epoch 15/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9349 - regression_loss: 0.3305 - classification_loss: 0.6044
    
    Epoch 00015: saving model to ./snapshots\resnet50_csv_15.h5
    
    Epoch 00015: ReduceLROnPlateau reducing learning rate to 9.999999092680235e-13.
    Epoch 16/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0713 - regression_loss: 0.3863 - classification_loss: 0.6850
    
    Epoch 00016: saving model to ./snapshots\resnet50_csv_16.h5
    Epoch 17/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9337 - regression_loss: 0.3293 - classification_loss: 0.6044
    
    Epoch 00017: saving model to ./snapshots\resnet50_csv_17.h5
    
    Epoch 00017: ReduceLROnPlateau reducing learning rate to 9.9999988758398e-14.
    Epoch 18/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0704 - regression_loss: 0.3853 - classification_loss: 0.6850
    
    Epoch 00018: saving model to ./snapshots\resnet50_csv_18.h5
    Epoch 19/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9337 - regression_loss: 0.3293 - classification_loss: 0.6044
    
    Epoch 00019: saving model to ./snapshots\resnet50_csv_19.h5
    
    Epoch 00019: ReduceLROnPlateau reducing learning rate to 9.999999146890344e-15.
    Epoch 20/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0695 - regression_loss: 0.3845 - classification_loss: 0.6850
    
    Epoch 00020: saving model to ./snapshots\resnet50_csv_20.h5
    Epoch 21/30
    100/100 [==============================] - 16s 160ms/step - loss: 0.9350 - regression_loss: 0.3306 - classification_loss: 0.6044
    
    Epoch 00021: saving model to ./snapshots\resnet50_csv_21.h5
    
    Epoch 00021: ReduceLROnPlateau reducing learning rate to 9.999998977483753e-16.
    Epoch 22/30
    100/100 [==============================] - 16s 160ms/step - loss: 1.0708 - regression_loss: 0.3858 - classification_loss: 0.6850
    
    Epoch 00022: saving model to ./snapshots\resnet50_csv_22.h5
    Epoch 23/30
    100/100 [==============================] - 16s 165ms/step - loss: 0.9333 - regression_loss: 0.3288 - classification_loss: 0.6044
    
    Epoch 00023: saving model to ./snapshots\resnet50_csv_23.h5
    
    Epoch 00023: ReduceLROnPlateau reducing learning rate to 9.999998977483754e-17.
    Epoch 24/30
    100/100 [==============================] - 17s 167ms/step - loss: 1.0715 - regression_loss: 0.3865 - classification_loss: 0.6850
    
    Epoch 00024: saving model to ./snapshots\resnet50_csv_24.h5
    Epoch 25/30
    100/100 [==============================] - 17s 165ms/step - loss: 0.9352 - regression_loss: 0.3308 - classification_loss: 0.6044
    
    Epoch 00025: saving model to ./snapshots\resnet50_csv_25.h5
    
    Epoch 00025: ReduceLROnPlateau reducing learning rate to 9.999998845134856e-18.
    Epoch 26/30
    100/100 [==============================] - 17s 167ms/step - loss: 1.0729 - regression_loss: 0.3878 - classification_loss: 0.6850
    
    Epoch 00026: saving model to ./snapshots\resnet50_csv_26.h5
    Epoch 27/30
    100/100 [==============================] - 17s 167ms/step - loss: 0.9355 - regression_loss: 0.3311 - classification_loss: 0.6044
    
    Epoch 00027: saving model to ./snapshots\resnet50_csv_27.h5
    
    Epoch 00027: ReduceLROnPlateau reducing learning rate to 9.999999010570977e-19.
    Epoch 28/30
    100/100 [==============================] - 17s 167ms/step - loss: 1.0724 - regression_loss: 0.3874 - classification_loss: 0.6850
    
    Epoch 00028: saving model to ./snapshots\resnet50_csv_28.h5
    Epoch 29/30
    100/100 [==============================] - 17s 166ms/step - loss: 0.9339 - regression_loss: 0.3294 - classification_loss: 0.6044
    
    Epoch 00029: saving model to ./snapshots\resnet50_csv_29.h5
    
    Epoch 00029: ReduceLROnPlateau reducing learning rate to 9.999999424161285e-20.
    Epoch 30/30
    100/100 [==============================] - 17s 166ms/step - loss: 1.0727 - regression_loss: 0.3877 - classification_loss: 0.6850
    
    Epoch 00030: saving model to ./snapshots\resnet50_csv_30.h5

     

    4.目标检测

    • 将模型进行转换后才能进行目标检测,在命令行执行convert_model.py
      python D:/PyCharm/PycharmProjects/tf-gpu-env/project/keras-retinanet-master/keras_retinanet/bin/convert_model.py D:\PyCharm\PycharmProjects\tf-gpu-env\project\keras-retinanet-master\keras_retinanet\bin\snapshots\resnet50_csv_34.h5 D:\PyCharm\PycharmProjects\tf-gpu-env\project\keras-retinanet-master\cov_resnet50_csv_34.h5

      如果没有转换的话,会报 错误: boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0)) 这一句出错了,错误是:ValueError: not enough values to unpack (expected 3, got 2) 

       

    • 将转换后的模型拷贝到snapshots  keras_retinanet 目标检测——自定义图片数据集的模型训练步骤_第3张图片  目录下
    • 在example里新建一个目标检测的.py文件,可以将修改以下几处

      改成转换后的模型名称

    ​​​​​​​改成你自己模型的类别对应关系                     

    待检测的图片地址               

    修改阈值


    特别感谢:

    https://github.com/fizyr/keras-retinanet

    https://github.com/tzutalin/labelImg

    https://blog.csdn.net/gaohuazhao/article/details/60871886

    你可能感兴趣的:(RetinaNet,目标检测,Python,深度学习)