Skip to content

Commit 9d4b678

Browse files
authored
Merge pull request rdcolema#5 from vadakattu/patch-1
Added a function to load a pre-trained model
2 parents 46a54b3 + 1383308 commit 9d4b678

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

img_clf.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def predict_labels(model):
265265
shuffle=False,
266266
class_mode=None)
267267

268-
base_path = "../data/test/test/"
268+
base_path = test_data_dir + "/test/"
269269

270270
with open("prediction.csv", "w") as f:
271271
p_writer = csv.writer(f, delimiter=',', lineterminator='\n')
@@ -281,7 +281,18 @@ def predict_labels(model):
281281
shuffle=False)
282282
prediction = model.predict_generator(test_generator, 1)[0][0]
283283
p_writer.writerow([pic_id, prediction])
284-
284+
285+
def load_model():
286+
"""Loads a model from an earlier run"""
287+
288+
json_file = open('final_model_architecture.json', 'r')
289+
model_json = json_file.read()
290+
json_file.close()
291+
model = model_from_json(model_json)
292+
model.load_weights('final_weights.h5')
293+
print "Model Loaded."
294+
295+
return model
285296

286297
if __name__ == "__main__":
287298
save_bottlebeck_features()

0 commit comments

Comments
 (0)