aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/Controllers/ModelController.cs2
-rw-r--r--backend/api/api/Models/Model.cs2
-rw-r--r--backend/api/api/Services/IModelService.cs1
-rw-r--r--backend/api/api/Services/ModelService.cs12
4 files changed, 16 insertions, 1 deletions
diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs
index 1d03d924..a4fa99c4 100644
--- a/backend/api/api/Controllers/ModelController.cs
+++ b/backend/api/api/Controllers/ModelController.cs
@@ -86,6 +86,8 @@ namespace api.Controllers
[Authorize(Roles = "User")]
public ActionResult<Model> Post([FromBody] Model model)
{
+ if (_modelService.CheckHyperparameters(model.inputNeurons, model.hiddenLayerNeurons, model.hiddenLayers, model.outputNeurons) == false)
+ return BadRequest("Bad parameters!");
var existingModel = _modelService.GetOneModel(model.username, model.name);
if (existingModel != null)
diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs
index dfc4336a..52516cd9 100644
--- a/backend/api/api/Models/Model.cs
+++ b/backend/api/api/Models/Model.cs
@@ -36,6 +36,8 @@ namespace api.Models
public int hiddenLayerNeurons { get; set; }
public int hiddenLayers { get; set; }
public int batchSize { get; set; }
+ // na izlazu je moguce da bude vise neurona (klasifikacioni problem sa vise od 2 klase)
+ public int outputNeurons { get; set; }
public string inputLayerActivationFunction { get; set; }
public string hiddenLayerActivationFunction { get; set; }
public string outputLayerActivationFunction { get; set; }
diff --git a/backend/api/api/Services/IModelService.cs b/backend/api/api/Services/IModelService.cs
index c1931ffa..887be4ae 100644
--- a/backend/api/api/Services/IModelService.cs
+++ b/backend/api/api/Services/IModelService.cs
@@ -11,6 +11,7 @@ namespace api.Services
Model Create(Model model);
void Update(string username, string name, Model model);
void Delete(string username, string name);
+ bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons);
}
}
diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs
index 2ba3c54d..3d5c3b3e 100644
--- a/backend/api/api/Services/ModelService.cs
+++ b/backend/api/api/Services/ModelService.cs
@@ -7,7 +7,6 @@ namespace api.Services
{
public class ModelService : IModelService
{
-
private readonly IMongoCollection<Model> _model;
public ModelService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
@@ -46,6 +45,17 @@ namespace api.Services
{
_model.ReplaceOne(model => model.username == username && model.name == name, model);
}
+ //
+ public bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons)
+ {
+ if (hiddenLayers <= 0 || hiddenLayerNeurons <= 0)
+ return false;
+ if (hiddenLayers > inputNeurons)
+ return false;
+ if (hiddenLayerNeurons <= 2 * inputNeurons || hiddenLayerNeurons <= (2 / 3) * inputNeurons + outputNeurons || (hiddenLayerNeurons <= Math.Max(inputNeurons, outputNeurons) && hiddenLayerNeurons >= Math.Min(inputNeurons, outputNeurons)))
+ return true;
+ return false;
+ }
}
}