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

Class CNNPredictor

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

Source from the content-addressed store, hash-verified

21
22
23class CNNPredictor(object):
24 __model = None
25
26 # ensure predictor be initialized only once by using Singleton Pattern
27 def __new__(cls, *args, **kwargs):
28 if not hasattr(cls, '__instance'):
29 cls.__instance = super().__new__(cls)
30 cls.__model = load_model('app/models/convolutional.h5')
31 return cls.__instance
32
33 @staticmethod
34 def predict(input_data):
35 assert CNNPredictor.__model, "Use 'CNNPredictor()' to initialize before using 'CNNPredictor.predict()'"
36
37 x = input_data.reshape(1, 28, 28, 1)
38 return CNNPredictor.__model.predict(x).flatten().tolist()

Callers 1

indexFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected