Skip to content

Instantly share code, notes, and snippets.

@mdkozlowski
Created July 26, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdkozlowski/381f58d0a590a1d3b1d121ce97b3eee7 to your computer and use it in GitHub Desktop.
Save mdkozlowski/381f58d0a590a1d3b1d121ce97b3eee7 to your computer and use it in GitHub Desktop.
import time
import_start = time.clock()
import tensorflow as tf
import_stop = time.clock()
import numpy as np
from keras.models import Model
from keras.layers import Dense, Input
def create_model():
input_layer = Input(shape=(1,))
dense_layer = Dense(1)(input_layer)
output = Dense(1, activation=None)(dense_layer)
model = Model(inputs=input_layer, outputs=output)
model.compile(loss='mean_squared_error', optimizer='Adam')
return model
def main():
model = create_model() # create a model with random weights
dummy_input = np.asarray(0).reshape((1,1))
first_prediction_start = time.clock()
model.predict(dummy_input) # dummy prediction
first_prediction_stop = time.clock()
second_prediction_start = time.clock()
model.predict(dummy_input) # dummy prediction
second_prediction_stop = time.clock()
third_prediction_start = time.clock()
model.predict(dummy_input) # dummy prediction
third_prediction_stop = time.clock()
print("%f s to load TensorFlow\n" % (import_stop - import_start))
print("%f s for first prediction" % (first_prediction_stop - first_prediction_start))
print("%f s for second prediction" % (second_prediction_stop - second_prediction_start))
print("%f s for third prediction" % (third_prediction_stop - third_prediction_start))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment