def make_model(X, class_names, nb_layers=4, try_checkpoint=True,
no_cp_fatal=False, weights_file='weights.hdf5'):
model = None
from_scratch = True
# Initialize weights using checkpoint if it exists.
if (try_checkpoint):
print("Looking for previous weights...")
if ( isfile(weights_file) ):
print ('Weights file detected. Loading from ',weights_file)
model = load_model(weights_file)
from_scratch = False
else:
if (no_cp_fatal):
raise Exception("No weights file detected; can't do anything. Aborting.")
else:
print('No weights file detected, so starting from scratch.')
if from_scratch:
if (LooseVersion(keras.__version__) < LooseVersion("2")):
print("Making Keras 1 version of model")
model = MyCNN(X, nb_classes=len(class_names), nb_layers=nb_layers)
else:
print("Making Keras 2 version of model")
model = MyCNN_Keras2(X, nb_classes=len(class_names), nb_layers=nb_layers)
model.summary()
return model
评论列表
文章目录