Last active
May 23, 2018 13:41
-
-
Save AmirAlavi/ab8e3bdf3fca09c25ba808dd4cbdd48a to your computer and use it in GitHub Desktop.
timing load_weights on Resent
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 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() |
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 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