-
Notifications
You must be signed in to change notification settings - Fork 26
/
fashion-mnist-fairing.py
61 lines (44 loc) · 1.73 KB
/
fashion-mnist-fairing.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import tensorflow as tf
import os
class MyFashionMnist(object):
def train(self):
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
model.summary()
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10)
model.evaluate(x_test, y_test, verbose=2)
if __name__ == '__main__':
if os.getenv('FAIRING_RUNTIME', None) is None:
from kubeflow import fairing
from kubeflow.fairing.kubernetes import utils as k8s_utils
DOCKER_REGISTRY = 'kubeflow-registry.default.svc.cluster.local:30000'
fairing.config.set_builder(
'append',
image_name='fairing-job',
base_image='brightfly/kubeflow-jupyter-lab:tf2.0-gpu',
registry=DOCKER_REGISTRY,
push=True)
# cpu 2, memory 5GiB
fairing.config.set_deployer('job',
namespace='dudaji',
pod_spec_mutators=[
k8s_utils.get_resource_mutator(cpu=2,
memory=5)]
)
fairing.config.run()
else:
remote_train = MyFashionMnist()
remote_train.train()
# In[ ]: