コード例 #1
0
ファイル: ImageController.cs プロジェクト: Owliie/SuperRes
        public async System.Threading.Tasks.Task <IActionResult> PostAsync([FromForm] IFormFile image, [FromForm] string scale)
        {
            MLSharpPython ml = new MLSharpPython();

            if (System.IO.File.Exists(Constants.InputImage))
            {
                System.IO.File.Delete(Constants.InputImage);
            }
            using (var fileStream = new FileStream(Constants.InputImage, FileMode.Create))
            {
                await image.CopyToAsync(fileStream);
            }

            string error = string.Empty;

            ml.ExecutePythonScript("../../super_resolution/super_resolve.py " +
                                   $"--model_pth \"{Constants.ModelBasic}\" " +
                                   $"--input_image \"{Constants.InputImage}\" " +
                                   $"--output_image \"{Constants.OutputImage}\" "
                                   + $"--scale {scale}"
                                   , out error);

            Console.WriteLine(error);

            return(this.Ok());
        }
コード例 #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string scriptAndArgs = scriptDir + "savesommatrix.py";

            scriptAndArgs += " " + scriptDir + "params.json";

            // Load values from the form
            string[] dataColumns = new string[lstColumns.Items.Count];
            for (int i = 0; i < lstColumns.Items.Count; i++)
            {
                dataColumns[i] = lstColumns.Items[i].Text;
            }

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("trainingData", inputDir + txtInputFile.Text);
            data.Add("colsToLoad", JsonConvert.SerializeObject(dataColumns));
            data.Add("indexCol", ((int)nudIDColumn.Value).ToString());
            data.Add("matrixFile", outputDir + txtOutputFile.Text);
            data.Add("mapWidth", ((int)nudMapWidth.Value).ToString());
            data.Add("mapHeight", ((int)nudMapHeight.Value).ToString());
            data.Add("iterLim", ((int)nudIterLim.Value).ToString());
            data.Add("initLR", ((float)nudLearnRate.Value).ToString());
            data.Add("initRad", ((float)nudRadius.Value).ToString());

            // Save parameters to the params.json file for the Python script to see
            string json = JsonConvert.SerializeObject(data);

            File.WriteAllText(scriptDir + "params.json", json);

            MLSharpPython scriptRunner = new MLSharpPython(pythonExe);

            scriptRunner.ExecutePythonScript(scriptAndArgs, out string stdError1);

            /*scriptRunner.ExecutePythonScript(@"D:\Matt\Documents\GitRepos\Dataset-Visualisation-Dissertation\python\Kohonen\savecoords.py" +
             *                                  @" D:\Matt\Documents\GitRepos\Dataset-Visualisation-Dissertation\python\Kohonen\params.json",
             *                                  out string stdError2);*/
        }
コード例 #3
0
        public ActionResult Home()
        {
            var filePythonNamePath = @"C:\Users\tejoh\python\Face_Registration.py";
            var filePythonExePath  = @"C:\Users\tejoh\AppData\Local\Programs\Python\Python38\python.exe";
            var filename1          = @"C:\Users\tejoh\python\john1.jpg";
            var filename2          = @"C:\Users\tejoh\python\john2.jpg";


            byte[] imageArray = System.IO.File.ReadAllBytes(filename1);
            string base64ImageRepresentation = Convert.ToBase64String(imageArray);



            string outputText, standardError;

            // Instantiate Machine Learning C# - Python class object
            IMLSharpPython mlSharpPython = new MLSharpPython(filePythonExePath);

            // Define Python script file and input parameter name
            string fileNameParameter = $"{filePythonNamePath}" /*{filePythonParameterName} {imagePathName}*/;
            string arguments         = $"{base64ImageRepresentation}" /*{filePythonParameterName} {imagePathName}*/;

            // Execute the python script file

            outputText = mlSharpPython.ExecutePythonScript(fileNameParameter, arguments, out standardError);
            if (string.IsNullOrEmpty(standardError))
            {
            }
            else
            {
                Console.WriteLine(standardError);
            }
            Console.ReadKey();

            return(Ok("Testing page"));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: agandreev/Dos2017
        //private static string filePythonParameterName = Properties.Settings.Default.FilePythonParameterName;

        static void Main()
        {
            string outputText, standardError;

            // Instantiate Machine Learning C# - Python class object
            IMLSharpPython mlSharpPython = new MLSharpPython(filePythonExePath);

            // Define Python script file and input parameter name
            string fileNameParameter = $"{filePythonNamePath} {$"sth"}";

            // Execute the python script file
            outputText = mlSharpPython.ExecutePythonScript(fileNameParameter, out standardError);
            if (string.IsNullOrEmpty(standardError))
            {
                //if there aren't some execptions in python and c#
                Console.WriteLine(outputText);
            }
            else
            {
                //if there are some execption in python and c#
                Console.WriteLine(standardError);
            }
            Console.ReadKey();
        }