feat: closes #18 added the code to generate models and other

This commit is contained in:
2023-09-26 20:15:28 +01:00
parent 04de6ad574
commit bad53a13e6
22 changed files with 651 additions and 70 deletions

View File

@@ -252,8 +252,39 @@
{{ end }}
{{ define "train-model-card" }}
<form hx-delete="/models/train" hx-headers='{"REQUEST-TYPE": "html"}' hx-swap="outerHTML" {{ if .Error }} class="submitted" {{end}} >
tain menu
<form hx-post="/models/train" hx-headers='{"REQUEST-TYPE": "html"}' hx-swap="outerHTML" {{ if .Error }} class="submitted" {{end}} >
{{ if .HasData }}
{{/* TODO expading mode */}}
<input type="hidden" value="{{ .Model.Id }}" name="id" />
<fieldset>
<legend>
Model Type
</legend>
<div class="input-radial">
<input id="model_type_simple" value="simple" name="model_type" type="radio" checked />
<label for="model_type_simple">Simple</label>
</div>
</fieldset>
{{/* TODO allow more models to be created */}}
<fieldset>
<label for="number_of_models">Number of Models</label>
<input id="number_of_models" type="number" name="number_of_models" value="1" />
</fieldset>
{{/* TODO to Change the acc */}}
<fieldset>
<label for="accuracy">Target accuracy</label>
<input id="accuracy" type="number" name="accuracy" value="95" />
</fieldset>
{{/* TODO allow to chose the base of the model */}}
{{/* TODO allow to change the shape of the model */}}
<button>
Train
</button>
{{ else }}
<h2>
Please provide data to the model first
</h2>
{{ end }}
</form>
{{ end }}
@@ -313,6 +344,29 @@
{{/* TODO improve this */}}
Processing zip file...
</div>
{{/* FAILED TO Prepare for training */}}
{{ else if (eq .Model.Status -3)}}
{{ template "base-model-card" . }}
<form hx-delete="/models/train/reset" hx-headers='{"REQUEST-TYPE": "html"}' hx-swap="outerHTML">
Failed Prepare for training.<br/>
<div class="spacer" ></div>
<input type="hidden" name="id" value="{{ .Model.Id }}" />
<button class="danger">
Try Again
</button>
</form>
{{ template "delete-model-card" . }}
{{ else if (eq .Model.Status 4)}}
{{ template "base-model-card" . }}
<div class="card" hx-get="/models/edit?id={{ .Model.Id }}" hx-headers='{"REQUEST-TYPE": "htmlfull"}' hx-push="true" hx-swap="outerHTML" hx-target=".app" hx-trigger="load delay:2s" >
{{/* TODO improve this */}}
Training the model...<br/>
{{/* TODO Add progress status on definitions */}}
{{/* TODO Add aility to stop training */}}
</div>
<button hx-post="/models/train/test?id={{ .Model.Id }}" hx-headers='{"REQUEST-TYPE": "html"}'>
Test
</button>
{{ else }}
<h1>
Unknown Status of the model.

View File

@@ -40,7 +40,7 @@
</table>
{{else}}
<h2 class="text-center">
You don't have any model
You don't have any models
</h2>
<div class="text-center">
<a class="button padded" hx-get="/models/add" hx-headers='{"REQUEST-TYPE": "htmlfull"}' hx-push-url="true" hx-swap="outerHTML" hx-target=".app">

View File

@@ -0,0 +1,47 @@
import tensorflow as tf
import random
from tensorflow import keras
from keras import layers, losses, optimizers
seed = random.randint(0, 100000000)
batch_size = 100
dataset = keras.utils.image_dataset_from_directory(
"{{ .DataDir }}",
color_mode="rgb",
validation_split=0.2,
label_mode='int',
seed=seed,
subset="training",
image_size=({{ .Size }}),
batch_size=batch_size)
dataset_validation = keras.utils.image_dataset_from_directory(
"{{ .DataDir }}",
color_mode="rgb",
validation_split=0.2,
label_mode='int',
seed=seed,
subset="validation",
image_size=({{ .Size }}),
batch_size=batch_size)
model = keras.Sequential([
{{- range .Layers }}
{{- if eq .LayerType 1}}
layers.Rescaling(1./255),
{{- else if eq .LayerType 2 }}
layers.Dense({{ .Shape }}, activation="relu"),
{{- else if eq .LayerType 3}}
layers.Flatten(),
{{- else }}
ERROR
{{- end }}
{{- end }}
])
model.compile(loss=losses.SparseCategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adam())
his = model.fit(dataset, validation_data= dataset_validation, epochs=100)

View File

@@ -176,7 +176,8 @@ form {
box-shadow: none;
}
form label {
form label,
form fieldset legend {
display: block;
padding-bottom: 5px;
font-size: 1.2rem;
@@ -224,6 +225,16 @@ form button {
padding: 10px;
}
form .input-radial input[type="radio"] {
width: auto;
box-shadow: none;
}
form .input-radial label {
display: inline;
font-size: 1rem;
}
/* Upload files */
form fieldset.file-upload input[type="file"] {