This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo pip install tensorflow | |
sudo pip install numpy | |
sudo pip install sklearn | |
sudo pip install keras |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seed = 7 | |
numpy.random.seed(seed) | |
dataset = numpy.loadtxt("./pima-indians-diabetes.data", delimiter=",") | |
# split into input (X) and output (Y) variables | |
X = dataset[:,0:8] | |
Y = dataset[:,8] | |
model = Sequential() | |
model.add(Dense(12, input_dim=8, init='uniform', activation='relu')) | |
model.add(Dense(8, init='uniform', activation='relu')) | |
model.add(Dense(1, init='uniform', activation='sigmoid')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.python.tools import freeze_graph, optimize_for_inference_lib | |
from keras import backend as K | |
from sklearn.cross_validation import train_test_split | |
from keras.wrappers.scikit_learn import KerasRegressor | |
import tensorflow as tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_model(saver, model, input_node_names, output_node_name,MODEL_NAME): | |
tf.train.write_graph(K.get_session().graph_def, 'out', \ | |
MODEL_NAME + '_graph.pbtxt') | |
saver.save(K.get_session(), 'out/' + MODEL_NAME + '.chkp') | |
freeze_graph.freeze_graph('out/' + MODEL_NAME + '_graph.pbtxt', None, \ | |
False, 'out/' + MODEL_NAME + '.chkp', output_node_name, \ | |
"save/restore_all", "save/Const:0", \ | |
'out/modelim' + MODEL_NAME + '.pb', True, "") | |
input_graph_def = tf.GraphDef() | |
with tf.gfile.Open('out/modelim' + MODEL_NAME + '.pb', "rb") as f: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train, X_test, y_train, y_test = train_test_split(X, Y) | |
estimators = [] | |
estimator = KerasRegressor(build_fn=model, epochs=20, batch_size=50, verbose=2) | |
export_model(tf.train.Saver(), estimator, ["input name"], "output name","test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export_model(tf.train.Saver(), estimator, [inputName], outPutName,"test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputName=model.input.name[:-2] | |
outPutName=model.output.name[:-2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Sequential | |
from keras.layers import Dense | |
import numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
predict=numpy.array([1,89,66,23,94,28.1,0.167,21]).reshape(1,8) | |
print(model.predict_classes(predict)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bazel-bin/tensorflow/contrib/lite/toco/toco \ | |
--input_file=modelimtest.pb \ | |
--input_format=TENSORFLOW_GRAPHDEF \ | |
--output_format=TFLITE \ | |
--output_file=modelim.lite \ | |
--inference_type=FLOAT \ | |
--input_type=FLOAT \ | |
--input_arrays=dense_1_input \ | |
--output_arrays=dense_3/Sigmoid \ | |
--input_shapes=1,8 |
OlderNewer