Skip to content

Commit 8e6f998

Browse files
committed
resolve merge conflict
2 parents 732aa02 + c01c547 commit 8e6f998

7 files changed

Lines changed: 571 additions & 10 deletions

File tree

dotscience/__init__.py

Lines changed: 459 additions & 10 deletions
Large diffs are not rendered by default.

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
env

examples/classes.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"0": "zero",
2+
"1": "one",
3+
"2": "two",
4+
"3": "three",
5+
"4": "four",
6+
"5": "five",
7+
"6": "six",
8+
"7": "seven",
9+
"8": "eight",
10+
"9": "nine"}

examples/env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export DOTSCIENCE_USERNAME=""
2+
export DOTSCIENCE_APIKEY=""
3+
export DOTSCIENCE_PROJECT_NAME=""
4+
export DOTSCIENCE_HOSTNAME=""

examples/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tensorflow==1.14.0
2+
#datadots-api==0.2.0

examples/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash -e
2+
if [ ! -f env ]; then
3+
echo "please copy env.sample to env and fill it in"
4+
exit 1
5+
fi
6+
rm -rf model
7+
. ./env
8+
PYTHONPATH=..:$PYTHONPATH python3 train.py

examples/train.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from __future__ import print_function
2+
import dotscience as ds
3+
import os
4+
5+
# defaults to connecting to prod
6+
ds.connect(
7+
os.getenv("DOTSCIENCE_USERNAME"),
8+
os.getenv("DOTSCIENCE_APIKEY"),
9+
os.getenv("DOTSCIENCE_PROJECT_NAME"),
10+
os.getenv("DOTSCIENCE_HOSTNAME")
11+
)
12+
13+
import tensorflow as tf
14+
from tensorflow.keras.datasets import mnist
15+
from tensorflow.keras.models import Sequential
16+
from tensorflow.keras.layers import Dense, Dropout, Flatten
17+
from tensorflow.keras.layers import Conv2D, MaxPooling2D
18+
from tensorflow.keras import backend as K
19+
20+
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
21+
22+
batch_size = ds.parameter("batch_size", 128)
23+
num_classes = ds.parameter("num_classes", 10)
24+
epochs = ds.parameter("epochs", 1)
25+
26+
# input image dimensions
27+
img_rows, img_cols = 28, 28
28+
limit = ds.parameter("limit", 1000)
29+
30+
# the data, split between train and test sets
31+
(x_train, y_train), (x_test, y_test) = mnist.load_data()
32+
x_train = x_train[:limit]
33+
y_train = y_train[:limit]
34+
35+
if K.image_data_format() == 'channels_first':
36+
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
37+
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
38+
input_shape = (1, img_rows, img_cols)
39+
else:
40+
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
41+
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
42+
input_shape = (img_rows, img_cols, 1)
43+
44+
x_train = x_train.astype('float32')
45+
x_test = x_test.astype('float32')
46+
x_train /= 255
47+
x_test /= 255
48+
print('x_train shape:', x_train.shape)
49+
print(x_train.shape[0], 'train samples')
50+
print(x_test.shape[0], 'test samples')
51+
52+
# convert class vectors to binary class matrices
53+
y_train = tf.keras.utils.to_categorical(y_train, num_classes)
54+
y_test = tf.keras.utils.to_categorical(y_test, num_classes)
55+
56+
model = Sequential()
57+
model.add(Conv2D(32, kernel_size=(3, 3),
58+
activation='relu',
59+
input_shape=input_shape))
60+
model.add(Conv2D(64, (3, 3), activation='relu'))
61+
model.add(MaxPooling2D(pool_size=(2, 2)))
62+
model.add(Dropout(0.25))
63+
model.add(Flatten())
64+
model.add(Dense(128, activation='relu'))
65+
model.add(Dropout(0.5))
66+
model.add(Dense(num_classes, activation='softmax'))
67+
68+
model.compile(loss=tf.keras.losses.categorical_crossentropy,
69+
optimizer=tf.keras.optimizers.Adam(),
70+
metrics=['accuracy'])
71+
72+
model.fit(x_train, y_train,
73+
batch_size=batch_size,
74+
epochs=epochs,
75+
verbose=1,
76+
validation_data=(x_test, y_test))
77+
score = model.evaluate(x_test, y_test, verbose=0)
78+
print('Test loss:', ds.metric("loss", score[0]))
79+
print('Test accuracy:', ds.metric("accuracy", score[1]))
80+
81+
#model.save("model.h5")
82+
#tf.keras.experimental.export_saved_model(model, ds.model(tf, 'model'))
83+
84+
85+
tf.keras.experimental.export_saved_model(model, ds.output('model'))
86+
ds.model(tf, "mnist", "model", classes="classes.json")
87+
ds.publish("trained mnist model", deploy=True)

0 commit comments

Comments
 (0)