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
if __name__ == '__main__': | |
import timeit | |
print 'Initialising high-accuracy decimal values...' | |
array_max = Decimal('1e6') | |
deci_two = Decimal(2) | |
values_decimal = np.arange(-array_max/deci_two, array_max/deci_two + Decimal(1), Decimal(1)) / array_max | |
values_decimal[0] -= Decimal('1e-4') | |
values = np.float32(values_decimal) | |
values_rev = np.random.permutation(values) |
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
import tensorflow as tf | |
import keras2onnx as k2o | |
import onnx | |
if __name__ == "__main__": | |
model = tf.keras.models.load_model('./data/save_model_v2.h5') | |
onnx_model = k2o.convert_keras(model, model.name) | |
onnx.save_model(onnx_model, './data/save_model_v2.onnx') |
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
import tensorflow as tf | |
def create_model(): | |
X = tf.keras.Input(shape=(10,), name='input') | |
h = tf.keras.layers.Dense(10, kernel_initializer=tf.constant_initializer(1), bias_initializer=tf.constant_initializer(1))(X) | |
y = tf.keras.layers.Dense(10, kernel_initializer=tf.constant_initializer(1), bias_initializer=tf.constant_initializer(1), name='output')(h) | |
model = tf.keras.models.Model(inputs=[X], outputs=[y]) | |
return model | |
def run_model(model: tf.keras.Model): |
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 save_weights(sess): | |
saver = tf.train.Saver() | |
saver.save(sess, './data/tf_io.ckpt') | |
def load_weights(sess, in_name, out_name): | |
tf.train.import_meta_graph('./data/tf_io.ckpt.meta') | |
saver = tf.train.Saver() | |
saver.restore(sess, './data/tf_io.ckpt') | |
X = tf.get_default_graph().get_tensor_by_name(in_name) | |
y = tf.get_default_graph().get_tensor_by_name(out_name) |
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 use_tf_saved_model(X, y, sess): | |
builder = tf.saved_model.builder.SavedModelBuilder('./data/save_model') | |
builder.add_meta_graph_and_variables( | |
sess, | |
[tf.saved_model.tag_constants.SERVING], | |
signature_def_map={ | |
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: tf.saved_model.predict_signature_def( | |
inputs={'X': X}, | |
outputs={'y': y} | |
) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.