Exemplo n.º 1
0
        public MobileNetV2(float multiplier = 1, int classes = 1000, string prefix = null, ParameterDict @params = null)
            : base(prefix, @params)
        {
            Features = new HybridSequential("");
            MobileNet.AddConv(Features, Convert.ToInt32(32 * multiplier), 3, pad: 1, stride: 2);
            for (var i = 0; i < in_channels_group.Length; i++)
            {
                var in_c = Convert.ToInt32(multiplier * in_channels_group[i]);
                var c    = Convert.ToInt32(multiplier * channels_group[i]);
                var s    = strides[i];
                var t    = ts[i];

                Features.Add(new LinearBottleneck(in_c, c, t, s));
            }

            var last_channel = multiplier > 1 ? Convert.ToInt32(1280 * multiplier) : 1280;

            MobileNet.AddConv(Features, last_channel, relu6: true);

            Features.Add(new GlobalAvgPool2D());

            Output = new HybridSequential("output_");
            Output.Add(new Conv2D(classes, (1, 1), use_bias: false, prefix: "pred_"));
            Output.Add(new Flatten());
        }
Exemplo n.º 2
0
 public LinearBottleneck(int in_channels, int channels, int t, int stride, string prefix = null,
                         ParameterDict @params = null) : base(prefix, @params)
 {
     use_shortcut = stride == 1 && in_channels == channels;
     output       = new HybridSequential();
     MobileNet.AddConv(output, in_channels * t, relu6: true);
     MobileNet.AddConv(output, in_channels * t, 3, stride, 1, in_channels, relu6: true);
     MobileNet.AddConv(output, channels, active: false, relu6: true);
 }
Exemplo n.º 3
0
        public static MobileNet GetMobileNetV2(float multiplier, bool pretrained = false, Context ctx = null,
                                               string root = "", int classes = 1000, string prefix = null, ParameterDict @params = null)
        {
            var net = new MobileNet(multiplier, classes, prefix, @params);

            if (pretrained)
            {
                net.LoadParameters(ModelStore.GetModelFile($"mobilenetv2_{multiplier}"), ctx);
            }

            return(net);
        }
Exemplo n.º 4
0
        public static MobileNet GetMobileNet(float multiplier, bool pretrained = false, Context ctx = null,
                                             string root = "", int classes = 1000, string prefix = "", ParameterDict @params = null)
        {
            var net = new MobileNet(multiplier, classes, prefix, @params);

            var version_suffix = string.Format("{0:0.00}", multiplier);

            if (version_suffix == "1.00" || version_suffix == "0.50")
            {
                version_suffix = version_suffix.Substring(0, 3);
            }

            if (pretrained)
            {
                net.LoadParameters(ModelStore.GetModelFile($"mobilenet{version_suffix}"), ctx);
            }

            return(net);
        }