Commit
·
b56e27a
1
Parent(s):
46f76ea
Pretrained model
Browse files- .gitattributes +1 -0
- app.py +27 -31
- requirements.txt +3 -3
- training.py +18 -0
- weights/checkpoint +2 -0
- weights/weights.data-00000-of-00001 +3 -0
- weights/weights.index +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
weights/weights.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,32 +1,28 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from PIL import Image
|
| 4 |
-
from tensorflow import keras
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
model.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
gr.Interface(fn=classify,
|
| 29 |
-
inputs=input_sketchpad,
|
| 30 |
-
outputs="label",
|
| 31 |
-
allow_flagging=False,
|
| 32 |
theme=gr.themes.Soft()).launch()
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from tensorflow import keras
|
| 5 |
+
|
| 6 |
+
model = keras.models.Sequential([
|
| 7 |
+
keras.layers.Flatten(input_shape=(28, 28)), # Diese Schicht nimmt unser 2D-Bild und verwandelt es in ein 1D-Array
|
| 8 |
+
keras.layers.Dense(512, activation='relu'), # Als Nächstes kommen zwei Schichten mit 512 künstlichen Neuronen. Als Funktion wählen wir 'relu' f(x) = max(0,x)
|
| 9 |
+
keras.layers.Dense(512, activation='relu'),
|
| 10 |
+
keras.layers.Dense(10, activation='softmax') # Die letzte Schicht besteht aus 10 Neuronen, die für unsere 10 Zahlen stehen. Die 'softmax' Funktion wandelt die Ergebnisse der vorherigen Schicht in Wahrscheinlichkeiten
|
| 11 |
+
])
|
| 12 |
+
|
| 13 |
+
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
|
| 14 |
+
|
| 15 |
+
model.load_weights('./weights/weights')
|
| 16 |
+
|
| 17 |
+
def classify(input):
|
| 18 |
+
image = np.expand_dims(np.array(Image.fromarray(input['layers'][0]).resize((28,28),resample=Image.Resampling.BILINEAR), dtype=int), axis=0)#[:,:,0]
|
| 19 |
+
prediction = model.predict(image).tolist()[0]
|
| 20 |
+
return {str(i): float(prediction[i]) for i in range(10)}
|
| 21 |
+
|
| 22 |
+
input_sketchpad = gr.Paint(image_mode="L", brush=gr.components.image_editor.Brush(default_color="rgb(156, 104, 200)"))
|
| 23 |
+
|
| 24 |
+
gr.Interface(fn=classify,
|
| 25 |
+
inputs=input_sketchpad,
|
| 26 |
+
outputs="label",
|
| 27 |
+
allow_flagging=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
theme=gr.themes.Soft()).launch()
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
PIL
|
| 2 |
-
numpy
|
| 3 |
-
gradio
|
| 4 |
tensorflow
|
|
|
|
| 1 |
+
PIL
|
| 2 |
+
numpy
|
| 3 |
+
gradio
|
| 4 |
tensorflow
|
training.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tensorflow import keras
|
| 2 |
+
|
| 3 |
+
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
|
| 4 |
+
|
| 5 |
+
x_train = x_train / 255.0
|
| 6 |
+
x_test = x_test / 255.0
|
| 7 |
+
|
| 8 |
+
model = keras.models.Sequential([
|
| 9 |
+
keras.layers.Flatten(input_shape=(28, 28)), # Diese Schicht nimmt unser 2D-Bild und verwandelt es in ein 1D-Array
|
| 10 |
+
keras.layers.Dense(512, activation='relu'), # Als Nächstes kommen zwei Schichten mit 512 künstlichen Neuronen. Als Funktion wählen wir 'relu' f(x) = max(0,x)
|
| 11 |
+
keras.layers.Dense(512, activation='relu'),
|
| 12 |
+
keras.layers.Dense(10, activation='softmax') # Die letzte Schicht besteht aus 10 Neuronen, die für unsere 10 Zahlen stehen. Die 'softmax' Funktion wandelt die Ergebnisse der vorherigen Schicht in Wahrscheinlichkeiten
|
| 13 |
+
])
|
| 14 |
+
|
| 15 |
+
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
|
| 16 |
+
model.fit(x_train, y_train, validation_data=(x_test, y_test), epochs=6)
|
| 17 |
+
|
| 18 |
+
model.save_weights('./weights/weights')
|
weights/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "weights"
|
| 2 |
+
all_model_checkpoint_paths: "weights"
|
weights/weights.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c830f3592c537868e20d93013f72906daa1c770ede682ab1ba938e12f18dcd33
|
| 3 |
+
size 8039013
|
weights/weights.index
ADDED
|
Binary file (1.35 kB). View file
|
|
|