『计算机视觉』Mask-RCNN_训练网络其三:model准备

一、模型初始化

1、创建模型并载入预训练参数

准备了数据集后,我们开始构建model,training网络结构上一节已经介绍完了,现在我们看一看训练时如何调用training结构的网络。

如上所示,我们首先建立图结构(详见上节『计算机视觉』Mask-RCNN_训练网络其二:train网络结构),然后选择初始化参数方案

例子(train_shape.ipynb)中使用的是COCO预训练模型,如果想要"Finds the last checkpoint file of the last trained model in the
model directory",那么选择"last"选项。

载入参数方法如下,注意几个之前接触不多的操作,

  1. 载入h5文件使用模块为h5py
  2. keras model有属性.layers以list形式返回全部的层对象
  3. keras.engine下的saving模块load_weights_from_hdf5_group_by_name按照名字对应,而load_weights_from_hdf5_group按照记录顺序对应
    def load_weights(self, filepath, by_name=False, exclude=None):
        """Modified version of the corresponding Keras function with
        the addition of multi-GPU support and the ability to exclude
        some layers from loading.
        exclude: list of layer names to exclude
        """
        import h5py
        # Conditional import to support versions of Keras before 2.2
        # TODO: remove in about 6 months (end of 2018)
        try:
            from keras.engine import saving
        except ImportError:
            # Keras before 2.2 used the ‘topology‘ namespace.
            from keras.engine import topology as saving

        if exclude:
            by_name = True

        if h5py is None:
            raise ImportError(‘`load_weights` requires h5py.‘)
        f = h5py.File(filepath, mode=‘r‘)
        if ‘layer_names‘ not in f.attrs and ‘model_weights‘ in f:
            f = f[‘model_weights‘]

        # In multi-GPU training, we wrap the model. Get layers
        # of the inner model because they have the weights.
        keras_model = self.keras_model
        layers = keras_model.inner_model.layers if hasattr(keras_model, "inner_model")            else keras_model.layers

        # Exclude some layers
        if exclude:
            layers = filter(lambda l: l.name not in exclude, layers)

        if by_name:
            saving.load_weights_from_hdf5_group_by_name(f, layers)
        else:
            saving.load_weights_from_hdf5_group(f, layers)
        if hasattr(f, ‘close‘):
            f.close()

        # Update the log directory
        self.set_log_dir(filepath)

2、从h5文件一窥load模式

原文地址:https://www.cnblogs.com/hellcat/p/9987442.html

时间: 2024-08-29 02:35:02

『计算机视觉』Mask-RCNN_训练网络其三:model准备的相关文章

『计算机视觉』Mask-RCNN_关键点检测分支(待续)

Github地址:Mask_RCNN 『计算机视觉』Mask-RCNN_论文学习 『计算机视觉』Mask-RCNN_项目文档翻译 『计算机视觉』Mask-RCNN_推断网络其一:总览 『计算机视觉』Mask-RCNN_推断网络其二:基于ReNet101的FPN共享网络 『计算机视觉』Mask-RCNN_推断网络其三:RPN锚框处理和Proposal生成 『计算机视觉』Mask-RCNN_推断网络其四:FPN和ROIAlign的耦合 『计算机视觉』Mask-RCNN_推断网络其五:目标检测结果精炼

『计算机视觉』mini深度学习框架实现

一.项目简介 手动实现mini深度学习框架,主要精力不放在运算优化上,仅体会原理. 地址见:miniDeepFrame 相关博客 『TensorFlow』卷积层.池化层详解 『科学计算』全连接层.均方误差.激活函数实现 文件介绍 Layer.py 层 class,已实现:全连接层,卷积层,平均池化层 Loss.py 损失函数 class,已实现:均方误差损失函数 Activate.py 激活函数 class,已实现:sigmoid.tanh.relu test.py 训练测试代码 主流框架对于卷

『计算机视觉』SSD源码学习_基于TensorFlow(待续)

原项目地址:SSD-Tensorflow 根据README的介绍,该项目收到了tf-slim项目中包含了多种经典网络结构(分类用)的启发,使用了模块化的编程思想,可以替换检查网络的结构,其模块组织如下: datasets:              数据及接口,interface to popular datasets (Pascal VOC, COCO, ...) and scripts to convert the former to TF-Records; networks:       

『计算机视觉』物体检测之RefineDet

Two Stage 的精度优势 二阶段的分类:二步法的第一步在分类时,正负样本是极不平衡的,导致分类器训练比较困难,这也是一步法效果不如二步法的原因之一,也是focal loss的motivation.而第二步在分类时,由于第一步滤掉了绝大部分的负样本,送给第二步分类的proposal中,正负样本比例已经比较平衡了,所以第二步分类中不存在正负样本极度不平衡的问题.即二步法可以在很大程度上,缓和正负样本极度不平衡的分类问题二阶段的回归:二步法中,第一步会先对初始候选框进行校正,然后把校正过的候选框

『计算机视觉』RCNN学习_其二:Mask-RCNN

参考资料 Mask R-CNN Mask R-CNN详解 开源代码: Tensorflow版本代码链接: Keras and TensorFlow版本代码链接: MxNet版本代码链接 一.Mask-RCNN Mask R-CNN是一个实例分割(Instance segmentation)算法,通过增加不同的分支,可以完成目标分类.目标检测.语义分割.实例分割.人体姿势识别等多种任务,灵活而强大. Mask R-CNN进行目标检测与实例分割 Mask R-CNN进行人体姿态识别 其抽象架构如下:

『cs231n』计算机视觉基础

线性分类器损失函数明细: 『cs231n』线性分类器损失函数 最优化Optimiz部分代码: 1.差劲的方案,随机搜索 bestloss = float('inf') # 无穷大 for num in range(1000): W = np.random.randn(10, 3073) * 0.0001 loss = L(X_train, Y_train, W) if loss < bestloss: bestloss = loss bestW = W scores = bsetW.dot(Xt

『TensorFlow』分布式训练_其二_多GPU并行demo分析(待续)

建议比对『MXNet』第七弹_多GPU并行程序设计 models/tutorials/image/cifar10/cifer10_multi_gpu-train.py # Copyright 2015 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file exc

『TensorFlow』函数查询列表_神经网络相关

神经网络(Neural Network) 激活函数(Activation Functions) 操作 描述 tf.nn.relu(features, name=None) 整流函数:max(features, 0) tf.nn.relu6(features, name=None) 以6为阈值的整流函数:min(max(features, 0), 6) tf.nn.elu(features, name=None) elu函数,exp(features) - 1 if < 0,否则featuresE

『TensorFlow』迁移学习_他山之石,可以攻玉

目的: 使用google已经训练好的模型,将最后的全连接层修改为我们自己的全连接层,将原有的1000分类分类器修改为我们自己的5分类分类器,利用原有模型的特征提取能力实现我们自己数据对应模型的快速训练.实际中对于一个陌生的数据集,原有模型经过不高的迭代次数即可获得很好的准确率. 实战: 实机文件夹如下,两个压缩文件可以忽略: 花朵图片数据下载: 1 curl -O http://download.tensorflow.org/example_images/flower_photos.tgz 已经