Esempio n. 1
0
        public BottleneckV2(int channels, int stride, bool downsample = false, int in_channels = 0,
                            string prefix = "", ParameterDict @params = null) : base(prefix, @params)
        {
            var channel_one_fourth = Convert.ToInt32(channels / 4);

            bn1   = new BatchNorm();
            conv1 = new Conv2D(channel_one_fourth, (1, 1), (1, 1), use_bias: false);
            bn2   = new BatchNorm();
            conv2 = ResNet.Conv3x3(channel_one_fourth, stride, channel_one_fourth);
            bn3   = new BatchNorm();
            conv3 = new Conv2D(channels, (1, 1), (1, 1), use_bias: false);
            RegisterChild(bn1, "bn1");
            RegisterChild(conv1, "conv1");
            RegisterChild(bn2, "bn2");
            RegisterChild(conv2, "conv2");
            RegisterChild(bn3, "bn3");
            RegisterChild(conv3, "conv3");

            if (downsample)
            {
                ds = new Conv2D(channels, (1, 1), (stride, stride), use_bias: false, in_channels: in_channels);
                RegisterChild(ds, "downsample");
            }
            else
            {
                ds = null;
            }
        }
Esempio n. 2
0
        public ResNetV1(string block, int[] layers, int[] channels, int classes = 1000, bool thumbnail = false,
                        string prefix = "", ParameterDict @params = null) : base(prefix, @params)
        {
            if (layers.Length != channels.Length - 1)
            {
                throw new Exception("layers.length should be equal to channels.length - 1");
            }

            Features = new HybridSequential();
            if (thumbnail)
            {
                Features.Add(ResNet.Conv3x3(channels[0], 1, 0));
            }
            else
            {
                Features.Add(new Conv2D(channels[0], (7, 7), (2, 2), (3, 3), use_bias: false));
                Features.Add(new BatchNorm());
                Features.Add(new Activation(ActivationType.Relu));
                Features.Add(new MaxPool2D((3, 3), (2, 2), (1, 1)));
            }

            for (var i = 0; i < layers.Length; i++)
            {
                var stride    = i == 0 ? 1 : 2;
                var num_layer = layers[i];
                Features.Add(MakeLayer(block, num_layer, channels[i + 1], stride, i + 1, channels[i]));
            }

            Features.Add(new GlobalAvgPool2D());

            Output = new Dense(classes, in_units: channels.Last());

            RegisterChild(Features, "features");
            RegisterChild(Output, "output");
        }
Esempio n. 3
0
        private void Btn_runML_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.mMainWindow.listBox.Items.Clear();
            switch (MLCore.MLModelSelected)
            {
            case MLModel.ResNet:
                ResNet.EvaluationSingleImage(GV.imgOriginal);

                for (int i = 0; i < ResNet.resultList.Count; i++)
                {
                    MainWindow.mMainWindow.listBox.Items.Add(string.Format("{0}: {1}", MLCore.MLSelectedLabels[i], ResNet.resultList[i]));
                }
                BindMngr.GMessage.value = string.Format("This must be a {0}!", ResNet.OutputString, ResNet.OutputProbablility);
                break;

            case MLModel.FastRCNN:
                FastRCNN.EvaluateObjectDetectionModel();
                break;

            case MLModel.Yolo:
                GV.imgProcessed = new Image <Bgr, byte>(mYolo.Detect(GV.imgOriginal.ToBitmap()));
                MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgProcessed);
                break;
            }
        }
Esempio n. 4
0
        public BottleneckV1(int channels, int stride, bool downsample = false, int in_channels = 0,
                            string prefix = "", ParameterDict @params = null) : base(prefix, @params)
        {
            var channel_one_fourth = Convert.ToInt32(channels / 4);

            body = new HybridSequential("");
            body.Add(new Conv2D(channel_one_fourth, (1, 1), (stride, stride)));
            body.Add(new BatchNorm());
            body.Add(new Activation(ActivationType.Relu));
            body.Add(ResNet.Conv3x3(channel_one_fourth, 1, channel_one_fourth));
            body.Add(new BatchNorm());
            body.Add(new Activation(ActivationType.Relu));
            body.Add(new Conv2D(channels, (1, 1), (1, 1)));
            body.Add(new BatchNorm());

            if (downsample)
            {
                ds = new HybridSequential();
                ds.Add(new Conv2D(channels, (1, 1), (stride, stride), use_bias: false, in_channels: in_channels));
                ds.Add(new BatchNorm());
                RegisterChild(ds, "downsample");
            }
            else
            {
                ds = null;
            }

            RegisterChild(body, "body");
        }
Esempio n. 5
0
 public BasicBlockV2(int channels, int stride, bool downsample = false, int in_channels = 0,
                     string prefix = null, ParameterDict @params = null) : base(prefix, @params)
 {
     bn1   = new BatchNorm();
     conv1 = ResNet.Conv3x3(channels, stride, in_channels);
     bn2   = new BatchNorm();
     conv2 = ResNet.Conv3x3(channels, 1, in_channels);
     if (downsample)
     {
         ds = new Conv2D(channels, (1, 1), (stride, stride), use_bias: false, in_channels: in_channels);
     }
     else
     {
         ds = null;
     }
 }
Esempio n. 6
0
        private void Btn_ML_modelLoad_Click(object sender, RoutedEventArgs e)
        {
            switch (MLCore.MLModelSelected)
            {
            case MLModel.ResNet:
                ResNet.LoadModel(TB_ML_modelName.Text);
                break;

            case MLModel.FastRCNN:
                break;

            case MLModel.Yolo:
                mYolo.LoadModel(GV.ML_Folders[(int)MLFolders.ML_YOLO_model]);
                break;
            }
            GB_ML_operation.IsEnabled = true;
        }
Esempio n. 7
0
 public BasicBlockV1(int channels, int stride, bool downsample = false, int in_channels = 0,
                     string prefix = null, ParameterDict @params = null) : base(prefix, @params)
 {
     body = new HybridSequential("");
     body.Add(ResNet.Conv3x3(channels, stride, in_channels));
     body.Add(new BatchNorm());
     body.Add(new Activation(ActivationType.Relu));
     body.Add(ResNet.Conv3x3(channels, 1, in_channels));
     body.Add(new BatchNorm());
     if (downsample)
     {
         ds = new HybridSequential();
         ds.Add(new Conv2D(channels, (1, 1), (stride, stride), use_bias: false, in_channels: in_channels));
         ds.Add(new BatchNorm());
     }
     else
     {
         ds = null;
     }
 }
Esempio n. 8
0
        public MainWindow()
        {
            //Static MainWindow
            mMainWindow = this;
            //Windows.main = this;
            DataContext = BindMngr;

            loadingScreen.Show();
            InitializeComponent();

            mTrainingWindow = new TrainingWindow();

            // Setup background worker
            PreviewRoutine.previewSetup();
            ConnectRoutine.connectionSetup();
            ImageResizing.ImageResizingSetup();
            ResNet.CNTK_ResNetSetup();
            ZxingDecoder.DecoderSetup();
            mTrainingWindow.TrainModelRoutineSetup();

            OCR.OCRSetup(OCRMode.NUMBERS);

            // Create Directories
            GV.ML_Folders[(int)MLFolders.MLRoot]           = Environment.CurrentDirectory + MLFolders.MLRoot.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_CNTK]          = Environment.CurrentDirectory + MLFolders.ML_CNTK.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_CNTK_model]    = Environment.CurrentDirectory + MLFolders.ML_CNTK_model.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO]          = Environment.CurrentDirectory + MLFolders.ML_YOLO.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_backup]   = Environment.CurrentDirectory + MLFolders.ML_YOLO_backup.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_model]    = Environment.CurrentDirectory + MLFolders.ML_YOLO_model.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_data]     = Environment.CurrentDirectory + MLFolders.ML_YOLO_data.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_data_img] = Environment.CurrentDirectory + MLFolders.ML_YOLO_data_img.GetDescription();

            foreach (string str in GV.ML_Folders)
            {
                if (str != null && !Directory.Exists(str))
                {
                    Directory.CreateDirectory(str);
                }
            }
        }
Esempio n. 9
0
        public static void Run()
        {
            var net   = ResNet.ResNet18_v2(true);
            var image = Img.ImRead("goldfish.jpg");

            image = Img.ResizeShort(image, 227);
            image = image.AsType(DType.Float32) / 255;
            var normalized = Img.ColorNormalize(image, new NDArray(new[] { 0.485f, 0.456f, 0.406f }),
                                                new NDArray(new[] { 0.229f, 0.224f, 0.225f }));

            normalized = normalized.Transpose(new Shape(2, 0, 1));
            normalized = normalized.ExpandDims(axis: 0);
            var     pred            = net.Call(normalized);
            NDArray prob            = nd.Softmax(pred).Topk(k: 5);
            var     label_index     = prob.ArrayData.OfType <float>().ToList();
            var     imagenet_labels = TestUtils.GetImagenetLabels();

            foreach (int i in label_index)
            {
                Console.WriteLine(imagenet_labels[i]);
            }
        }