This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =================================================================================== | |
| Kernel Shape Output Shape Params \ | |
| Layer | |
| 0_rb1.convb1.Conv2d_conv [3, 16, 3, 3] [1, 16, 32, 128] 448.0 | |
| 1_rb1.convb1.BatchNorm2d_bn [16] [1, 16, 32, 128] 32.0 | |
| 2_rb1.LeakyReLU_act1 - [1, 16, 32, 128] - | |
| 3_rb1.convb2.Conv2d_conv [16, 16, 3, 3] [1, 16, 32, 128] 2.32k | |
| 4_rb1.convb2.BatchNorm2d_bn [16] [1, 16, 32, 128] 32.0 | |
| 5_rb1.Conv2d_shortcut [3, 16, 1, 1] [1, 16, 32, 128] 64.0 | |
| 6_rb1.LeakyReLU_act2 - [1, 16, 32, 128] - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import typing | |
| import numpy as np | |
| from mltu.inferenceModel import OnnxInferenceModel | |
| from mltu.utils.text_utils import ctc_decoder, get_cer | |
| class ImageToWordModel(OnnxInferenceModel): | |
| def __init__(self, *args, **kwargs): | |
| super().__init__(*args, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all | |
| TensorBoard 2.10.1 at http://localhost:6006/ (Press CTRL+C to quit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Tensorboard --logdir Models\08_handwriting_recognition_torch\202303142139\logs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # create callbacks | |
| earlyStopping = EarlyStopping(monitor='val_CER', patience=20, mode="min", verbose=1) | |
| modelCheckpoint = ModelCheckpoint(configs.model_path + '/model.pt', monitor='val_CER', mode="min", save_best_only=True, verbose=1) | |
| tb_callback = TensorBoard(configs.model_path + '/logs') | |
| reduce_lr = ReduceLROnPlateau(monitor='val_CER', factor=0.9, patience=10, verbose=1, mode='min', min_lr=1e-6) | |
| model2onnx = Model2onnx( | |
| saved_model_path=configs.model_path + '/model.pt', | |
| input_shape=(1, configs.height, configs.width, 3), | |
| verbose=1, | |
| metadata={"vocab": configs.vocab} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # put on cuda device if available | |
| if torch.cuda.is_available(): | |
| network = network.cuda() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # uncomment to print network summary, torchsummaryX package is required | |
| summary(network, torch.zeros((1, configs.height, configs.width, 3))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| loss = CTCLoss(blank=len(configs.vocab)) | |
| optimizer = optim.Adam(network.parameters(), lr=configs.learning_rate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| network = Network(len(configs.vocab), activation='leaky_relu', dropout=0.3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Augment training data with random brightness, rotation and erode/dilate | |
| train_dataProvider.augmentors = [ | |
| RandomBrightness(), | |
| RandomErodeDilate(), | |
| RandomSharpen(), | |
| RandomRotate(angle=10), | |
| ] |