コード例 #1
0
        private LayerParameter addBody(bool bDeploy, string strDataName, bool bNamedParams = false, string strLayerPostfix = "", Phase phaseExclude = Phase.NONE)
        {
            LayerParameter lastLayer;

            switch (m_model)
            {
            case MODEL.RESNET26:
                lastLayer = addResNetOctConvBody(strDataName, new int[] { 2, 2, 2, 2 });
                break;

            default:
                throw new Exception("The model type '" + m_model.ToString() + "' is not supported.");
            }

            for (int i = 0; i < m_rgIpLayers.Count; i++)
            {
                LayerParameter ip      = new LayerParameter(LayerParameter.LayerType.INNERPRODUCT);
                string         strName = "fc" + (i + 1).ToString();
                ip.name = strName + strLayerPostfix;
                ip.inner_product_param.axis         = 1;
                ip.inner_product_param.num_output   = (uint)m_rgIpLayers[i].Item1;
                ip.inner_product_param.enable_noise = m_rgIpLayers[i].Item2;
                ip.top.Add(ip.name);
                ip.parameters.Add(new ParamSpec(1, 1, (bNamedParams) ? strName + "_w" : null));
                ip.parameters.Add(new ParamSpec(1, 2, (bNamedParams) ? strName + "_b" : null));
                addExclusion(ip, phaseExclude);
                lastLayer = connectAndAddLayer(lastLayer, ip);
            }

            return(lastLayer);
        }
コード例 #2
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="strBaseDirectory">Specifies the base directory that contains the data and models.</param>
        /// <param name="strDataset">Specifies the dataset that the model will run on.</param>
        /// <param name="nChannels">Specifies the number of channels in the data set (e.g. color = 3, b/w = 1).</param>
        /// <param name="bSiamese">Specifies whether or not to create a Siamese network."</param>
        /// <param name="rgIpLayers">Specifies a list of inner product layers added to the end of the network where each entry specifies the number of output and whether or not Noise is enabled for the layer.</param>
        /// <param name="bUsePool5">Specifies whether or not to use the Pool layer as the last layer.</param>
        /// <param name="bUseDilationConv5">Specifies whether or not to use dilation on block 5 layers.</param>
        /// <param name="model">Specifies the type of ResNet model to create.</param>
        /// <param name="nBatchSize">Optionally, specifies the batch size (default = 32).</param>
        /// <param name="nAccumBatchSize">Optionally, specifies the accumulation batch size (default = 32).</param>
        /// <param name="rgGpuId">Optionally, specifies a set of GPU ID's to use (when null, GPU=0 is used).</param>
        /// <param name="net">Specifies the 'base' net parameter that is to be altered.</param>
        public ResNetModelBuilder(string strBaseDirectory, string strDataset, int nChannels, bool bSiamese, List <Tuple <int, bool> > rgIpLayers, bool bUsePool5, bool bUseDilationConv5, MODEL model, int nBatchSize = 32, int nAccumBatchSize = 32, List <int> rgGpuId = null, NetParameter net = null)
            : base(strBaseDirectory, net)
        {
            if (rgGpuId == null)
            {
                m_rgGpuID.Add(0);
            }
            else
            {
                m_rgGpuID = new List <int>(rgGpuId);
            }

            m_nChannels       = nChannels;
            m_bSiamese        = bSiamese;
            m_rgIpLayers      = rgIpLayers;
            m_model           = model;
            m_strModel        = model.ToString();
            m_nBatchSize      = nBatchSize;
            m_nAccumBatchSize = nAccumBatchSize;
            m_nIterSize       = m_nAccumBatchSize / m_nBatchSize;

            m_nBatchSizePerDevice = (m_rgGpuID.Count == 1) ? m_nBatchSize : m_nBatchSize / m_rgGpuID.Count;
            m_nIterSize           = (int)Math.Ceiling((float)m_nAccumBatchSize / (m_nBatchSizePerDevice * m_rgGpuID.Count));
            m_nGpuID   = m_rgGpuID[0];
            m_dfBaseLr = 0.001;

            m_bUseDilationConv5 = bUseDilationConv5;
            m_bUsePool5         = bUsePool5;
            m_strDataset        = strDataset;

            //-------------------------------------------------------
            // Create the transformer for Training.
            //-------------------------------------------------------
            m_transformTrain             = new TransformationParameter();
            m_transformTrain.mirror      = true;
            m_transformTrain.color_order = TransformationParameter.COLOR_ORDER.BGR; // to support caffe models.
            m_transformTrain.mean_value  = new List <double>();
            m_transformTrain.mean_value.Add(104);
            m_transformTrain.mean_value.Add(117);
            m_transformTrain.mean_value.Add(123);

            //-------------------------------------------------------
            // Create the transformer for Testing.
            //-------------------------------------------------------
            m_transformTest             = new TransformationParameter();
            m_transformTest.color_order = TransformationParameter.COLOR_ORDER.BGR; // to support caffe models.
            m_transformTest.mean_value  = new List <double>();
            m_transformTest.mean_value.Add(104);
            m_transformTest.mean_value.Add(117);
            m_transformTest.mean_value.Add(123);
        }
コード例 #3
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="strBaseDirectory">Specifies the base directory that contains the data and models.</param>
        /// <param name="strDataset">Specifies the dataset that the model will run on.</param>
        /// <param name="rgIpLayers">Specifies a list of inner product layers added to the end of the network where each entry specifies the number of output and whether or not Noise is enabled for the layer.</param>
        /// <param name="model">Specifies the type of ResNet model to create.</param>
        /// <param name="nBatchSize">Optionally, specifies the batch size (default = 32).</param>
        /// <param name="rgGpuId">Optionally, specifies a set of GPU ID's to use (when null, GPU=0 is used).</param>
        /// <param name="net">Specifies the 'base' net parameter that is to be altered.</param>
        public ResNetOctConvModelBuilder(string strBaseDirectory, string strDataset, List <Tuple <int, bool> > rgIpLayers, MODEL model, int nBatchSize = 32, List <int> rgGpuId = null, NetParameter net = null)
            : base(strBaseDirectory, net)
        {
            if (rgGpuId == null)
            {
                m_rgGpuID.Add(0);
            }
            else
            {
                m_rgGpuID = new List <int>(rgGpuId);
            }

            m_rgIpLayers = rgIpLayers;
            m_model      = model;
            m_strModel   = model.ToString();
            m_nBatchSize = nBatchSize;

            m_nIterSize = 1;
            m_nGpuID    = m_rgGpuID[0];
            m_dfBaseLr  = 0.001;

            m_strDataset = strDataset;

            //-------------------------------------------------------
            // Create the transformer for Training.
            //-------------------------------------------------------
            m_transformTrain             = new TransformationParameter();
            m_transformTrain.mirror      = true;
            m_transformTrain.color_order = TransformationParameter.COLOR_ORDER.BGR; // to support caffe models.
            m_transformTrain.mean_value  = new List <double>();
            m_transformTrain.mean_value.Add(104);
            m_transformTrain.mean_value.Add(117);
            m_transformTrain.mean_value.Add(123);

            //-------------------------------------------------------
            // Create the transformer for Testing.
            //-------------------------------------------------------
            m_transformTest             = new TransformationParameter();
            m_transformTest.color_order = TransformationParameter.COLOR_ORDER.BGR; // to support caffe models.
            m_transformTest.mean_value  = new List <double>();
            m_transformTest.mean_value.Add(104);
            m_transformTest.mean_value.Add(117);
            m_transformTest.mean_value.Add(123);
        }