Added lr scheduler nodes and cifar10 workflows.

This commit is contained in:
HowToSD
2025-03-12 14:57:44 -07:00
parent 635c97c037
commit acb5d9f820
20 changed files with 770 additions and 6 deletions
+8 -3
View File
@@ -35,10 +35,15 @@ Convolutional model
* Evaluation: examples/workflows/fashion_mnist_eval_conv.json
ResNet model
* Training: examples/workflows/cifar10_train_v8.json
* Evaluation: examples/workflows/cifar10_eval_v8.json
**Training**
* examples/workflows/cifar10_train_v8.json
* examples/workflows/cifar10_train_v11_2nd_run.json
**Evaluation**
* examples/workflows/cifar10_eval_v8.json
* examples/workflows/cifar10_eval_v11_2nd_run.json
This model achieved 93.12% accuracy on CIFAR-10. While not state-of-the-art, it is a strong result. Due to random initialization, data augmentation, and dataset shuffling, accuracy may vary slightly between runs. If your accuracy is significantly lower, consider running it multiple times or checking for potential issues in the training setup.
This train_v8 model achieved 93.12% accuracy & train_v11_2nd_run model achieved 94.34 on CIFAR-10 (first run was 94.27%). train_v11_2nd_run added cosine annealing learning rate scheduler while train_v8 used fixed learning rate. While not state-of-the-art, these are strong results. Due to random initialization, data augmentation, and dataset shuffling, accuracy may vary slightly between runs. If your accuracy is significantly lower, consider running it multiple times or checking for potential issues in the training setup.
**Note: Before you try these workflows, please install ComfyUI-Data-Analysis extension.**
+4
View File
@@ -136,10 +136,14 @@
| [Pt Load Model](pt_load_model.md) | A wrapper class for saving a PyTorch model. |
| [Pt Predict Classification Model](pt_predict_classification_model.md) | Performs inference on input data. |
| [Pt Train Classification Model](pt_train_classification_model.md) | Trains a classification model using a given dataset, optimizer, and number of epochs. |
| [Pt Train Classification Model Lr](pt_train_classification_model_lr.md) | Trains a classification model using a given dataset, optimizer, and number of epochs with learning rate decay. |
| [Ptn Conv Model](ptn_conv_model.md) | A convolutional model consisting of multiple convolutional layers. |
| [Ptn Linear Model](ptn_linear_model.md) | A linear model consisting of dense layers. |
| [Ptn Resnet Model](ptn_resnet_model.md) | A Resnet model consisting of multiple Resnet layers. |
| [Pto Adam](pto_adam.md) | Instantiates the Adam optimizer. |
| [Pto Lr Scheduler Cosine Annealing](pto_lr_scheduler_cosine_annealing.md) | Creates a cosine annealing learning rate scheduler for an optimizer. |
| [Pto Lr Scheduler Reduce On Plateau](pto_lr_scheduler_reduce_on_plateau.md) | Creates a reduce-on-plateau learning rate scheduler for an optimizer. |
| [Pto Lr Scheduler Step](pto_lr_scheduler_step.md) | Creates a StepLR learning rate scheduler for an optimizer. |
| [Ptv Dataset](ptv_dataset.md) | A Torchvision Dataset class wrapper. |
| [Ptv Dataset Len](ptv_dataset_len.md) | A wrapper class that calls Python len on a dataset. |
| [Ptv Dataset Loader](ptv_dataset_loader.md) | A node to combine the dataset and data loader into a single node. |
@@ -0,0 +1,31 @@
# Pt Train Classification Model Lr
Trains a classification model using a given dataset, optimizer, and number of epochs with learning rate decay.
early_stopping_rounds: Specifies the number of rounds to monitor the evaluation loss when early_stopping is enabled and validation data is specified. If the loss does not decrease compared to the current best loss within this period, training will be stopped.
output_best_val_model: Whether to outputs the model with the best val loss or the model from the last epoch.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| train_loader | Ptdataloader |
| optimizer | Ptoptimizer |
| scheduler | Ptlrscheduler |
| epochs | Int |
| use_gpu | Boolean |
| early_stopping | Boolean |
| early_stopping_rounds | Int |
| output_best_val_model | Boolean |
| val_loader | Ptdataloader |
## Output
| Data type |
|---|
| Ptmodel |
| Tensor |
| Tensor |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,49 @@
# Pto Lr Scheduler Cosine Annealing
Creates a cosine annealing learning rate scheduler for an optimizer.
https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html
lists:
eta_t = eta_min + (1/2) * (eta_max - eta_min) * (1 + cos((t_cur / t_max) * pi))
eta_min is set to 0 by default, so the equation simplifies to:
eta_t = (1/2) * eta_max * (1 + cos((t_cur / t_max) * pi))
When t_cur = 0:
(1 + cos((t_cur / t_max) * pi)) evaluates to (1 + cos(0 * pi)) = (1 + 1) = 2
When t_cur = t_max:
(1 + cos((t_cur / t_max) * pi)) evaluates to (1 + cos(1 * pi)) = (1 - 1) = 0
Therefore, eta_t value changes as follows:
* Starts from (1/2) * eta_max * 2, which simplifies to eta_max
* Ends at 0
Parameters
**optimizer**
(torch.optim.Optimizer) – Wrapped optimizer whose learning rate needs scheduling.
**num_epochs**
(int) – Number of epochs. This maps to the T_max parameter for CosineAnnealingLR internally.
**minimum_lr**
(float) – Minimum learning rate.
## Input
| Name | Data type |
|---|---|
| optimizer | Ptoptimizer |
| num_epochs | Int |
| minimum_lr | Float |
## Output
| Data type |
|---|
| Ptlrscheduler |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,30 @@
# Pto Lr Scheduler Reduce On Plateau
Creates a reduce-on-plateau learning rate scheduler for an optimizer.
Parameters
**optimizer**
(torch.optim.Optimizer) – Wrapped optimizer whose learning rate needs scheduling.
**grace_period**
(int) – Number of epochs to monitor the val loss reduction. If loss does not decrease within grace period epochs, learning rate will be reduced by multiplying the gamma. E.g. if gamma is set to 0.5, new learning rate will be 0.5 * current learning rate.
**gamma**
(float) – Learning rate multiplier to be applied when grace period is up.
## Input
| Name | Data type |
|---|---|
| optimizer | Ptoptimizer |
| grace_period | Int |
| gamma | Float |
## Output
| Data type |
|---|
| Ptlrscheduler |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+30
View File
@@ -0,0 +1,30 @@
# Pto Lr Scheduler Step
Creates a StepLR learning rate scheduler for an optimizer.
Parameters
**optimizer**
(torch.optim.Optimizer) – Wrapped optimizer whose learning rate needs scheduling.
**step_size**
(int) – Period of learning rate decay.
**gamma**
(float) – Multiplicative factor of learning rate decay.
## Input
| Name | Data type |
|---|---|
| optimizer | Ptoptimizer |
| step_size | Int |
| gamma | Float |
## Output
| Data type |
|---|
| Ptlrscheduler |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.