Created
July 26, 2018 15:17
-
-
Save mdkozlowski/381f58d0a590a1d3b1d121ce97b3eee7 to your computer and use it in GitHub Desktop.
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 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