Create model.py
Browse files
model.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import onnxruntime as ort
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
class Model:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.session = ort.InferenceSession("mnist_cnn.onnx")
|
| 7 |
+
|
| 8 |
+
def predict(self, inputs):
|
| 9 |
+
inputs = np.array(inputs).astype(np.float32).reshape(1, 28, 28, 1)
|
| 10 |
+
outputs = self.session.run(None, {"input": inputs})
|
| 11 |
+
return {"digit": int(np.argmax(outputs[0])), "confidence_scores": outputs[0].tolist()}
|