MCPcopy Create free account
hub / github.com/Turing-Project/WriteGPT / predict

Function predict

RecognizaitonNetwork/densenet/model.py:36–61  ·  view source on GitHub ↗
(img)

Source from the content-addressed store, hash-verified

34 return u''.join(char_list)
35
36def predict(img):
37 width, height = img.size[0], img.size[1]
38 scale = height * 1.0 / 32
39 width = int(width / scale)
40
41 img = img.resize([width, 32], Image.ANTIALIAS)
42
43 '''
44 img_array = np.array(img.convert('1'))
45 boundary_array = np.concatenate((img_array[0, :], img_array[:, width - 1], img_array[31, :], img_array[:, 0]), axis=0)
46 if np.median(boundary_array) == 0: # 将黑底白字转换为白底黑字
47 img = ImageOps.invert(img)
48 '''
49
50 img = np.array(img).astype(np.float32) / 255.0 - 0.5
51
52 X = img.reshape([1, 32, width, 1])
53
54 y_pred = basemodel.predict(X)
55 y_pred = y_pred[:, :, :]
56
57 # out = K.get_value(K.ctc_decode(y_pred, input_length=np.ones(y_pred.shape[0]) * y_pred.shape[1])[0][0])[:, :]
58 # out = u''.join([characters[x] for x in out[0]])
59 out = decode(y_pred)
60
61 return out

Callers

nothing calls this directly

Calls 2

decodeFunction · 0.85
predictMethod · 0.45

Tested by

no test coverage detected