CaptchaReactNeuron
Changes
Details
diff --git a/NeuralNetwork/NeuralNetwork.Model/Services/ITextRecognisingService.cs b/NeuralNetwork/NeuralNetwork.Model/Services/ITextRecognisingService.cs
index f0bc300..2cc058d 100644
--- a/NeuralNetwork/NeuralNetwork.Model/Services/ITextRecognisingService.cs
+++ b/NeuralNetwork/NeuralNetwork.Model/Services/ITextRecognisingService.cs
@@ -19,6 +19,14 @@ namespace NeuralNetwork.Model.Services
int Work(byte[] image);
/// <summary>
+ /// Метод обучения нейросети
+ /// </summary>
+ /// <param name="image">изображение</param>
+ /// <param name="number">число, изображенное на картинке</param>
+ /// <returns></returns>
+ int Learn(byte[] image, int number);
+
+ /// <summary>
/// Вспомогательный метод, проверка открытия файла как картинки
/// </summary>
/// <param name="image"></param>
diff --git a/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs b/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
index 8de5a04..f328eab 100644
--- a/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
+++ b/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
@@ -57,19 +57,40 @@ namespace NeuralNetwork.Model.Services
if (collect.Length == 1)
{
var floatArray = BitmapToFloatArrayRgbQ(InsertBitmap(new Bitmap(bitmap.Clone(collect.First(), bitmap.PixelFormat), new Size(20, 20)), 28, 28));
- //var byteList = floatArray.Select(e => (byte)Math.Round(e * 256f)).ToList();
- //using (StreamWriter wr = new StreamWriter(@"D:\dataset.csv", true))
- //{
- // wr.Write("0");
- // byteList.ForEach(e => wr.Write("," + e));
- // wr.WriteLine();
- //}
- var res = MNIST.GetNumber(floatArray);
+ int res = -2;
return res;
}
}
return -1;
}
+
+ public int Learn(byte[] image, int number)
+ {
+ Bitmap bitmap = null;
+ try
+ {
+ using (MemoryStream stream = new MemoryStream(image))
+ {
+ bitmap = new Bitmap(stream);
+ }
+ if (bitmap != null)
+ {
+ bitmap = RemoveTransparency(bitmap);
+ var collect = FindObjects(BitmapToFloatMatrixRgbQ(bitmap));
+ if (collect.Length == 1)
+ {
+ var floatArray = BitmapToFloatArrayRgbQ(InsertBitmap(new Bitmap(bitmap.Clone(collect.First(), bitmap.PixelFormat), new Size(20, 20)), 28, 28));
+ MNIST.WriteNumber(floatArray, number);
+ return -2;
+ }
+ }
+ }
+ catch
+ {
+
+ }
+ return -1;
+ }
}
}
diff --git a/NeuralNetwork/NeuralNetwork.Neutral/CNTK/MNIST.cs b/NeuralNetwork/NeuralNetwork.Neutral/CNTK/MNIST.cs
index 37e1993..bcfe234 100644
--- a/NeuralNetwork/NeuralNetwork.Neutral/CNTK/MNIST.cs
+++ b/NeuralNetwork/NeuralNetwork.Neutral/CNTK/MNIST.cs
@@ -100,13 +100,17 @@ namespace NeuralNetwork.Model.Neutral.CNTK
static public class MNIST
{
- //private const string PathData = @"App_Data\train.csv";//@"d:\train.csv";//@"d:\dataset.csv";
+ private static string BaseDataPath;
+ private static string LearnDataPath;
private static DeviceDescriptor device = DeviceDescriptor.CPUDevice;
private static NeutralNetwork network;
- public static void Init(string path)
+ public static void Init(string baseDataPath, string learnDataPath)
{
- network = new NeutralNetwork(LoadData(path));
+ BaseDataPath = baseDataPath;
+ LearnDataPath = learnDataPath;
+
+ network = new NeutralNetwork(LoadData(BaseDataPath));
}
public static int GetNumber(float [] input)
@@ -130,7 +134,8 @@ namespace NeuralNetwork.Model.Neutral.CNTK
if (!File.Exists(path))
throw new System.IO.IOException($"File {path} not found.");
var f = File.ReadLines(path);
- var data = from t in f.Skip(1)
+ var data = from t in f
+ where !string.IsNullOrEmpty(t)
let zz = t.Split(',').Select(float.Parse)
select new Digit
{
@@ -139,5 +144,19 @@ namespace NeuralNetwork.Model.Neutral.CNTK
};
return data.ToArray();
}
+
+ public static void WriteNumber(float[] input, int number)
+ {
+ if (!string.IsNullOrEmpty(LearnDataPath))
+ {
+ var byteList = input.Select(e => (byte)System.Math.Round(e * 256f)).ToList();
+ using (StreamWriter wr = new StreamWriter(LearnDataPath, true))
+ {
+ wr.Write(number);
+ byteList.ForEach(e => wr.Write("," + e));
+ wr.WriteLine();
+ }
+ }
+ }
}
}
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/App_Data/learn.csv b/NeuralNetwork/NeuralNetwork.UI.Web/App_Data/learn.csv
new file mode 100644
index 0000000..c94cf54
--- /dev/null
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/App_Data/learn.csv
@@ -0,0 +1,6 @@
+2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,254,254,254,254,254,254,254,254,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,245,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,166,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0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0,0,0,0,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,179,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,82,254,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,229,229,254,25,25,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/API/TextRecognisingController.cs b/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/API/TextRecognisingController.cs
index 857d80c..c32804d 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/API/TextRecognisingController.cs
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/API/TextRecognisingController.cs
@@ -63,5 +63,61 @@ namespace NeuralNetwork.UI.Web.Controllers
return Json(model);
}
+
+ /// <summary>
+ /// Выполняет распознование цифр на изображении
+ /// </summary>
+ /// <param name="file">Base64 картинка</param>
+ /// <returns></returns>
+ [HttpPost]
+ public JsonResult Learn(string file, string number)
+ {
+ TextRecognisingResponseModel model = null;
+
+ try
+ {
+ var image_data = ConvertService.Base64ToByte(file);
+
+ if (!TextRecognisingService.TryOpen(image_data))
+ {
+ model = new TextRecognisingResponseModel()
+ {
+ Successe = false,
+ Message = "Ошибка. Не удалось открыть файл как изображение"
+ };
+
+ return Json(model);
+ }
+
+ int _number;
+ if (!int.TryParse(new string(number.Where(e => char.IsNumber(e)).ToArray()), out _number))
+ {
+ model = new TextRecognisingResponseModel()
+ {
+ Successe = false,
+ Message = "Ошибка. Не удалось обработать число для обучения"
+ };
+
+ return Json(model);
+ }
+
+ model = new TextRecognisingResponseModel()
+ {
+ Successe = true,
+ Message = "Ok",
+ Result = TextRecognisingService.Learn(image_data, _number)
+ };
+ }
+ catch (Exception ex)
+ {
+ model = new TextRecognisingResponseModel()
+ {
+ Successe = false,
+ Message = "Ошибка. В процессе обработки изображения произошла ошибка"
+ };
+ }
+
+ return Json(model);
+ }
}
}
\ No newline at end of file
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/AppController.cs b/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/AppController.cs
index 48a1342..56d1ebd 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/AppController.cs
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Controllers/AppController.cs
@@ -15,10 +15,10 @@ namespace NeuralNetwork.UI.Web.Controllers
return View();
}
- [HttpGet]
- public ActionResult ReactIndex()
- {
- return View();
- }
+ //[HttpGet]
+ //public ActionResult ReactIndex()
+ //{
+ // return View();
+ //}
}
}
\ No newline at end of file
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs b/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
index be163b7..f9cc5e1 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
@@ -22,18 +22,19 @@ namespace NeuralNetwork.UI.Web
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
- //AddBinToPathVar();
- //TestNetworkRun();
- //GCClear();
+ AddBinToPathVar();
+ TestNetworkRun();
+ GCClear();
}
- private void TestNetworkRun()
+ private void TestNetworkRun()
{
string path_App_Data = Server.MapPath("~/App_Data");
string path_DataSet = Path.Combine(path_App_Data, "train.csv");
+ string path_LearnSet = Path.Combine(path_App_Data, "learn.csv");
- NeuralNetwork.Model.Neutral.CNTK.MNIST.Init(path_DataSet);
+ NeuralNetwork.Model.Neutral.CNTK.MNIST.Init(path_DataSet, path_LearnSet);
}
private void AddBinToPathVar()
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj b/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
index 1de495d..48b3a4d 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
@@ -139,6 +139,7 @@
<Content Include="Content\bootstrap-reboot.css.map" />
<Content Include="Content\bootstrap-grid.min.css.map" />
<Content Include="Content\bootstrap-grid.css.map" />
+ <Content Include="App_Data\learn.csv" />
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
<Content Include="Scripts\bootstrap.bundle.js" />
<Content Include="Scripts\bootstrap.bundle.min.js" />
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Api/API_TextRecognising.js b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Api/API_TextRecognising.js
index dd6a53e..474da61 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Api/API_TextRecognising.js
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Api/API_TextRecognising.js
@@ -3,6 +3,7 @@ class API_TextRecognising {
constructor() {
this.URL_TextRecognising = "/TextRecognising/Recognising";
+ this.URL_TextRecognising_Learn = "/TextRecognising/Learn";
}
@@ -28,4 +29,26 @@ class API_TextRecognising {
return json;
}
+ async Request_TextRecognising_Learn(file, number) {
+
+ console.log("Api request:" + this.URL_TextRecognising_Learn);
+
+ let response = await fetch(this.URL_TextRecognising_Learn,
+ {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({
+ file: file,
+ number: number
+ })
+ }
+ );
+ let json = await response.json();
+
+
+ return json;
+ }
+
}
\ No newline at end of file
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
index 39d2665..20070f6 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
@@ -7,7 +7,8 @@ class ReactAppPage extends React.Component {
this.api = new API_TextRecognising();
this.state =
{
- TextRecognising_Result: ""
+ TextRecognising_Result: "",
+ TextRecognising_Learn: ""
};
this.api = new API_TextRecognising();
@@ -15,6 +16,8 @@ class ReactAppPage extends React.Component {
//@* Прикрепление текущего объекта к this в функции обработки *@
this._OnClick_Button_Clear = this._OnClick_Button_Clear.bind(this);
this._OnClick_Button_Recognized = this._OnClick_Button_Recognized.bind(this);
+ this._OnClick_Button_Learn = this._OnClick_Button_Learn.bind(this);
+ this.handleInputChange = this.handleInputChange.bind(this);
}
componentDidMount() {
@@ -23,8 +26,13 @@ class ReactAppPage extends React.Component {
this.canvas.PrintLine();
}
+ handleInputChange(event) {
+ this.setState({ TextRecognising_Learn: event.target.value });
+ }
+
_OnClick_Button_Clear() {
this.canvas.ClearCanvas();
+ this.setState({ TextRecognising_Result: "", TextRecognising_Learn: "" });
}
_OnClick_Button_Recognized() {
@@ -36,6 +44,15 @@ class ReactAppPage extends React.Component {
});
}
+ _OnClick_Button_Learn() {
+ let image = this.canvas.GetImage();
+
+ this.api.Request_TextRecognising_Learn(image, this.state.TextRecognising_Learn)
+ .then((data) => {
+ this.setState({ TextRecognising_Result: data.Result });
+ });
+ }
+
render() {
return (
<div>
@@ -60,7 +77,19 @@ class ReactAppPage extends React.Component {
<div className="input-group-prepend">
<span className="input-group-text" id="basic-addon1">Result:</span>
</div>
- <input type="text" readonly="readonly" value={this.state.TextRecognising_Result} className="form-control" aria-describedby="basic-addon1"/>
+ <input type="text" readOnly="readonly" value={this.state.TextRecognising_Result} className="form-control" aria-describedby="basic-addon1"/>
+ </div>
+
+ <div className="input-group mb-3">
+ <div className="input-group-prepend">
+ <button
+ type="button"
+ onClick={this._OnClick_Button_Learn}
+ className="btn btn-secondary">
+ Обучить
+ </button>
+ </div>
+ <input type="text" value={this.state.TextRecognising_Learn} className="form-control" onChange={this.handleInputChange}/>
</div>
</div>
);
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Views/App/Index.cshtml b/NeuralNetwork/NeuralNetwork.UI.Web/Views/App/Index.cshtml
index 370748f..bf579e2 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Views/App/Index.cshtml
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Views/App/Index.cshtml
@@ -1,6 +1,6 @@
@{
- ViewBag.Title = "Index";
+ ViewBag.Title = "ReactIndex";
}
@*Canvas*@
@@ -8,20 +8,13 @@
@Scripts.Render("~/bundles/Canvas/JS")
@* API *@
@Scripts.Render("~/bundles/API")
-@* Page script *@
-@Scripts.Render("~/bundles/Pages/AppPage")
-<h2>Index</h2>
-<div class="CanvasContainer">
- <canvas id="Canvas" width="500" height="300"></canvas>
-</div>
+@Scripts.Render("~/bundles/React")
+@* Page script *@
+<script src="~/Scripts/Site/Pages/ReactAppPage.jsx" type="text/babel">
+</script>
+
+<h2>ReactIndex</h2>
-<button id="Button_Clear" type="button" class="btn btn-secondary">Очистить</button>
-<button id="Button_Recognized" type="button" class="btn btn-secondary">Распознать</button>
-<div class="input-group mb-3">
- <div class="input-group-prepend">
- <span class="input-group-text" id="basic-addon1">Result:</span>
- </div>
- <input id="Input_Result" type="text" readonly="readonly" class="form-control" aria-describedby="basic-addon1">
-</div>
\ No newline at end of file
+<div id="app"></div>
\ No newline at end of file
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Views/Shared/_Layout.cshtml b/NeuralNetwork/NeuralNetwork.UI.Web/Views/Shared/_Layout.cshtml
index f133f65..d7189b9 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Views/Shared/_Layout.cshtml
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Views/Shared/_Layout.cshtml
@@ -21,12 +21,9 @@
</div>
<div class="navbar-collapse collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav mr-auto">
- @*<li>@Html.ActionLink("Домашняя страница", "Index", "Home")</li>
- <li>@Html.ActionLink("Информация", "About", "Home")</li>
- <li>@Html.ActionLink("Связаться", "Contact", "Home")</li>*@
<li class="nav-item">@Html.ActionLink("TextRecognising", "Index", "App", null, new { @class = "nav-link" })</li>
- <li class="nav-item">@Html.ActionLink("React", "ReactIndex", "App", null, new { @class = "nav-link" })</li>
- <li class="nav-item">@Html.ActionLink("Test", "Index", "Test", null, new { @class = "nav-link" })</li>
+ @*<li class="nav-item">@Html.ActionLink("React", "ReactIndex", "App", null, new { @class = "nav-link" })</li>*@
+ @*<li class="nav-item">@Html.ActionLink("Test", "Index", "Test", null, new { @class = "nav-link" })</li>*@
</ul>
</div>
</div>
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Views/Test/Index.cshtml b/NeuralNetwork/NeuralNetwork.UI.Web/Views/Test/Index.cshtml
index f4fac26..059f5b3 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Views/Test/Index.cshtml
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Views/Test/Index.cshtml
@@ -10,7 +10,7 @@
@Scripts.Render("~/bundles/API")
@Scripts.Render("~/bundles/Pages/TestPage")
-<h2>Index</h2>
+<h2>Index test</h2>
<div class="CanvasContainer">
<canvas id="Canvas" width="500" height="300"></canvas>