Skip to content

Instantly share code, notes, and snippets.

@AmirAlavi
Last active May 23, 2018 13:41
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 AmirAlavi/ab8e3bdf3fca09c25ba808dd4cbdd48a to your computer and use it in GitHub Desktop.
Save AmirAlavi/ab8e3bdf3fca09c25ba808dd4cbdd48a to your computer and use it in GitHub Desktop.
timing load_weights on Resent
import keras
def get_model1():
model = keras.applications.resnet50.ResNet50()
return model
def main():
model1 = get_model1()
print(model1.summary())
model1.save_weights('pretrained_weights_resnet.h5')
if __name__ == '__main__':
main()
import timeit
from functools import partial
import keras
def get_model2():
model = keras.applications.resnet50.ResNet50()
return model
def load_weights(model):
model.load_weights('pretrained_weights_resnet.h5', by_name=True, skip_mismatch=False)
def main():
model2 = get_model2()
print(model2.summary())
times = timeit.Timer(partial(load_weights, model2)).repeat(10, 100)
# Divide by the number of repeats
time_taken = min(times) / 1000
print(time_taken)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment