MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / RegressionPredictor

Class RegressionPredictor

digit-recognizer/app/predictors.py:4–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3
4class RegressionPredictor(object):
5 __model = None
6
7 # ensure predictor be initialized only once by using Singleton Pattern
8 def __new__(cls, *args, **kwargs):
9 if not hasattr(cls, '__instance'):
10 cls.__instance = super().__new__(cls)
11 cls.__model = load_model('app/models/regression.h5')
12 return cls.__instance
13
14 @staticmethod
15 def predict(input_data):
16 assert RegressionPredictor.__model, \
17 "Use 'RegressionPredictor()' to initialize before using 'RegressionPredictor.predict()'"
18
19 x = input_data.reshape(1, 28, 28)
20 return RegressionPredictor.__model.predict(x).flatten().tolist()
21
22
23class CNNPredictor(object):

Callers 1

indexFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected