forked from kspub-github-book/pages-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.py
32 lines (24 loc) · 769 Bytes
/
export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
import tensorflow as tf
from tensorflow import keras
import tensorflowjs as tfjs
def create_model():
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
model = create_model()
model.load_weights('model')
test_input = np.zeros(28 * 28).reshape((1, 28, 28))
predictions = model.predict(test_input)
print()
print('Predictions for zero input')
print(predictions[0])
tfjs.converters.save_keras_model(model, "model")
print()
print('Model was exported.')