Skip to content

Instantly share code, notes, and snippets.

View pythonlessons's full-sized avatar
🏠
Working from home

Rokas Liuberskis pythonlessons

🏠
Working from home
View GitHub Profile
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_15.html
Created March 20, 2023 13:53
handwriting_recognition_pytorch
===================================================================================
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] -
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_14.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
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)
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_13.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
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)
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_12.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
Tensorboard --logdir Models\08_handwriting_recognition_torch\202303142139\logs
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_11.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
# 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}
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_10.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
# put on cuda device if available
if torch.cuda.is_available():
network = network.cuda()
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_9.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
# uncomment to print network summary, torchsummaryX package is required
summary(network, torch.zeros((1, configs.height, configs.width, 3)))
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_8.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
loss = CTCLoss(blank=len(configs.vocab))
optimizer = optim.Adam(network.parameters(), lr=configs.learning_rate)
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_7.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
network = Network(len(configs.vocab), activation='leaky_relu', dropout=0.3)
@pythonlessons
pythonlessons / handwriting_recognition_pytorch_6.py
Created March 20, 2023 13:53
handwriting_recognition_pytorch
# Augment training data with random brightness, rotation and erode/dilate
train_dataProvider.augmentors = [
RandomBrightness(),
RandomErodeDilate(),
RandomSharpen(),
RandomRotate(angle=10),
]