Skip to content

fix: improve release process and documentation #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_format: "v{version}"
commit: true
push: true
tag: true
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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"
Expand Down