Exemple #1
0
        private static Layer parse_route(KeyValuePair[] options, SizeParams parameters, Network net)
        {
            string l = OptionList.option_find(options, "layers");

            if (string.IsNullOrEmpty(l))
            {
                Utils.Error("Route Layer must specify input layers");
            }
            var lines = l.Split(',');
            int n     = lines.Length - 1;


            int[] layers = new int[n];
            int[] sizes  = new int[n];

            for (var i = 0; i < lines.Length; ++i)
            {
                int index = int.Parse(lines[i]);
                if (index < 0)
                {
                    index = parameters.Index + index;
                }
                layers[i] = index;
                sizes[i]  = net.Layers[index].Outputs;
            }

            int batch = parameters.Batch;

            Layer layer = Layer.make_route_layer(batch, n, layers, sizes);

            var first = net.Layers[layers[0]];

            layer.OutW = first.OutW;
            layer.OutH = first.OutH;
            layer.OutC = first.OutC;
            for (var i = 1; i < n; ++i)
            {
                int index = layers[i];
                var next  = net.Layers[index];
                if (next.OutW == first.OutW && next.OutH == first.OutH)
                {
                    layer.OutC += next.OutC;
                }
                else
                {
                    layer.OutH = layer.OutW = layer.OutC = 0;
                }
            }

            return(layer);
        }
Exemple #2
0
        private static Layer parse_shortcut(KeyValuePair[] options, SizeParams parameters, Network net)
        {
            string l     = OptionList.option_find(options, "from");
            int    index = int.Parse(l);

            if (index < 0)
            {
                index = parameters.Index + index;
            }

            int   batch = parameters.Batch;
            Layer from  = net.Layers[index];

            Layer s = Layer.make_shortcut_layer(batch, index, parameters.W, parameters.H, parameters.C, from.OutW, from.OutH, from.OutC);

            string     activationS = OptionList.option_find_str(options, "activation", "linear");
            Activation activation  = ActivationsHelper.Get_activation(activationS);

            s.Activation = activation;
            return(s);
        }
Exemple #3
0
        private static void parse_net_options(KeyValuePair[] options, Network net)
        {
            net.Batch        = OptionList.option_find_int(options, "batch", 1);
            net.LearningRate = OptionList.option_find_float(options, "learning_rate", .001f);
            net.Momentum     = OptionList.option_find_float(options, "momentum", .9f);
            net.Decay        = OptionList.option_find_float(options, "decay", .0001f);
            int subdivs = OptionList.option_find_int(options, "subdivisions", 1);

            net.TimeSteps    = OptionList.option_find_int_quiet(options, "time_steps", 1);
            net.Batch       /= subdivs;
            net.Batch       *= net.TimeSteps;
            net.Subdivisions = subdivs;

            net.Adam = OptionList.option_find_int_quiet(options, "adam", 0) != 0;
            if (net.Adam)
            {
                net.B1  = OptionList.option_find_float(options, "B1", .9f);
                net.B2  = OptionList.option_find_float(options, "B2", .999f);
                net.Eps = OptionList.option_find_float(options, "eps", .000001f);
            }

            net.H       = OptionList.option_find_int_quiet(options, "height", 0);
            net.W       = OptionList.option_find_int_quiet(options, "width", 0);
            net.C       = OptionList.option_find_int_quiet(options, "channels", 0);
            net.Inputs  = OptionList.option_find_int_quiet(options, "inputs", net.H * net.W * net.C);
            net.MaxCrop = OptionList.option_find_int_quiet(options, "max_crop", net.W * 2);
            net.MinCrop = OptionList.option_find_int_quiet(options, "min_crop", net.W);

            net.Angle      = OptionList.option_find_float_quiet(options, "angle", 0);
            net.Aspect     = OptionList.option_find_float_quiet(options, "aspect", 1);
            net.Saturation = OptionList.option_find_float_quiet(options, "saturation", 1);
            net.Exposure   = OptionList.option_find_float_quiet(options, "exposure", 1);
            net.Hue        = OptionList.option_find_float_quiet(options, "hue", 0);

            if (net.Inputs == 0 && !(net.H != 0 && net.W != 0 && net.C != 0))
            {
                Utils.Error("No input parameters supplied");
            }

            string policyS = OptionList.option_find_str(options, "policy", "constant");

            net.Policy = get_policy(policyS);
            net.BurnIn = OptionList.option_find_int_quiet(options, "burn_in", 0);
            if (net.Policy == LearningRatePolicy.Step)
            {
                net.Step  = OptionList.option_find_int(options, "step", 1);
                net.Scale = OptionList.option_find_float(options, "scale", 1);
            }
            else if (net.Policy == LearningRatePolicy.Steps)
            {
                string l = OptionList.option_find(options, "steps");
                string p = OptionList.option_find(options, "scales");
                if (string.IsNullOrEmpty(l) || string.IsNullOrEmpty(p))
                {
                    Utils.Error("STEPS policy must have steps and scales in cfg file");
                }

                var     lines  = l.Split(',');
                int[]   steps  = new int[lines.Length];
                float[] scales = new float[lines.Length];
                for (var i = 0; i < lines.Length; ++i)
                {
                    steps[i]  = int.Parse(lines[i]);
                    scales[i] = float.Parse(lines[i]);
                }

                net.Scales   = scales;
                net.Steps    = steps;
                net.NumSteps = lines.Length;
            }
            else if (net.Policy == LearningRatePolicy.Exp)
            {
                net.Gamma = OptionList.option_find_float(options, "gamma", 1);
            }
            else if (net.Policy == LearningRatePolicy.Sig)
            {
                net.Gamma = OptionList.option_find_float(options, "gamma", 1);
                net.Step  = OptionList.option_find_int(options, "step", 1);
            }
            else if (net.Policy == LearningRatePolicy.Poly || net.Policy == LearningRatePolicy.Random)
            {
                net.Power = OptionList.option_find_float(options, "power", 1);
            }
            net.MaxBatches = OptionList.option_find_int(options, "max_batches", 0);
        }