랭킹으로 돌아가기

Bjarten/early-stopping-pytorch

Jupyter Notebook

Early stopping for PyTorch

pytorchearly-stoppingearlystoppingpytorch-tutorialpythonmnistregularizationtutorial
스타 성장
스타
1.3k
포크
289
주간 성장
이슈
0
5001k
2018년 12월2021년 6월2024년 1월2026년 7월
README

Early Stopping for PyTorch

Early stopping is a form of regularization used to avoid overfitting on the training dataset. Early stopping keeps track of the validation loss, if the loss stops decreasing for several epochs in a row the training stops. The EarlyStopping class in early_stopping_pytorch/early_stopping.py is used to create an object to keep track of the validation loss while training a PyTorch model. It will save a checkpoint of the model each time the validation loss decrease. We set the patience argument in the EarlyStopping class to how many epochs we want to wait after the last time the validation loss improved before breaking the training loop. There is a simple example of how to use the EarlyStopping class in the MNIST_Early_Stopping_example notebook.

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

Installation

pip install early-stopping-pytorch

Option 2: Install from Source

For development or if you want the latest unreleased changes:

1. Clone the Repository

git clone https://github.com/your_username/early-stopping-pytorch.git
cd early-stopping-pytorch

2. Set Up the Virtual Environment

Run the setup script to create a virtual environment and install all necessary dependencies.

./setup_dev_env.sh

3. Activate the Virtual Environment

Activate the virtual environment:

source dev-venv/bin/activate

4. Install the Package in Editable Mode

Install the package locally in editable mode so you can use it immediately:

pip install -e .

Usage

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.

Citation

If you find this package useful in your research, please consider citing it as:

@misc{early_stopping_pytorch,
  author = {Bjarte Mehus Sunde},
  title = {early-stopping-pytorch: A PyTorch utility package for Early Stopping},
  year = {2024},
  url = {https://github.com/Bjarten/early-stopping-pytorch},
}

References

The EarlyStopping class in early_stopping_pytorch/early_stopping.py is inspired by the ignite EarlyStopping class.

관련 저장소
AUTOMATIC1111/stable-diffusion-webui

Stable Diffusion web UI

PythonPyPIGNU Affero General Public License v3.0deep-learningdiffusion
164.3k30.4k
huggingface/transformers

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

PythonPyPIApache License 2.0nlpnatural-language-processing
huggingface.co/transformers
162.8k34k
Comfy-Org/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.

PythonPyPIGNU General Public License v3.0stable-diffusionpytorch
comfy.org
121.7k14.3k
rasbt/LLMs-from-scratch

Implement a ChatGPT-like LLM in PyTorch from scratch, step by step

Jupyter NotebookOthergptlarge-language-models
amzn.to/4fqvn0D
99.5k15.3k
vllm-project/vllm

A high-throughput and memory-efficient inference and serving engine for LLMs

PythonPyPIApache License 2.0gptllm
vllm.ai
86.8k19.7k
comfyanonymous/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.

PythonPyPIGNU General Public License v3.0stable-diffusionpytorch
comfy.org
70.2k7.6k
labmlai/annotated_deep_learning_paper_implementations

🧑‍🏫 60+ Implementations/tutorials of deep learning papers with side-by-side notes 📝; including transformers (original, xl, switch, feedback, vit, ...), optimizers (adam, adabelief, sophia, ...), gans(cyclegan, stylegan2, ...), 🎮 reinforcement learning (ppo, dqn), capsnet, distillation, ... 🧠

PythonPyPIMIT Licensedeep-learningdeep-learning-tutorial
nn.labml.ai
67.2k6.7k
keras-team/keras

Deep Learning for humans

PythonPyPIApache License 2.0deep-learningtensorflow
keras.io
64.2k19.7k
CorentinJ/Real-Time-Voice-Cloning

Clone a voice in 5 seconds to generate arbitrary speech in real-time

PythonPyPIOtherdeep-learningpytorch
60k9.4k
ultralytics/ultralytics

Ultralytics YOLO26, YOLO11, YOLOv8 — object detection, instance segmentation, semantic segmentation, image classification, pose estimation, object tracking

PythonPyPIGNU Affero General Public License v3.0ultralyticsyolov8
platform.ultralytics.com
59.7k11.4k
ultralytics/yolov5

Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.

PythonPyPIGNU Affero General Public License v3.0yolov5object-detection
docs.ultralytics.com/yolov5/
57.7k17.5k
GokuMohandas/Made-With-ML

Learn how to develop, deploy and iterate on production-grade ML applications.

Jupyter NotebookMIT Licensemachine-learningdeep-learning
madewithml.com
48.8k7.7k