From b0d2728b6bc930b53e91049efa3691c219533938 Mon Sep 17 00:00:00 2001 From: Olivier Dulcy <106678676+odulcy-mindee@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:08:54 +0100 Subject: [PATCH] feat: :sparkles: tqdm slack (#1837) * feat: :sparkles: tqdm slack * fix * docs: :pencil2: update README.md --- references/classification/README.md | 10 ++++++++++ references/classification/train_pytorch_character.py | 6 +++++- references/classification/train_pytorch_orientation.py | 6 +++++- .../classification/train_tensorflow_character.py | 6 +++++- .../classification/train_tensorflow_orientation.py | 6 +++++- references/detection/README.md | 9 +++++++++ references/detection/evaluate_pytorch.py | 6 +++++- references/detection/evaluate_tensorflow.py | 6 +++++- references/detection/train_pytorch.py | 6 +++++- references/detection/train_pytorch_ddp.py | 6 +++++- references/detection/train_tensorflow.py | 6 +++++- references/recognition/README.md | 10 ++++++++++ references/recognition/train_pytorch.py | 6 +++++- references/recognition/train_pytorch_ddp.py | 6 +++++- references/recognition/train_tensorflow.py | 6 +++++- references/requirements.txt | 1 + 16 files changed, 90 insertions(+), 12 deletions(-) diff --git a/references/classification/README.md b/references/classification/README.md index 885cc0b565..8925bde8d1 100644 --- a/references/classification/README.md +++ b/references/classification/README.md @@ -54,6 +54,16 @@ Each path must lead to a folder where the images are stored. For example: └── ... ``` +## Slack Logging with tqdm + +To enable Slack logging using `tqdm`, you need to set the following environment variables: + +- `TQDM_SLACK_TOKEN`: the Slack Bot Token +- `TQDM_SLACK_CHANNEL`: you can retrieve it using `Right Click on Channel > Copy > Copy link`. You should get something like `https://xxxxxx.slack.com/archives/yyyyyyyy`. Keep only the `yyyyyyyy` part. + +You can follow this page on [how to create a Slack App](https://api.slack.com/quickstart). + + ## Advanced options Feel free to inspect the multiple script option to customize your training to your own needs! diff --git a/references/classification/train_pytorch_character.py b/references/classification/train_pytorch_character.py index b6e7f2ebfb..51b390f7b1 100644 --- a/references/classification/train_pytorch_character.py +++ b/references/classification/train_pytorch_character.py @@ -27,7 +27,11 @@ RandomPhotometricDistort, RandomRotation, ) -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import VOCABS, CharacterGenerator diff --git a/references/classification/train_pytorch_orientation.py b/references/classification/train_pytorch_orientation.py index 498c9fd919..b9e0b18920 100644 --- a/references/classification/train_pytorch_orientation.py +++ b/references/classification/train_pytorch_orientation.py @@ -26,7 +26,11 @@ RandomPerspective, RandomPhotometricDistort, ) -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import OrientationDataset diff --git a/references/classification/train_tensorflow_character.py b/references/classification/train_tensorflow_character.py index 4b61619165..f668e769dd 100644 --- a/references/classification/train_tensorflow_character.py +++ b/references/classification/train_tensorflow_character.py @@ -19,7 +19,11 @@ import numpy as np import tensorflow as tf from tensorflow.keras import Model, mixed_precision, optimizers -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr.models import login_to_hub, push_to_hf_hub diff --git a/references/classification/train_tensorflow_orientation.py b/references/classification/train_tensorflow_orientation.py index fc386977c9..731b11ae14 100644 --- a/references/classification/train_tensorflow_orientation.py +++ b/references/classification/train_tensorflow_orientation.py @@ -19,7 +19,11 @@ import numpy as np import tensorflow as tf from tensorflow.keras import Model, mixed_precision, optimizers -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr.models import login_to_hub, push_to_hf_hub diff --git a/references/detection/README.md b/references/detection/README.md index 884437e8e2..883404bc35 100644 --- a/references/detection/README.md +++ b/references/detection/README.md @@ -107,6 +107,15 @@ labels.json } ``` +## Slack Logging with tqdm + +To enable Slack logging using `tqdm`, you need to set the following environment variables: + +- `TQDM_SLACK_TOKEN`: the Slack Bot Token +- `TQDM_SLACK_CHANNEL`: you can retrieve it using `Right Click on Channel > Copy > Copy link`. You should get something like `https://xxxxxx.slack.com/archives/yyyyyyyy`. Keep only the `yyyyyyyy` part. + +You can follow this page on [how to create a Slack App](https://api.slack.com/quickstart). + ## Advanced options Feel free to inspect the multiple script option to customize your training to your own needs! diff --git a/references/detection/evaluate_pytorch.py b/references/detection/evaluate_pytorch.py index f717d8bb93..1a0a9b32ab 100644 --- a/references/detection/evaluate_pytorch.py +++ b/references/detection/evaluate_pytorch.py @@ -17,7 +17,11 @@ import torch from torch.utils.data import DataLoader, SequentialSampler from torchvision.transforms import Normalize -from tqdm import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import datasets from doctr import transforms as T diff --git a/references/detection/evaluate_tensorflow.py b/references/detection/evaluate_tensorflow.py index d547aaad1e..b7f031db6c 100644 --- a/references/detection/evaluate_tensorflow.py +++ b/references/detection/evaluate_tensorflow.py @@ -19,7 +19,11 @@ import tensorflow as tf from tensorflow.keras import mixed_precision -from tqdm import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm gpu_devices = tf.config.list_physical_devices("GPU") if any(gpu_devices): diff --git a/references/detection/train_pytorch.py b/references/detection/train_pytorch.py index f11694cf9d..2729d64f33 100644 --- a/references/detection/train_pytorch.py +++ b/references/detection/train_pytorch.py @@ -19,7 +19,11 @@ from torch.optim.lr_scheduler import CosineAnnealingLR, MultiplicativeLR, OneCycleLR, PolynomialLR from torch.utils.data import DataLoader, RandomSampler, SequentialSampler from torchvision.transforms.v2 import Compose, Normalize, RandomGrayscale, RandomPhotometricDistort -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import DetectionDataset diff --git a/references/detection/train_pytorch_ddp.py b/references/detection/train_pytorch_ddp.py index 87b7bd8d5c..b41cdeec4d 100644 --- a/references/detection/train_pytorch_ddp.py +++ b/references/detection/train_pytorch_ddp.py @@ -25,7 +25,11 @@ from torch.utils.data import DataLoader, SequentialSampler from torch.utils.data.distributed import DistributedSampler from torchvision.transforms.v2 import Compose, Normalize, RandomGrayscale, RandomPhotometricDistort -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import DetectionDataset diff --git a/references/detection/train_tensorflow.py b/references/detection/train_tensorflow.py index d9aada677a..8b2e44a46a 100644 --- a/references/detection/train_tensorflow.py +++ b/references/detection/train_tensorflow.py @@ -20,7 +20,11 @@ import numpy as np import tensorflow as tf from tensorflow.keras import Model, mixed_precision, optimizers -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr.models import login_to_hub, push_to_hf_hub diff --git a/references/recognition/README.md b/references/recognition/README.md index 9087cbc210..84d3268599 100644 --- a/references/recognition/README.md +++ b/references/recognition/README.md @@ -77,6 +77,16 @@ The order of entries in the json does not matter. When typing your labels, be aware that the VOCAB doesn't handle spaces. Also make sure your `labels.json` file is using UTF-8 encoding. +## Slack Logging with tqdm + +To enable Slack logging using `tqdm`, you need to set the following environment variables: + +- `TQDM_SLACK_TOKEN`: the Slack Bot Token +- `TQDM_SLACK_CHANNEL`: you can retrieve it using `Right Click on Channel > Copy > Copy link`. You should get something like `https://xxxxxx.slack.com/archives/yyyyyyyy`. Keep only the `yyyyyyyy` part. + +You can follow this page on [how to create a Slack App](https://api.slack.com/quickstart). + + ## Advanced options Feel free to inspect the multiple script option to customize your training to your own needs! diff --git a/references/recognition/train_pytorch.py b/references/recognition/train_pytorch.py index 434b599a9b..0f69151edb 100644 --- a/references/recognition/train_pytorch.py +++ b/references/recognition/train_pytorch.py @@ -25,7 +25,11 @@ RandomPerspective, RandomPhotometricDistort, ) -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import VOCABS, RecognitionDataset, WordGenerator diff --git a/references/recognition/train_pytorch_ddp.py b/references/recognition/train_pytorch_ddp.py index 54ab92c265..19e9b1a1cf 100644 --- a/references/recognition/train_pytorch_ddp.py +++ b/references/recognition/train_pytorch_ddp.py @@ -29,7 +29,11 @@ RandomPerspective, RandomPhotometricDistort, ) -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr import transforms as T from doctr.datasets import VOCABS, RecognitionDataset, WordGenerator diff --git a/references/recognition/train_tensorflow.py b/references/recognition/train_tensorflow.py index 4a2180f29e..b843b832cd 100644 --- a/references/recognition/train_tensorflow.py +++ b/references/recognition/train_tensorflow.py @@ -20,7 +20,11 @@ import numpy as np import tensorflow as tf from tensorflow.keras import Model, mixed_precision, optimizers -from tqdm.auto import tqdm + +if os.getenv("TQDM_SLACK_TOKEN") and os.getenv("TQDM_SLACK_CHANNEL"): + from tqdm.contrib.slack import tqdm +else: + from tqdm.auto import tqdm from doctr.models import login_to_hub, push_to_hf_hub diff --git a/references/requirements.txt b/references/requirements.txt index 5ded75a3b8..90e24543de 100644 --- a/references/requirements.txt +++ b/references/requirements.txt @@ -1,5 +1,6 @@ -e . tqdm +slack-sdk wandb>=0.10.31 clearml>=1.11.1 matplotlib>=3.1.0