Added experimental PyTorch model training.

This commit is contained in:
HowToSD
2025-03-03 18:39:52 -08:00
parent 62e4f6efb8
commit 11d3c9490c
40 changed files with 1649 additions and 4 deletions
+13
View File
@@ -113,6 +113,7 @@
| [Pandas Load JSON](pandas_load_json.md) | Loads JSON files into a pandas DataFrame. |
| [Pandas Save CSV](pandas_save_csv.md) | Saves a PandasDataFrame to a CSV file. |
| [Pandas Save JSON](pandas_save_json.md) | Saves a PandasDataFrame to a JSON file. |
| [Pt Save Model](pt_save_model.md) | A wrapper class for saving a PyTorch model. |
## Math
| Node | Description |
| --- | --- |
@@ -257,6 +258,18 @@
| [Pt To Latent](pt_to_latent.md) | Casts a PyTorch tensor as a latent tensor. |
| [Pt To Numpy](pt_to_numpy.md) | Converts PyTorch tensor to NumPy ndarray. |
| [Pt To Rgb Tensors](pt_to_rgb_tensors.md) | Splits a PyTorch tensor into R, G, and B tensors. |
| [Pto Adam](pto_adam.md) | Converts PyTorch tensor to NumPy ndarray. |
## PyTorch wrapper - Training
| Node | Description |
| --- | --- |
| [Pt Data Loader](pt_data_loader.md) | Loads data from a dataset node and creates a PyTorch DataLoader. |
| [Pt Evaluate Classification Model](pt_evaluate_classification_model.md) | Performs inference on test data and computes evaluation metrics. |
| [Pt Load Model](pt_load_model.md) | A wrapper class for saving a PyTorch model. |
| [Pt Train Classification Model](pt_train_classification_model.md) | Trains a classification model using a given dataset, optimizer, and number of epochs. |
| [Ptn Linear Model](ptn_linear_model.md) | A linear model consisting of dense layers. |
| [Ptv Dataset](ptv_dataset.md) | A Torchvision Dataset class wrapper. |
| [Ptv Dataset Loader](ptv_dataset_loader.md) | A node to combine the dataset and data loader into a single node. |
| [Ptv Transforms To Tensor](ptv_transforms_to_tensor.md) | Transforms elements of dataset to PyTorch tensors. |
## PyTorch wrapper - Transform
| Node | Description |
| --- | --- |
+29
View File
@@ -0,0 +1,29 @@
# Pt Data Loader
Loads data from a dataset node and creates a PyTorch DataLoader.
**dataset**
Connect a PtvDataset node that provides the dataset.
**batch size**
Specifies the number of samples per batch.
**shuffle**
If True, shuffles the dataset before each epoch.
## Input
| Name | Data type |
|---|---|
| dataset | Ptvdataset |
| batch_size | Int |
| shuffle | Boolean |
| parameters | String |
## Output
| Data type |
|---|
| Ptdataloader |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,23 @@
# Pt Evaluate Classification Model
Performs inference on test data and computes evaluation metrics.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| data_loader | Ptdataloader |
| use_gpu | Boolean |
## Output
| Data type |
|---|
| Float |
| Float |
| Float |
| Float |
| Int |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+18
View File
@@ -0,0 +1,18 @@
# Pt Load Model
A wrapper class for saving a PyTorch model.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| model_path | String |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+18
View File
@@ -0,0 +1,18 @@
# Pt Save Model
A wrapper class for saving a PyTorch model.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| model_path | String |
## Output
| Data type |
|---|
| String |
<HR>
Category: IO
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,24 @@
# Pt Train Classification Model
Trains a classification model using a given dataset, optimizer, and number of epochs.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| train_loader | Ptdataloader |
| optimizer | Ptoptimizer |
| epochs | Int |
| use_gpu | 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.
+34
View File
@@ -0,0 +1,34 @@
# Ptn Linear Model
A linear model consisting of dense layers.
### Fields:
- `dim_list`: A comma-separated string representing layer dimensions.
It should contain the input dimension for the first layer and the output dimensions
for all layers.
Example for a two-layer network:
- Input data: 784
- Layer 1: 784 → 128
- Layer 2: 128 → 10
- Specify `"784, 128, 10"`
- `bias_list`: A comma-separated string representing bias usage (True/False) per layer.
- `num_layers`: The number of layers in the model.
## Input
| Name | Data type |
|---|---|
| dim_list | String |
| bias_list | String |
| num_layers | Int |
## Output
| Data type |
|---|
| Ptmodel |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+20
View File
@@ -0,0 +1,20 @@
# Dense Model
A multi-layer dense neural network with ReLU activation after each dense layer, except for the final layer.
Args:
dim_list (List[int]): List of feature dimensions. Should be of length `num_layers + 1`.
bias_list (List[bool]): List indicating whether each layer should have a bias.
num_layers (int): Number of layers in the model.
Example:
For a three-layer network:
- Layer 1: input -> output1
- Layer 2: output1 -> output2
- Layer 3: output2 -> output3
`dim_list = [input_dim, output1_dim, output2_dim, output3_dim]`
<HR>
Category: Miscellaneous
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+20
View File
@@ -0,0 +1,20 @@
# Pto Adam
Converts PyTorch tensor to NumPy ndarray.
## Input
| Name | Data type |
|---|---|
| model | Ptmodel |
| learning_rate | Float |
| beta1 | Float |
| beta2 | Float |
## Output
| Data type |
|---|
| Ptoptimizer |
<HR>
Category: PyTorch wrapper - Tensor data conversion
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+51
View File
@@ -0,0 +1,51 @@
# Ptv Dataset
A Torchvision Dataset class wrapper.
Parameters
**name**
Specify a dataset class name such as MNIST, FashionMNIST in string.
This will be converted to a dataset class internally.
**download**
Set to True if you want to download.
**root**
Specify the root directory of the downloaded dataset relative to the
dataset directory of this extension, or specify the absolute path.
If you leave as a blank, the dataset will be downloaded under the `datasets` directory
of this extension.
**transform**
Data transforms e.g. transform to PyTorch tensor, normalize image.
Plug in the PTV Transforms node that contains Torchvision Transforms functionality.
**parameters**
Specify other parameters in Python dict format.
For example, if you want to set Train parameter to True to download the train set, specify:
```
{"train": True}
```
or if you want to download the test set, specify:
```
{"train": False}
```
## Input
| Name | Data type |
|---|---|
| name | String |
| download | Boolean |
| root | String |
| transform | Ptvtransform |
| parameters | String |
## Output
| Data type |
|---|
| Ptvdataset |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+60
View File
@@ -0,0 +1,60 @@
# Ptv Dataset Loader
A node to combine the dataset and data loader into a single node.
Transform is internally called to convert input data to PyTorch tensors.
Parameters
**name**
Specify the dataset class name such as MNIST, FashionMNIST in string.
This will be converted to a dataset class internally.
**download**
Set to True if you want to download.
**root**
Specify the root directory of the downloaded dataset relative to the
dataset directory of this extension, or specify the absolute path.
If you leave as a blank, the dataset will be downloaded under the `datasets` directory
of this extension.
**batch_size**
The number of samples per batch.
**shuffle**
If True, shuffles the dataset before each epoch.
**dataset parameters**
Specify other parameters in Python dict format.
For example, if you want to set Train parameter to True to download the train set, specify:
```
{"train": True}
```
or if you want to download the test set, specify:
```
{"train": False}
```
**load parameters**
Additional parameters in Python dictionary format.
## Input
| Name | Data type |
|---|---|
| name | String |
| download | Boolean |
| root | String |
| batch_size | Int |
| shuffle | Boolean |
| dataset_parameters | String |
| load_parameters | String |
## Output
| Data type |
|---|
| Ptdataloader |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,12 @@
# Ptv Transforms To Tensor
Transforms elements of dataset to PyTorch tensors.
## Output
| Data type |
|---|
| Ptvtransform |
<HR>
Category: PyTorch wrapper - Training
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.