CaptchaReactNeuron

8

12/15/2019 9:05:10 PM

Details

diff --git a/NeuralNetwork/NeuralNetwork.Model/NeuralNetwork.Model.csproj b/NeuralNetwork/NeuralNetwork.Model/NeuralNetwork.Model.csproj
index b0c9f06..c52c0ae 100644
--- a/NeuralNetwork/NeuralNetwork.Model/NeuralNetwork.Model.csproj
+++ b/NeuralNetwork/NeuralNetwork.Model/NeuralNetwork.Model.csproj
@@ -69,6 +69,10 @@
     <Folder Include="Entities\" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\NeuralNetwork.Neutral\NeuralNetwork.Neutral.csproj">
+      <Project>{4367a5a8-8bd8-4e9c-aac1-5b44a97d9114}</Project>
+      <Name>NeuralNetwork.Neutral</Name>
+    </ProjectReference>
     <ProjectReference Include="..\NeuralNetwork.PictureWork\NeuralNetwork.PictureWork.csproj">
       <Project>{31fd7758-278b-4174-9bda-67925fe9425c}</Project>
       <Name>NeuralNetwork.PictureWork</Name>
diff --git a/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs b/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
index 0b1d3ea..8de5a04 100644
--- a/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
+++ b/NeuralNetwork/NeuralNetwork.Model/Services/TextRecognisingService.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
 using System.IO;
 using System.Drawing;
 using static NeuralNetwork.PictureWork.PictureWork;
+using NeuralNetwork.Model.Neutral.CNTK;
 
 namespace NeuralNetwork.Model.Services
 {
@@ -55,13 +56,16 @@ namespace NeuralNetwork.Model.Services
                 var collect = FindObjects(BitmapToFloatMatrixRgbQ(bitmap));
                 if (collect.Length == 1)
                 {
-                    var byteList = BitmapToFloatArrayRgbQ(new Bitmap(bitmap.Clone(collect.First(), bitmap.PixelFormat), new Size(28, 28))).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 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);
+                    return res;
                 }
             }
 
diff --git a/NeuralNetwork/NeuralNetwork.PictureWork/PictureWork.cs b/NeuralNetwork/NeuralNetwork.PictureWork/PictureWork.cs
index fd99c27..1ac5575 100644
--- a/NeuralNetwork/NeuralNetwork.PictureWork/PictureWork.cs
+++ b/NeuralNetwork/NeuralNetwork.PictureWork/PictureWork.cs
@@ -185,5 +185,15 @@ namespace NeuralNetwork.PictureWork
             }
             return _array;
         }
+
+        public static Bitmap InsertBitmap(Bitmap src, int targetWidth, int targetHeight)
+        {
+            Bitmap target = new Bitmap(targetWidth, targetHeight);
+            Graphics g = Graphics.FromImage(target);
+            g.Clear(Color.White);
+            g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
+            g.DrawImage(src, 4, 4);
+            return target;
+        }
     }
 }
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs b/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
index 4d55181..25d49c6 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Global.asax.cs
@@ -23,7 +23,8 @@ namespace NeuralNetwork.UI.Web
             BundleConfig.RegisterBundles(BundleTable.Bundles);
 
             AddBinToPathVar();
-            TestNetworkRun();            
+            TestNetworkRun();
+            GCClear();
         }
 
 
@@ -41,7 +42,12 @@ namespace NeuralNetwork.UI.Web
 
             PathProvider pp = new PathProvider();
             pp.AddIfNot(path_bin, EnvironmentVariableTarget.Process);
-        }    
+        }
+
+        private void GCClear()
+        {
+            GC.Collect();
+        }
 
     }
 }
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj b/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
index 804bd6d..80bc7ae 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/NeuralNetwork.UI.Web.csproj
@@ -121,10 +121,6 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="Content\bootstrap-theme.css" />
-    <Content Include="Content\bootstrap-theme.min.css" />
-    <Content Include="Content\bootstrap.css" />
-    <Content Include="Content\bootstrap.min.css" />
     <Content Include="Content\Site\Tools\Canvas.css" />
     <Content Include="favicon.ico" />
     <Content Include="fonts\glyphicons-halflings-regular.svg" />
@@ -134,24 +130,7 @@
     <Content Include="fonts\glyphicons-halflings-regular.woff" />
     <Content Include="fonts\glyphicons-halflings-regular.ttf" />
     <Content Include="fonts\glyphicons-halflings-regular.eot" />
-    <Content Include="Content\bootstrap.min.css.map" />
-    <Content Include="Content\bootstrap.css.map" />
-    <Content Include="Content\bootstrap-theme.min.css.map" />
-    <Content Include="Content\bootstrap-theme.css.map" />
     <None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
-    <None Include="Scripts\jquery-3.3.1.intellisense.js" />
-    <Content Include="Scripts\bootstrap.js" />
-    <Content Include="Scripts\bootstrap.min.js" />
-    <Content Include="Scripts\jquery-3.3.1.js" />
-    <Content Include="Scripts\jquery-3.3.1.min.js" />
-    <Content Include="Scripts\jquery-3.3.1.slim.js" />
-    <Content Include="Scripts\jquery-3.3.1.slim.min.js" />
-    <None Include="Scripts\jquery.validate-vsdoc.js" />
-    <Content Include="Scripts\jquery.validate.js" />
-    <Content Include="Scripts\jquery.validate.min.js" />
-    <Content Include="Scripts\jquery.validate.unobtrusive.js" />
-    <Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
-    <Content Include="Scripts\modernizr-2.8.3.js" />
     <Content Include="Scripts\Site\Api\API_TextRecognising.js" />
     <Content Include="Scripts\Site\Pages\AppPage.js" />
     <Content Include="Scripts\Site\Pages\ReactAppPage.jsx" />
@@ -181,8 +160,6 @@
   <ItemGroup>
     <Content Include="App_Data\train.csv" />
     <None Include="packages.config" />
-    <Content Include="Scripts\jquery-3.3.1.slim.min.map" />
-    <Content Include="Scripts\jquery-3.3.1.min.map" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\AppTools\AppTools.csproj">
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
index bac3149..39d2665 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/ReactAppPage.jsx
@@ -40,7 +40,7 @@ class ReactAppPage extends React.Component {
         return (
             <div>
                 <div className="CanvasContainer">
-                    <canvas ref={"CanvasElem"} width="500" height="300"></canvas>
+                    <canvas ref={"CanvasElem"} width="500" height="300"/>
                 </div>
 
                 <button
@@ -60,7 +60,7 @@ 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>
+                    <input type="text" readonly="readonly" value={this.state.TextRecognising_Result} className="form-control" aria-describedby="basic-addon1"/>
                 </div>
             </div>
         );
diff --git a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/TestPage.js b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/TestPage.js
index 6353fa8..46ca3ae 100644
--- a/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/TestPage.js
+++ b/NeuralNetwork/NeuralNetwork.UI.Web/Scripts/Site/Pages/TestPage.js
@@ -7,9 +7,9 @@ var canvas;
 function ready() {
     api = new API_TextRecognising();
 
-      canvas = new Canvas(document.getElementById("Canvas"));
-	  canvas.Set_UserWrite(true);
-	  canvas.PrintLine();
+    canvas = new Canvas(document.getElementById("Canvas"));
+	canvas.Set_UserWrite(true);
+	canvas.PrintLine();
   }
 
   document.addEventListener("DOMContentLoaded", ready);
\ No newline at end of file