├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── Functions ├── .gitignore ├── .vscode │ └── extensions.json ├── Functions.csproj ├── HttpExample.cs ├── host.json └── local.settings.json ├── backend ├── DLLs │ └── NeuralNetwork.dll ├── MNISTReader.cs ├── NeuralNetwork.cs ├── TeachNetwork.csproj ├── bin │ └── Debug │ │ └── netcoreapp3.1 │ │ ├── NeuralNetwork.dll │ │ ├── TeachNetwork.deps.json │ │ ├── TeachNetwork.dll │ │ └── TeachNetwork.pdb ├── data │ ├── t10k-images.idx3-ubyte │ ├── t10k-labels.idx1-ubyte │ ├── train-images.idx3-ubyte │ └── train-labels.idx1-ubyte └── obj │ ├── Debug │ └── netcoreapp3.1 │ │ ├── .NETCoreApp,Version=v3.1.AssemblyAttributes.cs │ │ ├── TeachNetwork.AssemblyInfo.cs │ │ ├── TeachNetwork.AssemblyInfoInputs.cache │ │ ├── TeachNetwork.assets.cache │ │ ├── TeachNetwork.csproj.CopyComplete │ │ ├── TeachNetwork.csproj.CoreCompileInputs.cache │ │ ├── TeachNetwork.csproj.FileListAbsolute.txt │ │ ├── TeachNetwork.csprojAssemblyReference.cache │ │ ├── TeachNetwork.dll │ │ └── TeachNetwork.pdb │ ├── TeachNetwork.csproj.nuget.dgspec.json │ ├── TeachNetwork.csproj.nuget.g.props │ ├── TeachNetwork.csproj.nuget.g.targets │ ├── project.assets.json │ └── project.nuget.cache └── frontend ├── .eslintcache ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.js ├── components ├── CreateNN.js ├── Landing.js ├── NeuralNetwork.js ├── NeuralNetworkFunctions.js ├── start.svg ├── stop.svg └── upload.svg ├── index.js └── scss ├── app.scss └── components ├── create.module.scss ├── general.scss ├── landing.module.scss └── neuralnetwork.module.scss /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/backend/bin/Debug/netcoreapp3.1/TeachNetwork.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/backend", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach", 24 | "processId": "${command:pickProcess}" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "git.ignoreLimitWarning": true 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Back-end/Back-end.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/Back-end/Back-end.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/Back-end/Back-end.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /Functions/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Azure Functions localsettings file 5 | #local.settings.json 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | #*.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.jfm 196 | *.pfx 197 | *.publishsettings 198 | node_modules/ 199 | orleans.codegen.cs 200 | 201 | # Since there are multiple workflows, uncomment next line to ignore bower_components 202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 203 | #bower_components/ 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # Paket dependency manager 249 | .paket/paket.exe 250 | paket-files/ 251 | 252 | # FAKE - F# Make 253 | .fake/ 254 | 255 | # JetBrains Rider 256 | .idea/ 257 | *.sln.iml 258 | 259 | # CodeRush 260 | .cr/ 261 | 262 | # Python Tools for Visual Studio (PTVS) 263 | __pycache__/ 264 | *.pyc -------------------------------------------------------------------------------- /Functions/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-azuretools.vscode-azurefunctions" 4 | ] 5 | } -------------------------------------------------------------------------------- /Functions/Functions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | v3 5 | clear 6 | 7 | 8 | 9 | 10 | 11 | 12 | PreserveNewest 13 | 14 | 15 | PreserveNewest 16 | Never 17 | 18 | 19 | 20 | 21 | 22 | ..\backend\bin\Debug\netcoreapp3.1\TeachNetwork.dll 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Functions/HttpExample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Azure.WebJobs; 6 | using Microsoft.Azure.WebJobs.Extensions.Http; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.Logging; 9 | using Newtonsoft.Json; 10 | using NNFunctions; 11 | using System.Collections.Generic; 12 | using System.Threading; 13 | 14 | namespace Functions 15 | { 16 | public static class AsyncNN 17 | { 18 | public struct NN 19 | { 20 | public CancellationTokenSource CancellationToken { get; set; } 21 | public TeachNetwork Network { get; set; } 22 | } 23 | public static Dictionary asyncNeuralNetwork = new Dictionary(); 24 | public static int key = 0; 25 | } 26 | 27 | public static class HttpFunctions 28 | { 29 | 30 | public struct NNSetup 31 | { 32 | public double MomentTemp { get; set; } 33 | public double LearningRateTemp { get; set; } 34 | public string NeuronsAndLayers { get; set; } 35 | public double TerminatingErrorProcents { get; set; } 36 | } 37 | [FunctionName("StartNN")] 38 | public static async Task StartNN([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 39 | { 40 | log.LogInformation("C# HTTP trigger function processed a request."); 41 | 42 | NNSetup data; 43 | try 44 | { 45 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 46 | data = JsonConvert.DeserializeObject(requestBody); 47 | } 48 | catch (Exception ex) 49 | { 50 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 51 | } 52 | try 53 | { 54 | var cancellationToken = new CancellationTokenSource(); 55 | 56 | var network = new TeachNetwork 57 | { 58 | MomentTemp = data.MomentTemp == 0 ? 0.5 : data.MomentTemp, 59 | LearningRateTemp = data.LearningRateTemp == 0 ? 0.1 : data.LearningRateTemp, 60 | NeuronsAndLayers = string.IsNullOrEmpty(data.NeuronsAndLayers) ? "784 26+ 16 10" : data.NeuronsAndLayers, 61 | terminatingErrorProcents = data.TerminatingErrorProcents == 0 ? 0.00011 : data.TerminatingErrorProcents 62 | }; 63 | 64 | AsyncNN.asyncNeuralNetwork.Add(AsyncNN.key, new AsyncNN.NN { CancellationToken = cancellationToken, Network = network }); 65 | Thread workerThread = new Thread(() => AsyncNN.asyncNeuralNetwork[AsyncNN.key - 1].Network.Start(cancellationToken)); // I don't know why it doesn't work without the '- 1' 66 | workerThread.Start(); 67 | 68 | return new OkObjectResult(AsyncNN.key++); //A key so the used could access to the sertain NeuralNetwork 69 | } 70 | catch (Exception ex) 71 | { 72 | return new BadRequestObjectResult("The error occured at the Task call of the NeuralNetwork " + ex); 73 | } 74 | } 75 | 76 | [FunctionName("StopNN")] 77 | public static async Task StopNN([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 78 | { 79 | log.LogInformation("C# HTTP trigger function processed a request."); 80 | 81 | int data; 82 | try 83 | { 84 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 85 | data = JsonConvert.DeserializeObject(requestBody); 86 | } 87 | catch (Exception ex) 88 | { 89 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 90 | } 91 | try 92 | { 93 | var NN = AsyncNN.asyncNeuralNetwork[data].CancellationToken; 94 | 95 | NN.Cancel(); 96 | 97 | return new OkObjectResult(true); 98 | } 99 | catch (Exception ex) 100 | { 101 | return new BadRequestObjectResult("Something bad happened:\n" + ex); 102 | } 103 | } 104 | 105 | [FunctionName("ContinueNN")] 106 | public static async Task ContinueNN([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 107 | { 108 | log.LogInformation("C# HTTP trigger function processed a request."); 109 | 110 | int data; 111 | try 112 | { 113 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 114 | data = JsonConvert.DeserializeObject(requestBody); 115 | } 116 | catch (Exception ex) 117 | { 118 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 119 | } 120 | try 121 | { 122 | var NN = AsyncNN.asyncNeuralNetwork[data]; 123 | 124 | var cancellationToken = new CancellationTokenSource(); 125 | 126 | AsyncNN.asyncNeuralNetwork[data] = new AsyncNN.NN { CancellationToken = cancellationToken, Network = NN.Network }; 127 | 128 | Thread workerThread = new Thread(() => NN.Network.Start(cancellationToken)); 129 | workerThread.Start(); 130 | 131 | return new OkObjectResult(true); //Key so the user could access to the sertain NeuralNetwork 132 | } 133 | catch (Exception ex) 134 | { 135 | return new BadRequestObjectResult("Something bad happened:\n" + ex); 136 | } 137 | } 138 | 139 | [FunctionName("TestNN")] 140 | public static async Task TestNN([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 141 | { 142 | log.LogInformation("C# HTTP trigger function processed a request."); 143 | 144 | int data; 145 | try 146 | { 147 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 148 | data = JsonConvert.DeserializeObject(requestBody); 149 | } 150 | catch (Exception ex) 151 | { 152 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 153 | } 154 | try 155 | { 156 | var cancellationToken = new CancellationTokenSource(); 157 | var response = await Task.Run(() => AsyncNN.asyncNeuralNetwork[AsyncNN.key - 1].Network.Test(cancellationToken)); // I don't know why it doesn't work without the '- 1' 158 | 159 | return new OkObjectResult(response); //Key so the used could access to the sertain NeuralNetwork 160 | } 161 | catch (Exception ex) 162 | { 163 | return new BadRequestObjectResult("Something bad happened:\n" + ex); 164 | } 165 | } 166 | 167 | public struct Response 168 | { 169 | public int iteration; 170 | public int trainingSets; 171 | public double errorSum; 172 | public string sw; 173 | } 174 | 175 | [FunctionName("GetNNState")] 176 | public static async Task GetNNState([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 177 | { 178 | log.LogInformation("C# HTTP trigger function processed a request."); 179 | 180 | int data; 181 | try 182 | { 183 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 184 | data = JsonConvert.DeserializeObject(requestBody); 185 | } 186 | catch (Exception ex) 187 | { 188 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 189 | } 190 | 191 | try 192 | { 193 | var NN = AsyncNN.asyncNeuralNetwork[data].Network; 194 | 195 | return new OkObjectResult(new Response { iteration = (int)NN.iteration, trainingSets = NN.trainingSets, errorSum = NN.errorSum, sw = ((double)NN.sw.ElapsedMilliseconds / 1000).ToString("#,0.000", NN.sepByThous) }); //Key so the used could access to the sertain NeuralNetwork 196 | } 197 | catch (Exception ex) 198 | { 199 | return new BadRequestObjectResult("Something bad happened:\n" + ex); 200 | } 201 | } 202 | 203 | [FunctionName("DeleteNN")] 204 | public static async Task DeleteNN([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) 205 | { 206 | log.LogInformation("C# HTTP trigger function processed a request."); 207 | 208 | int data; 209 | try 210 | { 211 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 212 | data = JsonConvert.DeserializeObject(requestBody); 213 | } 214 | catch (Exception ex) 215 | { 216 | return new BadRequestObjectResult("Nicely done, I've received an error at the JSON deserialization:\n" + ex); 217 | } 218 | 219 | try 220 | { 221 | var NN = AsyncNN.asyncNeuralNetwork[data].CancellationToken; 222 | 223 | NN.Cancel(); 224 | NN.Dispose(); 225 | AsyncNN.asyncNeuralNetwork.Remove(data); 226 | 227 | return new OkObjectResult(true); //Key so the used could access to the sertain NeuralNetwork 228 | } 229 | catch (Exception ex) 230 | { 231 | return new BadRequestObjectResult("Something bad happened:\n" + ex); 232 | } 233 | } 234 | 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /Functions/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingExcludedTypes": "Request", 6 | "samplingSettings": { 7 | "isEnabled": true 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Functions/local.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsEncrypted": false, 3 | "Values": { 4 | "AzureWebJobsStorage": "UseDevelopmentStorage=true", 5 | "FUNCTIONS_WORKER_RUNTIME": "dotnet" 6 | }, 7 | "Host": { 8 | "LocalHttpPort": 7071, 9 | "CORS": "*" 10 | } 11 | } -------------------------------------------------------------------------------- /backend/DLLs/NeuralNetwork.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/DLLs/NeuralNetwork.dll -------------------------------------------------------------------------------- /backend/MNISTReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.IO; 4 | 5 | namespace MNISTReader 6 | { 7 | public static class ArrayExtensions 8 | { 9 | public static T[] CopyRange(this T[] inputArray, int startIndex, int length) 10 | { 11 | var outputArray = new T[length]; 12 | for (var i = startIndex; i < startIndex + length; i++) 13 | { 14 | outputArray[i - startIndex] = inputArray[i]; 15 | } 16 | return outputArray; 17 | } 18 | } 19 | 20 | public class LabeledTrainingData 21 | { 22 | public double[] Data { get; } 23 | public double[] Label { get; } 24 | 25 | public LabeledTrainingData(byte[] data, double[] label) 26 | { 27 | Data = new double[data.Length]; 28 | for (var i = 0; i < data.Length; i++) 29 | { 30 | Data[i] = data[i] / 255f; 31 | } 32 | Label = label; 33 | } 34 | } 35 | 36 | /// 37 | /// Class for reading the MNIST dataset which can be found here: http://yann.lecun.com/exdb/mnist/ 38 | /// 39 | public static class Reader 40 | { 41 | private const int OFFSET_SIZE = 4; 42 | 43 | private const int NUMBER_ITEMS_OFFSET = 4; 44 | private const int ITEMS_SIZE = 4; 45 | 46 | public const int ROWS = 28; 47 | 48 | public const int COLUMNS = 28; 49 | 50 | private const int IMAGE_OFFSET = 16; 51 | private const int IMAGE_SIZE = ROWS * COLUMNS; 52 | 53 | /// 54 | /// Reads the labels and images from the MNIST dataset and puts them in 55 | /// 56 | public static LabeledTrainingData[] LoadDigitImages(byte[] labelBytes, byte[] imageBytes) 57 | { 58 | 59 | var numberOfLabels = BitConverter.ToInt32(labelBytes.CopyRange(NUMBER_ITEMS_OFFSET, 4).Reverse().ToArray(), 0); 60 | var numberOfImages = BitConverter.ToInt32(imageBytes.CopyRange(NUMBER_ITEMS_OFFSET, 4).Reverse().ToArray(), 0); 61 | 62 | if (numberOfImages != numberOfLabels) 63 | { 64 | throw new IOException("The number of labels and images do not match!"); 65 | } 66 | 67 | var images = new LabeledTrainingData[numberOfLabels]; 68 | for (var i = 0; i < numberOfLabels; i++) 69 | { 70 | var label = labelBytes[OFFSET_SIZE + ITEMS_SIZE + i]; 71 | var labels = new double[10]; 72 | labels[label] = 1; 73 | var imageData = imageBytes.CopyRange(i * IMAGE_SIZE + IMAGE_OFFSET, IMAGE_SIZE); 74 | images[i] = new LabeledTrainingData(imageData, labels); 75 | } 76 | return images; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /backend/NeuralNetwork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NN; 3 | using MNISTReader; 4 | using System.IO; 5 | using System.Globalization; 6 | using System.Threading.Tasks; 7 | using System.Threading; 8 | 9 | namespace NNFunctions 10 | { 11 | public class TeachNetwork 12 | { 13 | private CancellationToken ct; 14 | readonly static string path = @"C:\Users\valer\Desktop\GitSave\HelloReact\backend\data\"; 15 | 16 | public double MomentTemp = 0.5; 17 | public double LearningRateTemp = 0.1; 18 | public string NeuronsAndLayers = "784 26+ 16 10"; //"[0]-InputNeurons, [1]-Neurons In 1-st HiddenLayer, 19 | // [2]-Neurons In 2-nd HiddenLayer,[..],[n-1]-Neurons In (n-1)-th HiddenLayer, [n]-OutputNeurons" 20 | // put + in each layer (except OUTPUT) to add bias 21 | public double terminatingErrorProcents = 0.00011; //The average error procent on which we want to end training 22 | 23 | private uint CheckForMistakes(ref NeuralNetwork network, ref LabeledTrainingData[] testData) 24 | { 25 | uint errCount = 0; 26 | 27 | for (uint i = 0; i < testData.GetLength(0); ++i) //Run through all TEST units 28 | { 29 | Neuron[] answer = network.RunNetwork(testData[i].Data); 30 | 31 | double biggestNumber = answer[0].value; 32 | uint bigNumIndex = 0; 33 | for (uint j = 0; j < answer.Length; ++j) //Normalizing answers in this unit 34 | { 35 | if (answer[j].value > biggestNumber) 36 | { 37 | biggestNumber = answer[j].value; 38 | bigNumIndex = j; 39 | } 40 | 41 | answer[j].value = 0; 42 | } 43 | answer[bigNumIndex].value = 1; 44 | 45 | for (uint j = 0; j < answer.Length; ++j) //Checking answers in this unit for a mistake 46 | { 47 | if (answer[j].value != testData[i].Label[j]) //If a mistake was made then: 48 | { 49 | ++errCount; 50 | break; 51 | } 52 | } 53 | } 54 | 55 | return errCount; 56 | } 57 | 58 | public uint iteration; 59 | public double errorSum; 60 | public int trainingSets = 1; 61 | 62 | public System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); 63 | public NumberFormatInfo sepByThous = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); 64 | 65 | 66 | private LabeledTrainingData[] test; 67 | private NeuralNetwork network; 68 | 69 | public async Task Start(CancellationTokenSource tokenSource2) 70 | { 71 | ct = tokenSource2.Token; 72 | 73 | Console.WriteLine("NeuralNetwork created"); 74 | 75 | await Task.Run(() => 76 | { 77 | ct.ThrowIfCancellationRequested(); 78 | 79 | sepByThous.NumberGroupSeparator = " "; 80 | 81 | #region Training&Test initialization 82 | 83 | byte[] labelData = File.ReadAllBytes(path + "train-labels.idx1-ubyte"); 84 | byte[] imageData = File.ReadAllBytes(path + "train-images.idx3-ubyte"); 85 | 86 | var train = Reader.LoadDigitImages(labelData, imageData); 87 | 88 | labelData = File.ReadAllBytes(path + "t10k-labels.idx1-ubyte"); 89 | imageData = File.ReadAllBytes(path + "t10k-images.idx3-ubyte"); 90 | test = Reader.LoadDigitImages(labelData, imageData); 91 | 92 | #endregion 93 | 94 | #region Main part - network training 95 | //Creating an object of NeuralNetwork with same parameters as we described in variables 96 | //NeuralNetwork network = new NeuralNetwork(@"C:\s\Neural.aaa"); 97 | network = new NeuralNetwork(NeuronsAndLayers, -1, 1) 98 | { 99 | Moment = MomentTemp, 100 | LearningRate = LearningRateTemp 101 | }; 102 | 103 | sw.Start(); 104 | 105 | uint i; 106 | uint j; 107 | double end; 108 | double error; 109 | Neuron[] endValue; 110 | do 111 | { 112 | iteration = 0; 113 | errorSum = 0; 114 | for (i = 0; i < train.Length; ++i) //Run through all TRAIN units 115 | { 116 | //Running the network with current INPUT values of this unit 117 | endValue = network.RunNetwork(train[i].Data); 118 | 119 | //Counting an error of current unit 120 | end = 0; 121 | for (j = 0; j < endValue.Length; ++j) 122 | end += Math.Pow(train[i].Label[j] - endValue[j].value, 2); 123 | error = end / train.Length; //((i-a1)*(i1-a1)+...+(in-an)*(in-an))/n 124 | errorSum += error; 125 | 126 | network.TeachNetwork(train[i].Label); 127 | 128 | //if (iteration++ % 1800 == 0) 129 | //Console.WriteLine("Iteration: " + trainingSets + " | " + iteration.ToString("#,0", sepByThous) + " current error = " + error + "% " + " average error = " + Math.Round(errorSum / train.GetLength(0) * 100, 5) + "% " + ((double)sw.ElapsedMilliseconds / 1000).ToString("#,0.000", sepByThous) + " sec"); 130 | 131 | ++iteration; 132 | 133 | if(ct.IsCancellationRequested) 134 | { 135 | Console.WriteLine("\nI'm disposing :'(\n"); 136 | 137 | sw.Stop(); 138 | 139 | ct.ThrowIfCancellationRequested(); 140 | } 141 | } 142 | ++trainingSets; 143 | } while (errorSum / train.GetLength(0) * 100 > terminatingErrorProcents); //while average error procent is greater tnah TEP - continue 144 | sw.Stop(); 145 | #endregion 146 | }, tokenSource2.Token); 147 | } 148 | 149 | public struct Response 150 | { 151 | public int TestCount { get; set; } 152 | public int ErrCount { get; set; } 153 | } 154 | 155 | public async Task Test(CancellationTokenSource tokenSource2) 156 | { 157 | var errCount = await Task.Run(() => CheckForMistakes(ref network, ref test), tokenSource2.Token); 158 | 159 | return new Response { TestCount = test.Length, ErrCount = (int)errCount}; 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /backend/TeachNetwork.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | library 5 | netcoreapp3.1 6 | Back_end 7 | clear 8 | 9 | 10 | 11 | 12 | ..\Dlls\NeuralNetwork.dll 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /backend/bin/Debug/netcoreapp3.1/NeuralNetwork.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/bin/Debug/netcoreapp3.1/NeuralNetwork.dll -------------------------------------------------------------------------------- /backend/bin/Debug/netcoreapp3.1/TeachNetwork.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeTarget": { 3 | "name": ".NETCoreApp,Version=v3.1", 4 | "signature": "" 5 | }, 6 | "compilationOptions": {}, 7 | "targets": { 8 | ".NETCoreApp,Version=v3.1": { 9 | "TeachNetwork/1.0.0": { 10 | "dependencies": { 11 | "NeuralNetwork": "1.0.0.0" 12 | }, 13 | "runtime": { 14 | "TeachNetwork.dll": {} 15 | } 16 | }, 17 | "NeuralNetwork/1.0.0.0": { 18 | "runtime": { 19 | "NeuralNetwork.dll": { 20 | "assemblyVersion": "1.0.0.0", 21 | "fileVersion": "1.0.0.0" 22 | } 23 | } 24 | } 25 | } 26 | }, 27 | "libraries": { 28 | "TeachNetwork/1.0.0": { 29 | "type": "project", 30 | "serviceable": false, 31 | "sha512": "" 32 | }, 33 | "NeuralNetwork/1.0.0.0": { 34 | "type": "reference", 35 | "serviceable": false, 36 | "sha512": "" 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /backend/bin/Debug/netcoreapp3.1/TeachNetwork.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/bin/Debug/netcoreapp3.1/TeachNetwork.dll -------------------------------------------------------------------------------- /backend/bin/Debug/netcoreapp3.1/TeachNetwork.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/bin/Debug/netcoreapp3.1/TeachNetwork.pdb -------------------------------------------------------------------------------- /backend/data/t10k-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/data/t10k-images.idx3-ubyte -------------------------------------------------------------------------------- /backend/data/t10k-labels.idx1-ubyte: -------------------------------------------------------------------------------- 1 | '                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             -------------------------------------------------------------------------------- /backend/data/train-images.idx3-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/data/train-images.idx3-ubyte -------------------------------------------------------------------------------- /backend/data/train-labels.idx1-ubyte: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/data/train-labels.idx1-ubyte -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using System.Reflection; 4 | [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")] 5 | -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | using System; 11 | using System.Reflection; 12 | 13 | [assembly: System.Reflection.AssemblyCompanyAttribute("TeachNetwork")] 14 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] 15 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] 16 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] 17 | [assembly: System.Reflection.AssemblyProductAttribute("TeachNetwork")] 18 | [assembly: System.Reflection.AssemblyTitleAttribute("TeachNetwork")] 19 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] 20 | 21 | // Generated by the MSBuild WriteCodeFragment class. 22 | 23 | -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.AssemblyInfoInputs.cache: -------------------------------------------------------------------------------- 1 | fd9b7872717d94fcf5d49669752e6ca70957b4da 2 | -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.assets.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/obj/Debug/netcoreapp3.1/TeachNetwork.assets.cache -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.csproj.CopyComplete: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/obj/Debug/netcoreapp3.1/TeachNetwork.csproj.CopyComplete -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.csproj.CoreCompileInputs.cache: -------------------------------------------------------------------------------- 1 | cde5bd426b521a3166c49adb994cba4e90675f29 2 | -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.csprojAssemblyReference.cache 2 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.AssemblyInfoInputs.cache 3 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.AssemblyInfo.cs 4 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.csproj.CoreCompileInputs.cache 5 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\bin\Debug\netcoreapp3.1\TeachNetwork.deps.json 6 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\bin\Debug\netcoreapp3.1\TeachNetwork.dll 7 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\bin\Debug\netcoreapp3.1\TeachNetwork.pdb 8 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\bin\Debug\netcoreapp3.1\NeuralNetwork.dll 9 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.csproj.CopyComplete 10 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.dll 11 | C:\Users\valer\Desktop\GitSave\HelloReact\backend\obj\Debug\netcoreapp3.1\TeachNetwork.pdb 12 | -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.csprojAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/obj/Debug/netcoreapp3.1/TeachNetwork.csprojAssemblyReference.cache -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/obj/Debug/netcoreapp3.1/TeachNetwork.dll -------------------------------------------------------------------------------- /backend/obj/Debug/netcoreapp3.1/TeachNetwork.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/backend/obj/Debug/netcoreapp3.1/TeachNetwork.pdb -------------------------------------------------------------------------------- /backend/obj/TeachNetwork.csproj.nuget.dgspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": 1, 3 | "restore": { 4 | "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj": {} 5 | }, 6 | "projects": { 7 | "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj": { 8 | "version": "1.0.0", 9 | "restore": { 10 | "projectUniqueName": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj", 11 | "projectName": "TeachNetwork", 12 | "projectPath": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj", 13 | "packagesPath": "C:\\Users\\valer\\.nuget\\packages\\", 14 | "outputPath": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\obj\\", 15 | "projectStyle": "PackageReference", 16 | "configFilePaths": [ 17 | "C:\\Users\\valer\\AppData\\Roaming\\NuGet\\NuGet.Config", 18 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config", 19 | "C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config" 20 | ], 21 | "originalTargetFrameworks": [ 22 | "netcoreapp3.1" 23 | ], 24 | "sources": { 25 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 26 | "https://api.nuget.org/v3/index.json": {} 27 | }, 28 | "frameworks": { 29 | "netcoreapp3.1": { 30 | "projectReferences": {} 31 | } 32 | }, 33 | "warningProperties": { 34 | "warnAsError": [ 35 | "NU1605" 36 | ] 37 | } 38 | }, 39 | "frameworks": { 40 | "netcoreapp3.1": { 41 | "imports": [ 42 | "net461", 43 | "net462", 44 | "net47", 45 | "net471", 46 | "net472", 47 | "net48" 48 | ], 49 | "assetTargetFallback": true, 50 | "warn": true, 51 | "frameworkReferences": { 52 | "Microsoft.NETCore.App": { 53 | "privateAssets": "all" 54 | } 55 | }, 56 | "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.403\\RuntimeIdentifierGraph.json" 57 | } 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /backend/obj/TeachNetwork.csproj.nuget.g.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | True 5 | NuGet 6 | $(MSBuildThisFileDirectory)project.assets.json 7 | $(UserProfile)\.nuget\packages\ 8 | C:\Users\valer\.nuget\packages\ 9 | PackageReference 10 | 5.7.0 11 | 12 | 13 | 14 | 15 | 16 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 17 | 18 | -------------------------------------------------------------------------------- /backend/obj/TeachNetwork.csproj.nuget.g.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | 6 | -------------------------------------------------------------------------------- /backend/obj/project.assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "targets": { 4 | ".NETCoreApp,Version=v3.1": {} 5 | }, 6 | "libraries": {}, 7 | "projectFileDependencyGroups": { 8 | ".NETCoreApp,Version=v3.1": [] 9 | }, 10 | "packageFolders": { 11 | "C:\\Users\\valer\\.nuget\\packages\\": {} 12 | }, 13 | "project": { 14 | "version": "1.0.0", 15 | "restore": { 16 | "projectUniqueName": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj", 17 | "projectName": "TeachNetwork", 18 | "projectPath": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj", 19 | "packagesPath": "C:\\Users\\valer\\.nuget\\packages\\", 20 | "outputPath": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\obj\\", 21 | "projectStyle": "PackageReference", 22 | "configFilePaths": [ 23 | "C:\\Users\\valer\\AppData\\Roaming\\NuGet\\NuGet.Config", 24 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config", 25 | "C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config" 26 | ], 27 | "originalTargetFrameworks": [ 28 | "netcoreapp3.1" 29 | ], 30 | "sources": { 31 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, 32 | "https://api.nuget.org/v3/index.json": {} 33 | }, 34 | "frameworks": { 35 | "netcoreapp3.1": { 36 | "projectReferences": {} 37 | } 38 | }, 39 | "warningProperties": { 40 | "warnAsError": [ 41 | "NU1605" 42 | ] 43 | } 44 | }, 45 | "frameworks": { 46 | "netcoreapp3.1": { 47 | "imports": [ 48 | "net461", 49 | "net462", 50 | "net47", 51 | "net471", 52 | "net472", 53 | "net48" 54 | ], 55 | "assetTargetFallback": true, 56 | "warn": true, 57 | "frameworkReferences": { 58 | "Microsoft.NETCore.App": { 59 | "privateAssets": "all" 60 | } 61 | }, 62 | "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.403\\RuntimeIdentifierGraph.json" 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /backend/obj/project.nuget.cache: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "dgSpecHash": "0DrEers0nOyiX6rfpxPpa66EbSSdo6h7H28LVpcx2qwqmSE3vlg6QeY+hVw3cma/T7exC9K2dmAXM9Hmhlkp6g==", 4 | "success": true, 5 | "projectFilePath": "C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\backend\\TeachNetwork.csproj", 6 | "expectedPackageFiles": [], 7 | "logs": [] 8 | } -------------------------------------------------------------------------------- /frontend/.eslintcache: -------------------------------------------------------------------------------- 1 | [{"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\NeuralNetwork.js":"1","C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\App.js":"2","C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\NeuralNetworkFunctions.js":"3","C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\index.js":"4","C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\Landing.js":"5","C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\CreateNN.js":"6"},{"size":5431,"mtime":1611668664420,"results":"7","hashOfConfig":"8"},{"size":1683,"mtime":1611668723252,"results":"9","hashOfConfig":"8"},{"size":3197,"mtime":1606991910026,"results":"10","hashOfConfig":"8"},{"size":196,"mtime":1604250998972,"results":"11","hashOfConfig":"8"},{"size":1414,"mtime":1608391288124,"results":"12","hashOfConfig":"8"},{"size":4899,"mtime":1611669177227,"results":"13","hashOfConfig":"8"},{"filePath":"14","messages":"15","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"1tgqrwv",{"filePath":"16","messages":"17","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"18","messages":"19","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":"20","usedDeprecatedRules":"21"},{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"21"},{"filePath":"24","messages":"25","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"21"},{"filePath":"26","messages":"27","errorCount":0,"warningCount":4,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\NeuralNetwork.js",["28"],"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\App.js",["29","30"],"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\NeuralNetworkFunctions.js",["31"],"\r\n\r\n// #region API URLs\r\nconst urlStartNN = \"http://localhost:7071/api/StartNN\"\r\nconst urlStopNN = \"http://localhost:7071/api/StopNN\"\r\nconst urlContinueNN = \"http://localhost:7071/api/ContinueNN\"\r\nconst urlGetNNState = \"http://localhost:7071/api/GetNNState\"\r\nconst urlTestNN = \"http://localhost:7071/api/TestNN\"\r\nconst urlDeleteNN = \"http://localhost:7071/api/DeleteNN\"\r\n// #endregion\r\n\r\n\r\nexport async function startNN(NNStructObj) {\r\n\tconst { moment, learningRate, struct, terminatingError } = NNStructObj\r\n\r\n\tlet NNStruct = {\r\n\t\tMomentTemp: moment === \"\" ? 0 : moment,\r\n\t\tLearningRateTemp: learningRate === \"\" ? 0 : learningRate,\r\n\t\tNeuronsAndLayers: struct === \"\" ? \"\" : struct,\r\n\t\tTerminatingErrorProcents: terminatingError === \"\" ? 0 : terminatingError\r\n\t}\r\n\r\n\tconsole.log(NNStruct)\r\n\r\n\tconst requestOptions = {\r\n\t\tmethod: 'POST',\r\n\t\theaders: { 'Content-Type': 'application/json' },\r\n\t\tbody: JSON.stringify(NNStruct)\r\n\t}\r\n\r\n\r\n\ttry {\r\n\t\tconst response = await fetch(urlStartNN, requestOptions)\r\n\t\tif (!response.ok) throw new Error('Problem in response with message: ' + response)\r\n\r\n\t\tconst data = await response.json();\r\n\t\treturn data\r\n\t}\r\n\tcatch (err) {\r\n\t\tthrow new Error('Exited with error: ' + err)\r\n\t}\r\n}\r\n\r\nexport async function stopNN(NNId) {\r\n\tconst requestOptions = {\r\n\t\tmethod: 'POST',\r\n\t\theaders: { 'Content-Type': 'application/json' },\r\n\t\tbody: JSON.stringify(NNId)\r\n\t}\r\n\t\r\n\t\r\n\ttry {\r\n\t\tconst response = await fetch(urlStopNN, requestOptions)\r\n\t\tif (!response.ok) throw new Error('Problem in response with message: ' + response)\r\n\r\n\t\tconst data = response.json()\r\n\t\treturn data\r\n\t}\r\n\tcatch (err) {\r\n\t\tthrow new Error('Exited with error: ' + err)\r\n\t}\r\n}\r\n\r\nexport async function continueNN(NNId) {\r\n\tconst requestOptions = {\r\n\t\tmethod: 'POST',\r\n\t\theaders: {\r\n\t\t\t'Content-Type': 'application/json',\r\n\t\t\t'Accept': 'application/json'\r\n\t\t},\r\n\t\tbody: JSON.stringify(NNId)\r\n\t}\r\n\r\n\r\n\ttry {\r\n\t\tconst response = await fetch(urlContinueNN, requestOptions)\r\n\t\tif (!response.ok) throw new Error('Problem in response with message: ' + response)\r\n\r\n\t\tconst data = await response.json();\r\n\t\treturn data\r\n\t}\r\n\tcatch (err) {\r\n\t\tthrow new Error('Exited with error: ' + err)\r\n\t}\r\n}\r\n\r\nexport async function deleteNN(NNId) {\r\n\tconst requestOptions = {\r\n\t\tmethod: 'POST',\r\n\t\theaders: {\r\n\t\t\t'Content-Type': 'application/json',\r\n\t\t\t'Accept': 'application/json'\r\n\t\t},\r\n\t\tbody: JSON.stringify(NNId)\r\n\t}\r\n\r\n\r\n\ttry {\r\n\t\tconst response = await fetch(urlDeleteNN, requestOptions)\r\n\t\tif (!response.ok) throw new Error('Problem in response with message: ' + response)\r\n\r\n\t\tconst data = await response.json();\r\n\t\treturn data\r\n\t}\r\n\tcatch (err) {\r\n\t\tthrow new Error('Exited with error: ' + err)\r\n\t}\r\n}\r\n\r\nexport async function getNNState(NNId) {\r\n\tconst requestOptions = {\r\n\t\tmethod: 'POST',\r\n\t\theaders: {\r\n\t\t\t'Content-Type': 'application/json',\r\n\t\t\t'Accept': 'application/json'\r\n\t\t},\r\n\t\tbody: JSON.stringify(NNId)\r\n\t}\r\n\t\r\n\t\r\n\ttry {\r\n\t\tconst response = await fetch(urlGetNNState, requestOptions)\r\n\t\tif (!response.ok) throw new Error('Problem in response with message: ' + response)\r\n\t\t\r\n\t\tconst data = await response.json();\r\n\t\treturn data\r\n\t}\r\n\tcatch (err) {\r\n\t\tthrow new Error('Exited with error: ' + err)\r\n\t}\r\n}",["32","33"],"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\index.js",[],"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\Landing.js",[],"C:\\Users\\valer\\Desktop\\GitSave\\HelloReact\\frontend\\src\\components\\CreateNN.js",["34","35","36","37"],{"ruleId":"38","severity":1,"message":"39","line":28,"column":9,"nodeType":"40","messageId":"41","endLine":28,"endColumn":16},{"ruleId":"42","severity":1,"message":"43","line":56,"column":5,"nodeType":"40","messageId":"44","endLine":56,"endColumn":13},{"ruleId":"38","severity":1,"message":"45","line":56,"column":5,"nodeType":"40","messageId":"41","endLine":56,"endColumn":13},{"ruleId":"38","severity":1,"message":"46","line":8,"column":7,"nodeType":"40","messageId":"41","endLine":8,"endColumn":16},{"ruleId":"47","replacedBy":"48"},{"ruleId":"49","replacedBy":"50"},{"ruleId":"38","severity":1,"message":"51","line":17,"column":8,"nodeType":"40","messageId":"41","endLine":17,"endColumn":14},{"ruleId":"38","severity":1,"message":"52","line":18,"column":8,"nodeType":"40","messageId":"41","endLine":18,"endColumn":20},{"ruleId":"38","severity":1,"message":"53","line":19,"column":8,"nodeType":"40","messageId":"41","endLine":19,"endColumn":14},{"ruleId":"38","severity":1,"message":"54","line":20,"column":8,"nodeType":"40","messageId":"41","endLine":20,"endColumn":24},"no-unused-vars","'NNstate' is assigned a value but never used.","Identifier","unusedVar","no-const-assign","'NNstruct' is constant.","const","'NNstruct' is assigned a value but never used.","'urlTestNN' is assigned a value but never used.","no-native-reassign",["55"],"no-negated-in-lhs",["56"],"'moment' is assigned a value but never used.","'learningRate' is assigned a value but never used.","'layers' is assigned a value but never used.","'terminatingError' is assigned a value but never used.","no-global-assign","no-unsafe-negation"] -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.6", 7 | "@testing-library/react": "^11.2.2", 8 | "@testing-library/user-event": "^12.2.2", 9 | "react": "^17.0.1", 10 | "react-dom": "^17.0.1", 11 | "react-scripts": "4.0.1", 12 | "recharts": "^2.0.3", 13 | "web-vitals": "^0.2.4" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | }, 39 | "devDependencies": { 40 | "sass": "^1.29.0", 41 | "web-pack": "1.0.0", 42 | "webpack": "^4.44.2", 43 | "webpack-dev-middleware": "^4.0.2", 44 | "webpack-dev-server": "^3.11.0", 45 | "webpack-hot-middleware": "^2.25.0" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluesky-0412/HelloReact/595454eb6780dcde72b0dbae1827c8313451fbe7/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useRef } from "react"; 2 | //import axios from 'axios'; 3 | 4 | import NeuralNetwork from "./components/NeuralNetwork" 5 | 6 | import LandingPage from "./components/Landing" 7 | import CreatePage from "./components/CreateNN" 8 | 9 | import './scss/app.scss' 10 | 11 | 12 | export default function App() { 13 | const uniqueKey = useRef(0); 14 | const NNstruct = useRef(); 15 | 16 | 17 | const [pageEnabled, setpageEnabled] = 18 | useState({ 19 | 'LandingPage': true, 20 | 'CreatePage': false, 21 | 'NNPage': false 22 | }); 23 | 24 | function changeActiveWindow(name) { 25 | function getPages() { 26 | let tempDict = [] 27 | Object.entries(pageEnabled).forEach(([k, v]) => { 28 | tempDict[k] = v 29 | }) 30 | 31 | return tempDict 32 | } 33 | 34 | function reset() { 35 | let allPages = getPages() 36 | for (let i in allPages) { 37 | allPages[i] = false 38 | } 39 | 40 | setpageEnabled(allPages) 41 | 42 | return allPages 43 | } 44 | 45 | let allPages = reset() 46 | allPages[name] = true 47 | 48 | setpageEnabled(allPages) 49 | } 50 | 51 | const uniqueKeyGenerator = () => { 52 | return uniqueKey.current = uniqueKey.current + 1; 53 | } 54 | 55 | function changeNNStruct(NNstructLocal) { 56 | NNstruct = NNstructLocal 57 | } 58 | 59 | return ( 60 |
61 |
62 |
63 | {pageEnabled['LandingPage'] ? changeActiveWindow('CreatePage')} /> : null} 64 | {pageEnabled['CreatePage'] ? changeActiveWindow('NNPage')} getKey={uniqueKeyGenerator}/> : null} 65 | {pageEnabled['NNPage'] ? : null} 66 |
67 |
68 |
69 | ) 70 | } -------------------------------------------------------------------------------- /frontend/src/components/CreateNN.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useRef } from "react"; 2 | 3 | import styles from '../scss/components/create.module.scss' 4 | 5 | import uploadsvg from './upload.svg' 6 | 7 | export default function CreatePage({ changeNNStruct, handlePageTransition, getKey }) { 8 | 9 | function handleSubmitClick(){ 10 | 11 | 12 | 13 | handlePageTransition(); 14 | } 15 | 16 | 17 | const moment = useRef(0); 18 | const learningRate = useRef(0); 19 | const layers = useRef([]); 20 | const terminatingError = useRef(0); 21 | 22 | 23 | return ( 24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 |
32 | { /* const moment = useRef(''); */} 33 | 34 |
35 | 36 | 37 | 38 | 39 | 40 |

LET'S GO!

41 |
42 |
43 |
44 |
45 | ) 46 | } 47 | 48 | function SetupInput({ name, text, placeholder, width, maxLimit = 5 }) { 49 | return ( 50 |
51 |

{text}

52 | 53 |
54 | ) 55 | } 56 | 57 | function LayersInput({ getKey }) { 58 | function SetupInputLocal({ name, text, placeholder }) { 59 | return ( 60 |
61 |
62 |

{text}

63 |
64 | 65 |
66 | ) 67 | } 68 | 69 | function HiddenLayer({ data_key, placeholder, handleAddingLayer, handleDeletingLayer 70 | }) { 71 | function HiddenLayerButtons() { 72 | const [isVisible, setVisibility] = useState(true) 73 | 74 | return ( 75 |
setVisibility(false)} onMouseLeave={() => setVisibility(true)} className={styles.hiddenLayer_buttons}> 76 |
handleAddingLayer(data_key)} hidden={isVisible}>
77 |
handleDeletingLayer(data_key)} hidden={isVisible}>
78 |
79 | ) 80 | } 81 | 82 | return ( 83 |
84 | 85 | 86 | 87 |
88 | ) 89 | } 90 | 91 | function createHiddenLayerElement() { 92 | let newKey = getKey() 93 | 94 | let element = 95 |
96 | 97 | 98 | 99 | return { 100 | key: newKey, 101 | value: element 102 | } 103 | } 104 | 105 | 106 | let hiddenLayerCount = 1; 107 | 108 | const [hiddenLayers, setHiddenLayers] = useState([createHiddenLayerElement()]) 109 | 110 | function addLayer(key) { 111 | if (hiddenLayerCount > 6) 112 | return 113 | 114 | let hiddenLayersTemp = hiddenLayers 115 | let elementIndex = hiddenLayersTemp.findIndex(layer => { 116 | return layer.key === key 117 | }) 118 | 119 | hiddenLayersTemp.splice(elementIndex + 1, 0, createHiddenLayerElement()) 120 | ++hiddenLayerCount 121 | 122 | setHiddenLayers([...hiddenLayersTemp]) 123 | } 124 | 125 | function deleteLayer(key) { 126 | if (hiddenLayerCount === 1) 127 | return 128 | 129 | let hiddenLayersTemp = hiddenLayers 130 | 131 | hiddenLayersTemp = hiddenLayersTemp.filter(layer => { 132 | return layer.key !== key 133 | }) 134 | 135 | --hiddenLayerCount 136 | 137 | setHiddenLayers([...hiddenLayersTemp]) 138 | 139 | console.log(hiddenLayersTemp) 140 | } 141 | 142 | useEffect(() => { 143 | console.log(hiddenLayers) 144 | }, [hiddenLayers]) 145 | 146 | 147 | return ( 148 |
149 |

Layers

150 | 151 |
152 | {hiddenLayers.map(element => element.value)} 153 |
154 | 155 |
156 | ) 157 | } 158 | 159 | function TrainingInput() { 160 | const [fileName, setFileName] = useState('') 161 | 162 | return ( 163 |
164 | 172 | setFileName(e.target.files[0].name)} /> 173 |
174 | ) 175 | } -------------------------------------------------------------------------------- /frontend/src/components/Landing.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import styles from '../scss/components/landing.module.scss' 4 | 5 | export default function LandingPage({ handlePageTransition }) { 6 | return ( 7 |
8 |
9 |
10 |
11 |

CREATE

12 |

NEURAL NETWORK

13 |
14 |
15 |
16 |
17 | Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nesciunt consectetur inventore velit repellat dicta! Suscipit placeat cumque odit hic numquam officiis enim inventore commodi, dolorum minima aliquam dolore itaque maiores. Officia molestiae, libero magnam quasi eveniet voluptas incidunt voluptates error nesciunt molestias suscipit est iste sint consequatur porro, minima culpa? Inventore possimus dolore nostrum nisi mollitia ab laudantium sapiente repudiandae soluta facilis sit aliquam distinctio amet libero corporis, cum voluptate. Deleniti illum non ipsam reiciendis natus rerum tempore minima, impedit quis earum neque sit obcaecati ratione atque quam perspiciatis ab id molestias accusantium soluta libero. Doloribus fugit illum ullam officia. 18 | 19 |
20 | 21 |

All rights reserved

22 |
23 | ) 24 | } -------------------------------------------------------------------------------- /frontend/src/components/NeuralNetwork.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useRef } from "react"; 2 | 3 | import * as NNApi from "./NeuralNetworkFunctions" 4 | 5 | import { LineChart, Line, CartesianGrid, XAxis, YAxis, Tooltip } from 'recharts'; 6 | 7 | import styles from '../scss/components/neuralnetwork.module.scss' 8 | import uploadsvg from './upload.svg' 9 | import startsvg from './start.svg' 10 | import stopsvg from './stop.svg' 11 | 12 | 13 | export default function NeuralNetwork() { 14 | 15 | //#region Variables 16 | const NNId = useRef(''); 17 | const interval = useRef(''); 18 | 19 | const moment = useRef(0.5); 20 | const learningRate = useRef(0.1); 21 | const struct = useRef('784 26+ 16 10'); 22 | const terminatingError = useRef(0.00011); 23 | 24 | const [startDisabled, setStartDisabled] = useState(false); 25 | const [stopDisabled, setStopDisabled] = useState(false); 26 | const [continueDisabled, setContinueDisabled] = useState(true); 27 | const [deleteDisabled, setDeleteDisabled] = useState(false); 28 | const [NNstate, setNNstate] = useState(null); 29 | //#endregion 30 | 31 | 32 | async function startNN() { 33 | try { 34 | const data = await NNApi.startNN({ moment: moment.current.value, learningRate: learningRate.current.value, struct: struct.current.value, terminatingError: terminatingError.current.value }) 35 | 36 | NNId.current = data 37 | 38 | getNNState() 39 | interval.current = setInterval(() => { 40 | getNNState() 41 | }, 5000) 42 | 43 | setStartDisabled(true) 44 | setContinueDisabled(true) 45 | setStopDisabled(false) 46 | setDeleteDisabled(false) 47 | 48 | console.log('NN created with ID ' + data) 49 | } 50 | catch (err) { 51 | console.log(err) 52 | } 53 | } 54 | 55 | async function stopNN() { 56 | try { 57 | const response = await NNApi.stopNN(NNId.current) 58 | 59 | clearInterval(interval.current) 60 | 61 | setStopDisabled(true) 62 | setContinueDisabled(false) 63 | 64 | console.log('process ' + NNId.current + ' stopped with code ' + response) 65 | } 66 | catch (err) { 67 | console.log(err) 68 | } 69 | } 70 | 71 | async function continueNN() { 72 | try { 73 | const response = await NNApi.continueNN(NNId.current) 74 | 75 | getNNState() 76 | interval.current = setInterval(() => { 77 | getNNState() 78 | }, 5000) 79 | 80 | setContinueDisabled(true) 81 | setStopDisabled(false) 82 | 83 | console.log('process ' + NNId.current + ' continued with code ' + response) 84 | } 85 | catch (err) { 86 | console.log(err) 87 | } 88 | } 89 | 90 | async function deleteNN() { 91 | try { 92 | const response = await NNApi.deleteNN(NNId.current) 93 | 94 | const state = { trainingSets: 0, iteration: 0, errorSum: 0, sw: "" } 95 | 96 | clearInterval(interval.current) 97 | 98 | setStopDisabled(true) 99 | setDeleteDisabled(true) 100 | setStartDisabled(false) 101 | setContinueDisabled(true) 102 | setNNstate(state) 103 | 104 | console.log('process ' + NNId.current + ' deleted with code ' + response) 105 | } 106 | catch (err) { 107 | console.log(err) 108 | } 109 | } 110 | 111 | async function getNNState() { 112 | const data = await NNApi.getNNState(NNId.current) 113 | 114 | setNNstate(data) 115 | 116 | console.log(data) 117 | } 118 | 119 | const data = [ 120 | { time: '0:00', mistake: 79 }, 121 | { time: '0:05', mistake: 77 }, 122 | { time: '0:10', mistake: 70 }, 123 | { time: '0:15', mistake: 64 }, 124 | { time: '0:20', mistake: 67 }, 125 | { time: '0:25', mistake: 64 }, 126 | { time: '0:30', mistake: 64 }, 127 | { time: '0:35', mistake: 62 }, 128 | { time: '0:40', mistake: 60 }, 129 | ] 130 | 131 | 132 | return ( 133 |
134 |
135 |
136 |

My Neural Network

137 |
138 |
139 |
140 |
141 |

142 | 143 |

144 |

145 | 146 |

147 |

148 | 149 |

150 |

151 | 152 |

153 |
154 | 155 |
156 |
157 | 163 | 164 | 165 | 166 | 167 | 168 | 169 |
170 |
171 |
172 |
173 | Start NeuralNetwork 174 | 175 |
176 | Stop NeuralNetwork 177 | 178 |
179 |

Download

Download NeuralNetwork
180 |
181 |
182 |
183 |
184 |
185 |
186 | ) 187 | } -------------------------------------------------------------------------------- /frontend/src/components/NeuralNetworkFunctions.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | // #region API URLs 4 | const urlStartNN = "http://localhost:7071/api/StartNN" 5 | const urlStopNN = "http://localhost:7071/api/StopNN" 6 | const urlContinueNN = "http://localhost:7071/api/ContinueNN" 7 | const urlGetNNState = "http://localhost:7071/api/GetNNState" 8 | const urlTestNN = "http://localhost:7071/api/TestNN" 9 | const urlDeleteNN = "http://localhost:7071/api/DeleteNN" 10 | // #endregion 11 | 12 | 13 | export async function startNN(NNStructObj) { 14 | const { moment, learningRate, struct, terminatingError } = NNStructObj 15 | 16 | let NNStruct = { 17 | MomentTemp: moment === "" ? 0 : moment, 18 | LearningRateTemp: learningRate === "" ? 0 : learningRate, 19 | NeuronsAndLayers: struct === "" ? "" : struct, 20 | TerminatingErrorProcents: terminatingError === "" ? 0 : terminatingError 21 | } 22 | 23 | console.log(NNStruct) 24 | 25 | const requestOptions = { 26 | method: 'POST', 27 | headers: { 'Content-Type': 'application/json' }, 28 | body: JSON.stringify(NNStruct) 29 | } 30 | 31 | 32 | try { 33 | const response = await fetch(urlStartNN, requestOptions) 34 | if (!response.ok) throw new Error('Problem in response with message: ' + response) 35 | 36 | const data = await response.json(); 37 | return data 38 | } 39 | catch (err) { 40 | throw new Error('Exited with error: ' + err) 41 | } 42 | } 43 | 44 | export async function stopNN(NNId) { 45 | const requestOptions = { 46 | method: 'POST', 47 | headers: { 'Content-Type': 'application/json' }, 48 | body: JSON.stringify(NNId) 49 | } 50 | 51 | 52 | try { 53 | const response = await fetch(urlStopNN, requestOptions) 54 | if (!response.ok) throw new Error('Problem in response with message: ' + response) 55 | 56 | const data = response.json() 57 | return data 58 | } 59 | catch (err) { 60 | throw new Error('Exited with error: ' + err) 61 | } 62 | } 63 | 64 | export async function continueNN(NNId) { 65 | const requestOptions = { 66 | method: 'POST', 67 | headers: { 68 | 'Content-Type': 'application/json', 69 | 'Accept': 'application/json' 70 | }, 71 | body: JSON.stringify(NNId) 72 | } 73 | 74 | 75 | try { 76 | const response = await fetch(urlContinueNN, requestOptions) 77 | if (!response.ok) throw new Error('Problem in response with message: ' + response) 78 | 79 | const data = await response.json(); 80 | return data 81 | } 82 | catch (err) { 83 | throw new Error('Exited with error: ' + err) 84 | } 85 | } 86 | 87 | export async function deleteNN(NNId) { 88 | const requestOptions = { 89 | method: 'POST', 90 | headers: { 91 | 'Content-Type': 'application/json', 92 | 'Accept': 'application/json' 93 | }, 94 | body: JSON.stringify(NNId) 95 | } 96 | 97 | 98 | try { 99 | const response = await fetch(urlDeleteNN, requestOptions) 100 | if (!response.ok) throw new Error('Problem in response with message: ' + response) 101 | 102 | const data = await response.json(); 103 | return data 104 | } 105 | catch (err) { 106 | throw new Error('Exited with error: ' + err) 107 | } 108 | } 109 | 110 | export async function getNNState(NNId) { 111 | const requestOptions = { 112 | method: 'POST', 113 | headers: { 114 | 'Content-Type': 'application/json', 115 | 'Accept': 'application/json' 116 | }, 117 | body: JSON.stringify(NNId) 118 | } 119 | 120 | 121 | try { 122 | const response = await fetch(urlGetNNState, requestOptions) 123 | if (!response.ok) throw new Error('Problem in response with message: ' + response) 124 | 125 | const data = await response.json(); 126 | return data 127 | } 128 | catch (err) { 129 | throw new Error('Exited with error: ' + err) 130 | } 131 | } -------------------------------------------------------------------------------- /frontend/src/components/start.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend/src/components/stop.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /frontend/src/components/upload.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById('root') 10 | ); -------------------------------------------------------------------------------- /frontend/src/scss/app.scss: -------------------------------------------------------------------------------- 1 | @import url(//db.onlinewebfonts.com/c/f2ecc6ef740fcf60de095b0b087dd58d?family=OCR+A+Extended); 2 | 3 | body { 4 | font-family: "OCR A Extended", sans-serif; 5 | 6 | background-color: #0085d4; 7 | color: white; 8 | 9 | font-size: 28px; 10 | 11 | margin: 0; 12 | padding: 0; 13 | } 14 | 15 | ::selection { 16 | background-color: rgba(163, 4, 4, 0.753); 17 | color: white; 18 | } 19 | 20 | * { 21 | font-size: 14px; 22 | text-align: center; 23 | } 24 | 25 | .container { 26 | margin: 0; 27 | padding: 0; 28 | } 29 | 30 | p { 31 | margin: 0; 32 | } -------------------------------------------------------------------------------- /frontend/src/scss/components/create.module.scss: -------------------------------------------------------------------------------- 1 | @import "general.scss"; 2 | 3 | .container { 4 | input[type="text"] { 5 | border-radius: 5px; 6 | border: #707070 solid 1px; 7 | background-color: #ececec; 8 | 9 | width: 52px; 10 | height: 30px; 11 | 12 | font-size: 18px; 13 | } 14 | input[type="text"]:hover { 15 | border: #0085d4 solid 1px; 16 | } 17 | input[type="text"]:focus { 18 | outline: 0; 19 | border: #026199 solid 1px; 20 | } 21 | input[type="text"]::placeholder { 22 | font-size: 15px; 23 | opacity: 0.8; 24 | } 25 | 26 | .header { 27 | height: 70px; 28 | width: 100%; 29 | 30 | display: flex; 31 | flex-direction: row; 32 | 33 | align-items: center; 34 | justify-content: center; 35 | 36 | input { 37 | width: 35%; 38 | height: 45%; 39 | 40 | border-radius: 50px; 41 | border: none; 42 | 43 | padding: 5px 30px; 44 | 45 | font-size: 28px; 46 | text-align: left; 47 | 48 | color: #707070; 49 | &:focus { 50 | outline: none; 51 | } 52 | &::placeholder { 53 | font-size: 20px; 54 | } 55 | } 56 | } 57 | 58 | .main { 59 | width: 100%; 60 | height: calc(100% - 70px); 61 | 62 | display: flex; 63 | flex-direction: column; 64 | 65 | align-items: center; 66 | justify-content: center; 67 | 68 | background-color: white; 69 | 70 | * { 71 | color: #707070; 72 | 73 | font-weight: 600; 74 | font-size: 20px; 75 | } 76 | } 77 | 78 | .setup_container { 79 | height: fit-content; 80 | width: fit-content; 81 | 82 | display: flex; 83 | flex-direction: column; 84 | 85 | align-items: center; 86 | justify-content: center; 87 | } 88 | 89 | .row { 90 | position: relative; 91 | 92 | display: flex; 93 | flex-direction: row; 94 | 95 | align-items: center; 96 | 97 | margin-bottom: 50px; 98 | } 99 | 100 | .imputnumber_container { 101 | position: relative; 102 | 103 | display: flex; 104 | align-items: center; 105 | 106 | margin: 0 50px; 107 | 108 | > p { 109 | margin-right: 20px; 110 | } 111 | 112 | .absolute { 113 | position: absolute; 114 | top: -20px; 115 | width: 100%; 116 | 117 | p { 118 | margin: auto; 119 | font-size: 16px; 120 | } 121 | } 122 | } 123 | 124 | .layers_container { 125 | .hiddenlayers_container { 126 | display: flex; 127 | flex-direction: row; 128 | position: relative; 129 | 130 | input[type="text"] { 131 | position: relative; 132 | z-index: 2; 133 | } 134 | 135 | .hiddenlayer_element { 136 | position: relative; 137 | margin: 0 10px; 138 | 139 | .hiddenLayer_buttons { 140 | position: absolute; 141 | top: calc(-100% - 5px); 142 | 143 | height: calc(100% + 75px); 144 | width: 100%; 145 | 146 | display: flex; 147 | flex-direction: column; 148 | 149 | align-items: center; 150 | justify-content: space-between; 151 | 152 | .plus { 153 | width: 30px; 154 | height: 30px; 155 | background-color: #dbdbdb; 156 | border-radius: 100%; 157 | position: relative; 158 | 159 | cursor: pointer; 160 | 161 | &::before { 162 | content: "+"; 163 | font-size: 30px; 164 | display: block; 165 | position: absolute; 166 | left: 6px; 167 | bottom: 0px; 168 | } 169 | } 170 | .minus { 171 | width: 30px; 172 | height: 30px; 173 | background-color: #dbdbdb; 174 | border-radius: 100%; 175 | position: relative; 176 | 177 | cursor: pointer; 178 | 179 | &::before { 180 | content: "-"; 181 | font-size: 30px; 182 | display: block; 183 | position: absolute; 184 | left: 6px; 185 | bottom: 0px; 186 | } 187 | } 188 | } 189 | } 190 | } 191 | } 192 | 193 | .inputfile_container { 194 | margin: 50px 0; 195 | 196 | .inputfile { 197 | margin: 20px 0 0 0; 198 | 199 | display: flex; 200 | align-items: center; 201 | flex-direction: row-reverse; 202 | 203 | cursor: pointer; 204 | 205 | .upload_img { 206 | border-radius: 100%; 207 | 208 | background-color: #0085d4; 209 | width: 60px; 210 | height: 60px; 211 | 212 | display: flex; 213 | align-items: center; 214 | justify-content: center; 215 | 216 | margin-left: 30px; 217 | } 218 | } 219 | } 220 | } 221 | 222 | .bluebutton_palette { 223 | margin-top: 50px; 224 | } 225 | -------------------------------------------------------------------------------- /frontend/src/scss/components/general.scss: -------------------------------------------------------------------------------- 1 | .button { 2 | border-radius: 50px; 3 | 4 | display: flex; 5 | flex-direction: column; 6 | background: white; 7 | 8 | align-items: center; 9 | justify-content: center; 10 | 11 | user-select: none; 12 | 13 | cursor: pointer; 14 | 15 | transition: 0.25s ease; 16 | 17 | * { 18 | margin: 0; 19 | 20 | color: blue; 21 | font-weight: 900; 22 | 23 | text-align: center; 24 | } 25 | } 26 | .button:hover { 27 | background: rgb(216, 216, 216); 28 | transform: scale(1.02); 29 | } 30 | .button:active{ 31 | transform: scale(0.98); 32 | } 33 | 34 | .fullpage_container { 35 | width: 100vw; 36 | max-width: 100%; 37 | height: 100vh; 38 | max-height: 100%; 39 | 40 | margin: 0; 41 | padding: 0; 42 | } 43 | 44 | .bluebutton_palette { 45 | width: 70%; 46 | height: 50px; 47 | background-color: #0085d4; 48 | 49 | color: white; 50 | 51 | * { 52 | color: white; 53 | } 54 | } 55 | .bluebutton_palette:hover { 56 | background: #006caa; 57 | } -------------------------------------------------------------------------------- /frontend/src/scss/components/landing.module.scss: -------------------------------------------------------------------------------- 1 | @import "general.scss"; 2 | 3 | .button_create { 4 | height: 100px; 5 | width: calc(40% + 20px); 6 | 7 | .create { 8 | margin-top: 5px; 9 | height: 50%; 10 | 11 | font-size: 46px; 12 | } 13 | 14 | .neuralnetwork { 15 | margin-top: 5px; 16 | 17 | letter-spacing: 3px; 18 | } 19 | } 20 | 21 | .container_text { 22 | font-size: 28px; 23 | 24 | width: 80%; 25 | margin: 0 auto 100px auto; 26 | 27 | text-align: left; 28 | } 29 | 30 | .flex_container { 31 | width: 100%; 32 | height: 100%; 33 | 34 | display: flex; 35 | flex-direction: column; 36 | 37 | align-items: center; 38 | justify-content: center; 39 | } 40 | -------------------------------------------------------------------------------- /frontend/src/scss/components/neuralnetwork.module.scss: -------------------------------------------------------------------------------- 1 | @import "general.scss"; 2 | 3 | .fullpage_container { 4 | display: flex; 5 | flex-direction: column; 6 | } 7 | 8 | .grid { 9 | display: grid; 10 | grid-template-columns: 1fr 600px; 11 | 12 | width: 100%; 13 | 14 | align-items: center; 15 | justify-items: center; 16 | 17 | * { 18 | text-align: start; 19 | } 20 | } 21 | 22 | .column { 23 | display: flex; 24 | flex-direction: column; 25 | 26 | margin-left: 5%; 27 | 28 | p { 29 | * { 30 | font-size: 20px; 31 | line-height: 40px; 32 | } 33 | } 34 | } 35 | 36 | .name_container { 37 | height: 7.5%; 38 | 39 | display: flex; 40 | align-items: center; 41 | justify-content: center; 42 | > p { 43 | font-size: 26px; 44 | font-weight: 600; 45 | } 46 | } 47 | 48 | .center_container { 49 | display: flex; 50 | flex-direction: row; 51 | align-items: center; 52 | 53 | background-color: white; 54 | color: #707070; 55 | 56 | height: 85%; 57 | width: 100%; 58 | } 59 | 60 | .button_container{ 61 | display: flex; 62 | flex-direction: row; 63 | 64 | justify-content: space-between; 65 | width: 100%; 66 | } 67 | 68 | .svgbuttons{ 69 | display: flex; 70 | flex-direction: row; 71 | } 72 | .svg_container { 73 | border-radius: 100%; 74 | 75 | background-color: #0085d4; 76 | width: 60px; 77 | height: 60px; 78 | 79 | margin-right: 10px; 80 | 81 | display: flex; 82 | align-items: center; 83 | justify-content: center; 84 | 85 | * { 86 | height: 30px; 87 | width: 30px; 88 | } 89 | } 90 | 91 | .disabled { 92 | opacity: 0.5; 93 | } 94 | .enabled { 95 | cursor: pointer; 96 | } 97 | 98 | .bluebutton_palette { 99 | display: flex; 100 | flex-direction: row; 101 | 102 | height: 60px; 103 | width: 170px; 104 | padding: 0 20px; 105 | 106 | justify-content: space-between; 107 | 108 | * { 109 | font-size: 20px; 110 | } 111 | } 112 | --------------------------------------------------------------------------------