Compare commits

...
Author SHA1 Message Date
Jake Miller 65bb9efa0d Fail more loudly when model file has an error
FileNotFound and invalid models will now throw errors
2019-05-15 11:21:10 -04:00
Dan Petro df3c0b968d Merge branch 'interrupt_evaluator' 2019-04-30 13:56:00 -07:00
Dan Petro 001061f639 Removed unused variable 2019-04-30 13:55:39 -07:00
Dan Petro 18d66608aa Linter exception for matplotlib 2019-04-30 10:41:04 -07:00
+12 -5
View File
@@ -1,9 +1,10 @@
import os
import random
import sys
# Prevent Tkinter Dependency
import matplotlib
matplotlib.use('agg')
matplotlib.use('agg') # noqa: E402
import matplotlib.pyplot as plt
import numpy as np
@@ -50,7 +51,7 @@ class EyeballModel:
image_width, image_height = 224, 224
input_shape = (image_width, image_height, 3)
def __init__(self, print_summary=False, weights_file="weights.h5", seed=None):
def __init__(self, weights_file, print_summary=False, seed=None):
"""Constructor for model class.
Keyword arguments:
@@ -95,10 +96,16 @@ class EyeballModel:
self.training_labels = self.training_labels.sample(frac=1)
if weights_file is not None and os.path.isfile(weights_file):
self.model.load_weights(weights_file)
try:
self.model.load_weights(weights_file)
except OSError as e:
print(f"ERROR: Unable to open weights file '{weights_file}'")
sys.exit(-1)
print("Loaded model from file.")
else:
print("No model loaded from file")
if weights_file is not None:
raise FileNotFoundError
print("WARN: No model loaded from file. Generating random model")
# Data augmentation
augmentor = Augmentor.Pipeline()
@@ -267,7 +274,7 @@ class EyeballModel:
prediction_manager = PredictionManager()
try:
output = self.model.predict_generator(
self.model.predict_generator(
evaluation_generator,
callbacks=[prediction_manager],
verbose=1,