From 2e21e6610a2d3550ce531a5d97400136afcd698e Mon Sep 17 00:00:00 2001 From: felix Date: Tue, 13 Feb 2024 14:04:50 +0100 Subject: [PATCH 1/2] rename char classifiation scripts and dependency pin --- .conda/meta.yaml | 2 +- api/pyproject.toml | 2 +- .../differentiable_binarization/pytorch.py | 38 +++++++++---------- pyproject.toml | 10 +++-- references/classification/README.md | 6 +-- references/classification/latency.csv | 31 --------------- ..._pytorch.py => train_pytorch_character.py} | 0 ...rflow.py => train_tensorflow_character.py} | 0 references/detection/latency.csv | 15 -------- references/detection/results.csv | 9 ----- references/obj_detection/latency.csv | 3 -- references/recognition/latency.csv | 21 ---------- 12 files changed, 29 insertions(+), 108 deletions(-) delete mode 100644 references/classification/latency.csv rename references/classification/{train_pytorch.py => train_pytorch_character.py} (100%) rename references/classification/{train_tensorflow.py => train_tensorflow_character.py} (100%) delete mode 100644 references/detection/latency.csv delete mode 100644 references/detection/results.csv delete mode 100644 references/obj_detection/latency.csv delete mode 100644 references/recognition/latency.csv diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 9cdb757128..c584b3f530 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -32,13 +32,13 @@ requirements: - shapely >=1.6.0, <3.0.0 - langdetect >=1.0.9, <2.0.0 - rapidfuzz >=3.0.0, <4.0.0 + - huggingface_hub >=0.20.0, <1.0.0 - matplotlib >=3.1.0 - weasyprint >=55.0 - defusedxml >=0.7.0 - mplcursors >=0.3 - unidecode >=1.0.0 - tqdm >=4.30.0 - - huggingface_hub >=0.20.0 about: home: {{ urls.get('repository') }} diff --git a/api/pyproject.toml b/api/pyproject.toml index d86fefabd5..2f26a38107 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -11,7 +11,7 @@ license = "Apache-2.0" [tool.poetry.dependencies] python = ">=3.8.2,<3.11" # pypdfium2 needs a python version above 3.8.2 -tensorflow = ">=2.11.0,<3.0.0" +tensorflow = ">=2.11.0,<2.16.0" # cf. https://github.com/mindee/doctr/pull/1461 python-doctr = {git = "https://github.com/mindee/doctr.git", extras = ['tf'], branch = "main" } # Fastapi: minimum version required to avoid pydantic error # cf. https://github.com/tiangolo/fastapi/issues/4168 diff --git a/doctr/models/detection/differentiable_binarization/pytorch.py b/doctr/models/detection/differentiable_binarization/pytorch.py index 17686bb28e..9e4b81ef92 100644 --- a/doctr/models/detection/differentiable_binarization/pytorch.py +++ b/doctr/models/detection/differentiable_binarization/pytorch.py @@ -57,28 +57,24 @@ def __init__( conv_layer = DeformConv2d if deform_conv else nn.Conv2d - self.in_branches = nn.ModuleList( - [ - nn.Sequential( - conv_layer(chans, out_channels, 1, bias=False), - nn.BatchNorm2d(out_channels), - nn.ReLU(inplace=True), - ) - for idx, chans in enumerate(in_channels) - ] - ) + self.in_branches = nn.ModuleList([ + nn.Sequential( + conv_layer(chans, out_channels, 1, bias=False), + nn.BatchNorm2d(out_channels), + nn.ReLU(inplace=True), + ) + for idx, chans in enumerate(in_channels) + ]) self.upsample = nn.Upsample(scale_factor=2, mode="bilinear", align_corners=True) - self.out_branches = nn.ModuleList( - [ - nn.Sequential( - conv_layer(out_channels, out_chans, 3, padding=1, bias=False), - nn.BatchNorm2d(out_chans), - nn.ReLU(inplace=True), - nn.Upsample(scale_factor=2**idx, mode="bilinear", align_corners=True), - ) - for idx, chans in enumerate(in_channels) - ] - ) + self.out_branches = nn.ModuleList([ + nn.Sequential( + conv_layer(out_channels, out_chans, 3, padding=1, bias=False), + nn.BatchNorm2d(out_chans), + nn.ReLU(inplace=True), + nn.Upsample(scale_factor=2**idx, mode="bilinear", align_corners=True), + ) + for idx, chans in enumerate(in_channels) + ]) def forward(self, x: List[torch.Tensor]) -> torch.Tensor: if len(x) != len(self.out_branches): diff --git a/pyproject.toml b/pyproject.toml index 2dc5acbf0d..bbb66cf0d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ dependencies = [ "shapely>=1.6.0,<3.0.0", "langdetect>=1.0.9,<2.0.0", "rapidfuzz>=3.0.0,<4.0.0", + "huggingface-hub>=0.20.0,<1.0.0", "matplotlib>=3.1.0", "weasyprint>=55.0", "Pillow>=9.2.0", @@ -51,12 +52,13 @@ dependencies = [ "mplcursors>=0.3", "unidecode>=1.0.0", "tqdm>=4.30.0", - "huggingface-hub>=0.20.0", ] [project.optional-dependencies] tf = [ - "tensorflow>=2.11.0,<3.0.0", # cf. https://github.com/mindee/doctr/pull/1182 + # cf. https://github.com/mindee/doctr/pull/1182 + # cf. https://github.com/mindee/doctr/pull/1461 + "tensorflow>=2.11.0,<2.16.0", "tf2onnx>=1.16.0,<2.0.0", # cf. https://github.com/onnx/tensorflow-onnx/releases/tag/v1.16.0 ] torch = [ @@ -89,7 +91,9 @@ docs = [ ] dev = [ # Tensorflow - "tensorflow>=2.11.0,<3.0.0", # cf. https://github.com/mindee/doctr/pull/1182 + # cf. https://github.com/mindee/doctr/pull/1182 + # cf. https://github.com/mindee/doctr/pull/1461 + "tensorflow>=2.11.0,<2.16.0", "tf2onnx>=1.16.0,<2.0.0", # cf. https://github.com/onnx/tensorflow-onnx/releases/tag/v1.16.0 # PyTorch "torch>=1.12.0,<3.0.0", diff --git a/references/classification/README.md b/references/classification/README.md index fd41c42357..d0e5c3b83a 100644 --- a/references/classification/README.md +++ b/references/classification/README.md @@ -16,13 +16,13 @@ pip install -r references/requirements.txt You can start your training in TensorFlow: ```shell -python references/classification/train_tensorflow.py mobilenet_v3_large --epochs 5 +python references/classification/train_tensorflow_character.py mobilenet_v3_large --epochs 5 ``` or PyTorch: ```shell -python references/classification/train_pytorch.py mobilenet_v3_large --epochs 5 --device 0 +python references/classification/train_pytorch_character.py mobilenet_v3_large --epochs 5 --device 0 ``` ## Usage orientation classification @@ -61,7 +61,7 @@ Feel free to inspect the multiple script option to customize your training to yo Character classification: ```python -python references/classification/train_tensorflow.py --help +python references/classification/train_tensorflow_character.py --help ``` Orientation classification: diff --git a/references/classification/latency.csv b/references/classification/latency.csv deleted file mode 100644 index b5b7fcdb1e..0000000000 --- a/references/classification/latency.csv +++ /dev/null @@ -1,31 +0,0 @@ -arch,input_shape,framework,hardware,mean,std -mobilenet_v3_small,"(32, 32)",pytorch,cpu,16.53,0.4 -mobilenet_v3_small,"(32, 32)",pytorch,gpu,4.48,0.28 -mobilenet_v3_small_r,"(32, 32)",pytorch,cpu,12.36,0.34 -mobilenet_v3_small_r,"(32, 32)",pytorch,gpu,4.54,0.17 -mobilenet_v3_large,"(32, 32)",pytorch,cpu,28.63,0.59 -mobilenet_v3_large,"(32, 32)",pytorch,gpu,5.2,0.24 -mobilenet_v3_large_r,"(32, 32)",pytorch,cpu,22.91,0.65 -mobilenet_v3_large_r,"(32, 32)",pytorch,gpu,5.72,0.19 -vgg16_bn_r,"(32, 32)",pytorch,cpu,160.66,1.89 -vgg16_bn_r,"(32, 32)",pytorch,gpu,9.2,1.54 -resnet31,"(32, 32)",pytorch,cpu,, -resnet31,"(32, 32)",pytorch,gpu,25.1,0.94 -magc_resnet31,"(32, 32)",pytorch,cpu,, -magc_resnet31,"(32, 32)",pytorch,gpu,25.82,0.43 -mobilenet_v3_small,"(32, 32)",tensorflow,cpu,85.35,1.06 -mobilenet_v3_small,"(32, 32)",tensorflow,gpu,30.61,0.54 -mobilenet_v3_small_r,"(32, 32)",tensorflow,cpu,243.89,2.04 -mobilenet_v3_small_r,"(32, 32)",tensorflow,gpu,28.19,0.67 -mobilenet_v3_large,"(32, 32)",tensorflow,cpu,184.7,1.63 -mobilenet_v3_large,"(32, 32)",tensorflow,gpu,34.59,0.73 -mobilenet_v3_large_r,"(32, 32)",tensorflow,cpu,437.52,4.55 -mobilenet_v3_large_r,"(32, 32)",tensorflow,gpu,32.59,0.71 -resnet18,"(32, 32)",tensorflow,cpu,27.96,0.43 -resnet18,"(32, 32)",tensorflow,gpu,12.35,0.39 -vgg16_bn_r,"(32, 32)",tensorflow,cpu,182.68,18.75 -vgg16_bn_r,"(32, 32)",tensorflow,gpu,9.04,1.1 -resnet31,"(32, 32)",tensorflow,cpu,, -resnet31,"(32, 32)",tensorflow,gpu,28.35,0.84 -magc_resnet31,"(32, 32)",tensorflow,cpu,, -magc_resnet31,"(32, 32)",tensorflow,gpu,32.71,2.66 diff --git a/references/classification/train_pytorch.py b/references/classification/train_pytorch_character.py similarity index 100% rename from references/classification/train_pytorch.py rename to references/classification/train_pytorch_character.py diff --git a/references/classification/train_tensorflow.py b/references/classification/train_tensorflow_character.py similarity index 100% rename from references/classification/train_tensorflow.py rename to references/classification/train_tensorflow_character.py diff --git a/references/detection/latency.csv b/references/detection/latency.csv deleted file mode 100644 index cad1954d43..0000000000 --- a/references/detection/latency.csv +++ /dev/null @@ -1,15 +0,0 @@ -arch,input_shape,framework,hardware,mean,std -linknet_resnet18,"(1024, 1024)",pytorch,cpu,473.73,31.55 -linknet_resnet18,"(1024, 1024)",pytorch,gpu,23.92,0.46 -db_resnet34,"(1024, 1024)",pytorch,cpu,955.65,153.92 -db_resnet34,"(1024, 1024)",pytorch,gpu,44.95,0.38 -db_resnet50,"(1024, 1024)",pytorch,cpu,1257.69,112.12 -db_resnet50,"(1024, 1024)",pytorch,gpu,65.11,0.3 -db_mobilenet_v3_large,"(1024, 1024)",pytorch,cpu,576.56,27.48 -db_mobilenet_v3_large,"(1024, 1024)",pytorch,gpu,40.48,0.75 -linknet_resnet18,"(1024, 1024)",tensorflow,cpu,642.86,13.24 -linknet_resnet18,"(1024, 1024)",tensorflow,gpu,31.62,1.56 -db_resnet50,"(1024, 1024)",tensorflow,cpu,1251.3,138.18 -db_resnet50,"(1024, 1024)",tensorflow,gpu,80.21,0.74 -db_mobilenet_v3_large,"(1024, 1024)",tensorflow,cpu,1641.06,144.8 -db_mobilenet_v3_large,"(1024, 1024)",tensorflow,gpu,179.02,3.4 diff --git a/references/detection/results.csv b/references/detection/results.csv deleted file mode 100644 index 3eb6cd2da4..0000000000 --- a/references/detection/results.csv +++ /dev/null @@ -1,9 +0,0 @@ -architecture,input_shape,framework,test_set,recall,precision,mean_iou -db_resnet50,"(1024, 1024)",tensorflow,funsd,0.8121,0.8665,0.6681 -db_resnet50,"(1024, 1024)",tensorflow,cord,0.9245,0.8962,0.7457 -db_mobilenet_v3_large,"(1024, 1024)",tensorflow,funsd,0.783,0.828,0.6396 -db_mobilenet_v3_large,"(1024, 1024)",tensorflow,cord,0.8098,0.6657,0.5978 -db_resnet50,"(1024, 1024)",pytorch,funsd,0.7917,0.863,0.6652 -db_mobilenet_v3_large,"(1024, 1024)",pytorch,funsd,0.8006,0.841,0.6476 -db_resnet50,"(1024, 1024)",pytorch,cord,0.9296,0.9123,0.7654 -db_mobilenet_v3_large,"(1024, 1024)",pytorch,cord,0.8053,0.6653,0.5976 diff --git a/references/obj_detection/latency.csv b/references/obj_detection/latency.csv deleted file mode 100644 index ef92e78695..0000000000 --- a/references/obj_detection/latency.csv +++ /dev/null @@ -1,3 +0,0 @@ -arch,input_shape,framework,hardware,mean,std -fasterrcnn_mobilenet_v3_large_fpn,"(1024, 1024)",pytorch,cpu,257.85,14.28 -fasterrcnn_mobilenet_v3_large_fpn,"(1024, 1024)",pytorch,gpu,17.76,0.68 diff --git a/references/recognition/latency.csv b/references/recognition/latency.csv deleted file mode 100644 index 593664ef9e..0000000000 --- a/references/recognition/latency.csv +++ /dev/null @@ -1,21 +0,0 @@ -arch,input_shape,framework,hardware,mean,std -crnn_vgg16_bn,"(32, 128)",pytorch,cpu,687.93,93.79 -crnn_vgg16_bn,"(32, 128)",pytorch,gpu,32.34,0.25 -crnn_mobilenet_v3_small,"(32, 128)",pytorch,cpu,64.74,7.97 -crnn_mobilenet_v3_small,"(32, 128)",pytorch,gpu,8.43,0.57 -crnn_mobilenet_v3_large,"(32, 128)",pytorch,cpu,138.81,9.27 -crnn_mobilenet_v3_large,"(32, 128)",pytorch,gpu,12.93,1.1 -sar_resnet31,"(32, 128)",pytorch,cpu,, -sar_resnet31,"(32, 128)",pytorch,gpu,256.21,1.89 -master,"(32, 128)",pytorch,cpu,, -master,"(32, 128)",pytorch,gpu,, -crnn_vgg16_bn,"(32, 128)",tensorflow,cpu,826.57,20.15 -crnn_vgg16_bn,"(32, 128)",tensorflow,gpu,62.92,1.32 -crnn_mobilenet_v3_small,"(32, 128)",tensorflow,cpu,901.53,5.14 -crnn_mobilenet_v3_small,"(32, 128)",tensorflow,gpu,67.98,1.71 -crnn_mobilenet_v3_large,"(32, 128)",tensorflow,cpu,1487.1,26.14 -crnn_mobilenet_v3_large,"(32, 128)",tensorflow,gpu,75.67,1.34 -sar_resnet31,"(32, 128)",tensorflow,cpu,, -sar_resnet31,"(32, 128)",tensorflow,gpu,258.95,2.2 -master,"(32, 128)",tensorflow,cpu,, -master,"(32, 128)",tensorflow,gpu,1180.08,18.38 From 4c9b66e1cb52726f348a43c77b2b0a495d050291 Mon Sep 17 00:00:00 2001 From: felix Date: Tue, 13 Feb 2024 14:35:37 +0100 Subject: [PATCH 2/2] ci job --- .github/workflows/references.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/references.yml b/.github/workflows/references.yml index 17dffe4393..a6ad687a67 100644 --- a/.github/workflows/references.yml +++ b/.github/workflows/references.yml @@ -54,10 +54,10 @@ jobs: sudo apt-get update && sudo apt-get install fonts-freefont-ttf -y - if: matrix.framework == 'tensorflow' name: Train for a short epoch (TF) - run: python references/classification/train_tensorflow.py vit_s -b 32 --val-samples 1 --train-samples 1 --epochs 1 + run: python references/classification/train_tensorflow_character.py vit_s -b 32 --val-samples 1 --train-samples 1 --epochs 1 - if: matrix.framework == 'pytorch' name: Train for a short epoch (PT) - run: python references/classification/train_pytorch.py vit_s -b 32 --val-samples 1 --train-samples 1 --epochs 1 + run: python references/classification/train_pytorch_character.py vit_s -b 32 --val-samples 1 --train-samples 1 --epochs 1 train-orientation-classification: runs-on: ${{ matrix.os }}