小编lee*_*emm的帖子

如何将decode_batch_predictions()方法添加到Keras Captcha OCR模型中?

当前的Keras Captcha OCR 模型返回 CTC 编码输出,需要推理后解码。

要对其进行解码,需要在推理之后作为单独的步骤运行解码实用函数。

preds = prediction_model.predict(batch_images)
pred_texts = decode_batch_predictions(preds)
Run Code Online (Sandbox Code Playgroud)

解码的效用函数使用keras.backend.ctc_decode,而 又使用贪婪解码器或波束搜索解码器。

# A utility function to decode the output of the network
def decode_batch_predictions(pred):
    input_len = np.ones(pred.shape[0]) * pred.shape[1]
    # Use greedy search. For complex tasks, you can use beam search
    results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0][
        :, :max_length
    ]
    # Iterate over the results and get back the text
    output_text = []
    for res in results:
        res = tf.strings.reduce_join(num_to_char(res)).numpy().decode("utf-8")
        output_text.append(res)
    return output_text …
Run Code Online (Sandbox Code Playgroud)

ocr decoding keras ctc

5
推荐指数
1
解决办法
546
查看次数

Python只替换re.sub匹配的一部分

以下Python脚本: re.sub("[^a-zA-Z]pi[^a-zA-Z]", "(math.pi)", "2pi3 + supirse")

结果是: '(math.pi) + supirse'

虽然之前和之后的非alpha匹配pi很关键,但我不希望在匹配中替换这些非alpha字符.我想看到以下输出:'2(math.pi)3 + supirse'

注意:先前的建议如下: re.sub("\Bpi\B", "(math.pi)", "2pi3 + supirse")

导致完全替换每个实例:'2(math.pi)3 + su(math.pi)rse'这也不是我想要的

python regex match

1
推荐指数
1
解决办法
3629
查看次数

标签 统计

ctc ×1

decoding ×1

keras ×1

match ×1

ocr ×1

python ×1

regex ×1