mobilenet_v3_large, mobilenet_v3_small, shufflenet_v2_x1_0, shufflenet_v2_x1_5, shufflenet_v2_x2_0, ) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(1, os.path.dirname(os.path.abspath(__file__))) from cnocr.utils import set_logger, get_model_size from cnocr.consts import IMG_STANDARD_HEIGHT, ENCODER_CONFIGS, DECODER_CONFIGS from cnocr.models.densenet import DenseNet, DenseNetLite from cnocr.models.mobilenet import gen_mobilenet_v3 logger = set_logger('info') def test_conv(): conv = nn.Conv2d(32, 32, kernel_size=5, stride=1, padding=2, bias=False) input = torch.rand(1, 32, 10, 4) res = conv(input) logger.info(res.shape) def test_densenet(): width = 280 img = torch.rand(4, 1, IMG_STANDARD_HEIGHT, width) net = DenseNet(32, [2, 2, 2, 2], 64) net.eval() logger.info(net)
import os import time import logging import argparse from operator import itemgetter from pathlib import Path from collections import Counter import mxnet as mx import Levenshtein sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from cnocr import CnOcr from cnocr.utils import set_logger, gen_context logger = set_logger(log_level=logging.INFO) def evaluate(): parser = argparse.ArgumentParser() parser.add_argument("--model-name", help="model name", type=str, default='densenet-lite-lstm') parser.add_argument("--model-epoch", type=int, default=None, help="model epoch") parser.add_argument( "--gpu", help="Number of GPUs for training [Default 0, means using cpu]"
# Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. from pathlib import Path import os import re import unicodedata from cnocr.consts import VOCAB_FP from cnocr.utils import read_charset, read_tsv_file, set_logger logger = set_logger(log_level='INFO') def check_legal(width, height, fname, gt, letter2id): legal_letters = set(letter2id) if width <= height: return False if len(gt) < 3 or len(gt) > 30: return False if gt[0] == '#' and len(gt) == 3 and len(set(gt)) == 1: return False gt_set = set(gt) illegal_letters = gt_set - legal_letters if illegal_letters: logger.warning(f'illegal letters in gt "{gt}": {illegal_letters}')