From 5e6a03c79cce8dc748a504bb3d975692bf220aa9 Mon Sep 17 00:00:00 2001 From: Bjarten Date: Sun, 10 Nov 2024 11:13:16 +0100 Subject: [PATCH 1/3] fix: tag push --- .github/workflows/release.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5ff0a08..e227bb1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,4 +22,8 @@ jobs: - name: Python Semantic Release uses: python-semantic-release/python-semantic-release@v9.12.0 with: - github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github_token: ${{ secrets.GITHUB_TOKEN }} + tag_format: "v{version}" + commit: true + push: true + tag: true \ No newline at end of file From c5e84feb9b20f994d15412abcb0deb8d5dd34af8 Mon Sep 17 00:00:00 2001 From: Bjarten Date: Sun, 10 Nov 2024 12:01:14 +0100 Subject: [PATCH 2/3] fix: update versions --- pyproject.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e9b9e6..57171cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "early-stopping-pytorch" -dynamic = ["version"] +version = "1.0.1" description = "A PyTorch utility package for Early Stopping" readme = "README.md" authors = [ @@ -16,11 +16,9 @@ dependencies = [ "torch>=1.9.0" ] -[tool.setuptools.dynamic] -version = {attr = "early_stopping_pytorch.__version__"} - [tool.semantic_release] version_variable = ["early_stopping_pytorch/__init__.py:__version__"] +version_toml = ["pyproject.toml:project.version"] # Add this line branch = "main" upload_to_pypi = false build_command = "pip install build && python -m build" From 7be6453a3334fc6297752a1835ba00e303caf0d6 Mon Sep 17 00:00:00 2001 From: Bjarten Date: Sun, 10 Nov 2024 12:01:33 +0100 Subject: [PATCH 3/3] docs: update readme --- README.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0ecceb4..0fd1ba7 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,17 @@ Early stopping is a form of regularization used to avoid overfitting on the trai Underneath is a plot from the example notebook, which shows the last checkpoint made by the EarlyStopping object, right before the model started to overfit. It had patience set to 20. -![Loss plot](loss_plot.png?raw=true) +![Loss Plot](https://raw.githubusercontent.com/Bjarten/early-stopping-pytorch/main/loss_plot.png) -## Usage +## Installation + +### Option 1: Install from PyPI (Recommended) +```bash +pip install early-stopping-pytorch +``` + +### Option 2: Install from Source +For development or if you want the latest unreleased changes: ### 1. Clone the Repository ```bash @@ -31,10 +39,27 @@ Install the package locally in editable mode so you can use it immediately: pip install -e . ``` -### 5. Use the Package -You can now import and use the package in your Python code: +## Usage + ```python from early_stopping_pytorch import EarlyStopping + +# Initialize early stopping object +early_stopping = EarlyStopping(patience=7, verbose=True) + +# In your training loop: +for epoch in range(num_epochs): + # ... training code ... + val_loss = ... # calculate validation loss + + # Early stopping call + early_stopping(val_loss, model) + if early_stopping.early_stop: + print("Early stopping triggered") + break ``` + +For a complete example, see the [MNIST Early Stopping Example Notebook](MNIST_Early_Stopping_example.ipynb). + ## References The ```EarlyStopping``` class in ```early_stopping_pytorch/early_stopping.py``` is inspired by the [ignite EarlyStopping class](https://github.com/pytorch/ignite/blob/master/ignite/handlers/early_stopping.py).