forked from Lornatang/CRNN-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
80 lines (68 loc) · 2.56 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2021 Dakewe Biotech Corporation. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
# ==============================================================================
import random
import numpy as np
import torch
from torch.backends import cudnn
# Random seed to maintain reproducible results
random.seed(0)
torch.manual_seed(0)
np.random.seed(0)
# Use GPU for training by default
device = torch.device("cpu", 0)
# Turning on when the image size does not change during training can speed up training
cudnn.benchmark = True
# character to be recognized
chars = "0123456789abcdefghijklmnopqrstuvwxyz"
labels_dict = {char: i + 1 for i, char in enumerate(chars)}
chars_dict = {label: char for char, label in labels_dict.items()}
# Model parameter configuration
model_num_classes = len(chars) + 1
model_image_width = 100
model_image_height = 32
# Mean and std of the model input data source
mean = 0.5
std = 0.5
# Current configuration parameter method
mode = "test"
# Experiment name, easy to save weights and log files
exp_name = "CRNN_MJSynth"
if mode == "train":
# Train dataset
train_dataroot = "./data/MJSynth"
annotation_train_file_name = "annotation_train.txt"
# Test dataset
test_dataroot = "./data/IIIT5K"
annotation_test_file_name = "annotation_test.txt"
batch_size = 64
num_workers = 4
# Incremental training and migration training
resume = ""
# Total num epochs
epochs = 5
# Adadelta optimizer parameter
model_lr = 1.0
# How many iterations to print the training result
print_frequency = 1000
if mode == "test":
# Whether to enable half-precision inference
fp16 = False
# The path and name of the folder where the verification results are saved
result_dir = "./results/test"
result_file_name = "IC13_test.txt"
# The directory path where the dataset to be verified is located
dataroot = "./data/ICDAR2013"
annotation_file_name = "annotation_test.txt"
#model_path = "results/CRNN_MJSynth/last.pth.tar"
model_path = "results/pretrained_models/CRNN-MJSynth-e9341ede.pth.tar"