MCPcopy Index your code
hub / github.com/makelove/OpenCV-Python-Tutorial / evaluate_model

Function evaluate_model

官方samples/digits.py:105–123  ·  view source on GitHub ↗
(model, digits, samples, labels)

Source from the content-addressed store, hash-verified

103
104
105def evaluate_model(model, digits, samples, labels):
106 resp = model.predict(samples)
107 err = (labels != resp).mean()
108 print('error: %.2f %%' % (err*100))
109
110 confusion = np.zeros((10, 10), np.int32)
111 for i, j in zip(labels, resp):
112 confusion[i, int(j)] += 1
113 print('confusion matrix:')
114 print(confusion)
115 print()
116
117 vis = []
118 for img, flag in zip(digits, resp == labels):
119 img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
120 if not flag:
121 img[...,:2] = 0
122 vis.append(img)
123 return mosaic(25, vis)
124
125def preprocess_simple(digits):
126 return np.float32(digits).reshape(-1, SZ*SZ) / 255.0

Callers 1

digits.pyFile · 0.85

Calls 2

mosaicFunction · 0.90
predictMethod · 0.45

Tested by

no test coverage detected