# Path: mxnet/metrics/base.py
# class STNAccuracy(mx.metric.EvalMetric):
# 
#     def __init__(self, make_label_time_major=True):
#         super(STNAccuracy, self).__init__('Accuracy')
#         self.make_label_time_major = make_label_time_major
# 
#     def accuracy(self, labels, preds):
#         if preds.shape != labels.shape:
#             preds = np.argmax(preds, axis=1)
#         preds = preds.astype(np.int32)
#         labels = labels.astype(np.int32)
# 
#         sum_metric = (preds.flat == labels.flat).sum()
#         return sum_metric, len(preds.flat)
# 
#     def update(self, labels, preds):
#         cls_prob = preds[0].asnumpy()
#         labels = labels[0].asnumpy()
#         cls_labels = labels
# 
#         if len(cls_labels.shape) == 2:
#             # make labels time major
#             if self.make_label_time_major:
#                 cls_labels = np.transpose(cls_labels, axes=(1, 0))
#             cls_labels = cls_labels.ravel()
# 
#         accuracy_sum, num_instances = self.accuracy(cls_labels, cls_prob)
#         self.sum_metric += accuracy_sum
#         self.num_inst += num_instances


import logging
import math
import mxnet as mx
import numpy as np
from .base import STNAccuracy
from .ctc.ctc_loss import CTCLoss as C_CTCLoss




def remove_blank(label, blank_label=0):
    blank_indices = np.where(label == blank_label)[0]
    if len(blank_indices) == 0:
        return label

    return label[:blank_indices[0]]


def strip_prediction(prediction, blank_label=0):
    stripped_prediction = []
    enlarged_prediction = [blank_label] + list(prediction)

    for char_1, char_2 in zip(enlarged_prediction, prediction):
        if char_2 == blank_label or char_2 == char_1:
            continue
        stripped_prediction.append(char_2)

    return stripped_prediction



# Path: mxnet/metrics/base.py
# class STNAccuracy(mx.metric.EvalMetric):
# 
#     def __init__(self, make_label_time_major=True):
#         super(STNAccuracy, self).__init__('Accuracy')
#         self.make_label_time_major = make_label_time_major
# 
#     def accuracy(self, labels, preds):
#         if preds.shape != labels.shape:
#             preds = np.argmax(preds, axis=1)
#         preds = preds.astype(np.int32)
#         labels = labels.astype(np.int32)
# 
#         sum_metric = (preds.flat == labels.flat).sum()
#         return sum_metric, len(preds.flat)
# 
#     def update(self, labels, preds):
#         cls_prob = preds[0].asnumpy()
#         labels = labels[0].asnumpy()
#         cls_labels = labels
# 
#         if len(cls_labels.shape) == 2:
#             # make labels time major
#             if self.make_label_time_major:
#                 cls_labels = np.transpose(cls_labels, axes=(1, 0))
#             cls_labels = cls_labels.ravel()
# 
#         accuracy_sum, num_instances = self.accuracy(cls_labels, cls_prob)
#         self.sum_metric += accuracy_sum
#         self.num_inst += num_instances


# Path: mxnet/metrics/ctc_metrics.py
import logging
import math
import mxnet as mx
import numpy as np
from .base import STNAccuracy
from .ctc.ctc_loss import CTCLoss as C_CTCLoss





def remove_blank(label, blank_label=0):
    blank_indices = np.where(label == blank_label)[0]
    if len(blank_indices) == 0:
        return label

    return label[:blank_indices[0]]


def strip_prediction(prediction, blank_label=0):
    stripped_prediction = []
    enlarged_prediction = [blank_label] + list(prediction)

    for char_1, char_2 in zip(enlarged_prediction, prediction):
        if char_2 == blank_label or char_2 == char_1:
            continue
        stripped_prediction.append(char_2)

    return stripped_prediction



class CTCSTNAccuracy(STNAccuracy):