Skip to content

Instantly share code, notes, and snippets.

@hartikainen
Created February 1, 2020 14:21
Show Gist options
  • Save hartikainen/29cbab60e5039219a513c9f0231d9fc4 to your computer and use it in GitHub Desktop.
Save hartikainen/29cbab60e5039219a513c9f0231d9fc4 to your computer and use it in GitHub Desktop.
import pickle
import tensorflow as tf
def main():
x = tf.keras.layers.Input((3, ))
y = tf.keras.layers.Dense(5)(x)
model_1 = tf.keras.Model(x, y)
_ = model_1(tf.random.uniform((15, 3)))
model_2 = pickle.loads(pickle.dumps(model_1))
for w1, w2 in zip(model_1.get_weights(), model_2.get_weights()):
tf.debugging.assert_equal(w1, w2)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment