Added Ptv Transforms Resize node to resize image data. Added workflows and PyTorch model training tutorials.
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
# Dog cat classification model training tutorial
|
||||
This tutorial covers how to use **ComfyUI Data Analysis** to train an image classification model with your own image dataset.
|
||||
We'll use a **dog and cat image dataset** created specifically for this tutorial, which is available publicly on [my GitHub repo](https://github.com/HowToSD/dog_and_cat_dataset).
|
||||
|
||||
Once you complete the tutorial, you can experiment with your own images.
|
||||
|
||||
**Disclaimer:** The model architecture is a traditional convolutional neural network (CNN) and is **not state-of-the-art**. This choice keeps the model small, enabling faster training and easier explanation.
|
||||
|
||||
---
|
||||
|
||||
## Overview of Steps
|
||||
|
||||
1. Downloading the dog and cat dataset from the GitHub repo
|
||||
2. Edit the training workflow
|
||||
3. Run the training workflow
|
||||
4. Edit the evaluation workflow
|
||||
5. Run the evaluation workflow
|
||||
|
||||
---
|
||||
|
||||
## 1. Download the Dog & Cat Dataset
|
||||
|
||||
Visit [the GitHub repo](https://github.com/HowToSD/dog_and_cat_dataset) and go to the **Releases** page.
|
||||
Click **"Source code (zip)"** to download the zip that contains all the images.
|
||||
Extract the ZIP file using an unarchiver.
|
||||
|
||||
The dataset follows this directory structure:
|
||||
|
||||
```
|
||||
dog_and_cat
|
||||
train
|
||||
cats
|
||||
dogs
|
||||
|
||||
val
|
||||
cats
|
||||
dogs
|
||||
```
|
||||
|
||||
|
||||
Take note of the **full paths** to the `train` and `val` directories, as you'll need them in the next step.
|
||||
|
||||
---
|
||||
|
||||
## 2. Editing the Training Workflow
|
||||
|
||||
Drag and drop the below file into ComfyUI:
|
||||
```
|
||||
examples/workflow/dog_cat_classification_train_model.json
|
||||
```
|
||||
Some nodes will be marked red, indicating they require edits.
|
||||
The only required changes are the **train** and **val** dataset paths.
|
||||
Replace them with the paths noted earlier.
|
||||
|
||||
---
|
||||
|
||||
## 3. Running the Training Workflow
|
||||
|
||||
Click **Queue** to start training.
|
||||
|
||||
Monitor the console for errors. If training runs smoothly, you should see output like this:
|
||||
|
||||
```
|
||||
Epoch (train) 1/20, Loss: 0.6865
|
||||
Epoch (val) 1/20, Loss: 0.6801
|
||||
Epoch (train) 2/20, Loss: 0.6216
|
||||
Epoch (val) 2/20, Loss: 0.5710
|
||||
Epoch (train) 3/20, Loss: 0.4998
|
||||
Epoch (val) 3/20, Loss: 0.4716
|
||||
Epoch (train) 4/20, Loss: 0.3827
|
||||
Epoch (val) 4/20, Loss: 0.4045
|
||||
Epoch (train) 5/20, Loss: 0.2897
|
||||
Epoch (val) 5/20, Loss: 0.3297
|
||||
Epoch (train) 6/20, Loss: 0.2243
|
||||
Epoch (val) 6/20, Loss: 0.2925
|
||||
Epoch (train) 7/20, Loss: 0.1603
|
||||
Epoch (val) 7/20, Loss: 0.2916
|
||||
Epoch (train) 8/20, Loss: 0.1102
|
||||
Epoch (val) 8/20, Loss: 0.3216
|
||||
Epoch (train) 9/20, Loss: 0.0916
|
||||
Epoch (val) 9/20, Loss: 0.2706
|
||||
Epoch (train) 10/20, Loss: 0.0522
|
||||
Epoch (val) 10/20, Loss: 0.2220
|
||||
Epoch (train) 11/20, Loss: 0.0481
|
||||
Epoch (val) 11/20, Loss: 0.2820
|
||||
Epoch (train) 12/20, Loss: 0.0228
|
||||
Epoch (val) 12/20, Loss: 0.2899
|
||||
Epoch (train) 13/20, Loss: 0.0130
|
||||
Epoch (val) 13/20, Loss: 0.3056
|
||||
Epoch (train) 14/20, Loss: 0.0137
|
||||
Epoch (val) 14/20, Loss: 0.3070
|
||||
Epoch (train) 15/20, Loss: 0.0200
|
||||
Epoch (val) 15/20, Loss: 0.2714
|
||||
Epoch (train) 16/20, Loss: 0.0313
|
||||
Epoch (val) 16/20, Loss: 0.3108
|
||||
Epoch (train) 17/20, Loss: 0.0125
|
||||
Epoch (val) 17/20, Loss: 0.3388
|
||||
Epoch (train) 18/20, Loss: 0.0174
|
||||
Epoch (val) 18/20, Loss: 0.2989
|
||||
Epoch (train) 19/20, Loss: 0.0017
|
||||
Epoch (val) 19/20, Loss: 0.3165
|
||||
Epoch (train) 20/20, Loss: 0.0009
|
||||
Epoch (val) 20/20, Loss: 0.3582
|
||||
Prompt executed in 253.64 seconds
|
||||
```
|
||||
|
||||
If you encounter an error:
|
||||
- Ensure dataset paths are correct.
|
||||
- Reduce **batch size** if your GPU runs out of memory (OOM error).
|
||||
|
||||
Once training completes, a **line chart** displaying training progress will appear at the bottom right of the canvas. You don’t need to interpret it initially.
|
||||
|
||||
---
|
||||
|
||||
## 4. Editing the Evaluation Workflow
|
||||
Now, let's verify if the model was trained correctly. In this step, we'll feed the validation data into the trained model and compute metrics to assess its performance.
|
||||
|
||||
Drag and drop the below file into ComfyUI:
|
||||
```
|
||||
examples/workflow/dog_cat_classification_eval_model.json
|
||||
```
|
||||
|
||||
into **ComfyUI**.
|
||||
|
||||
Update the **val dataset path**.
|
||||
|
||||
---
|
||||
|
||||
## 5. Running the Evaluation Workflow
|
||||
|
||||
Click **Queue**. The evaluation process runs much faster than training.
|
||||
|
||||
Check the **Accuracy** node—it should display a value around **0.9**, confirming successful model training.
|
||||
|
||||
Congratulations! You’ve successfully trained a machine learning model from scratch without writing a single line of code.
|
||||
|
||||
Now, you can use your own images to train the model in the same way.
|
||||
@@ -0,0 +1,49 @@
|
||||
# Model Training
|
||||
|
||||
Experimental PyTorch model training has been added.
|
||||
No coding is required. Training is as simple as a single click!
|
||||
Currently, only classification is supported.
|
||||
|
||||
The system is designed to be modular. For example, to switch from a linear model to a convolutional model, you only need to replace the model node (see screenshot below).
|
||||
|
||||
You can choose to:
|
||||
* Use your own images
|
||||
* Use a public dataset
|
||||
|
||||
## Using Your Own Images
|
||||
|
||||
Check out [the dog and cat classification tutorial](dog_cat_classification_model_training.md).
|
||||
|
||||
## Public Datasets
|
||||
|
||||
Currently, only Fashion MNIST has been tested. Other public datasets have not been verified yet, though they may work.
|
||||
If you try one and it doesn't work, please create an issue so I can investigate adding support.
|
||||
|
||||
To use the Fashion MNIST dataset, simply drag and drop the workflow files below into ComfyUI. The model will be downloaded automatically.
|
||||
|
||||
Linear model
|
||||
* Training: examples/fashion_mnist_train.json
|
||||
* Evaluation: examples/fashion_mnist_eval.json
|
||||
|
||||
Convolutional model
|
||||
* Training: examples/fashion_mnist_train_conv.json
|
||||
* Evaluation: examples/fashion_mnist_eval_conv.json
|
||||
|
||||
These training workflows train a FashionMNIST model from scratch effortlessly.
|
||||
|
||||
### Training workflow
|
||||
**Linear model**
|
||||

|
||||
|
||||
**Conv model**
|
||||

|
||||
|
||||
*Close up of the conv node*
|
||||

|
||||
|
||||
### Eval workflow
|
||||
**Linear model**
|
||||

|
||||
|
||||
**Conv model**
|
||||

|
||||
@@ -276,6 +276,7 @@
|
||||
| [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 Image Folder Dataset](ptv_image_folder_dataset.md) | A Torchvision ImageFolder Dataset class wrapper. |
|
||||
| [Ptv Transforms Resize](ptv_transforms_resize.md) | Resizes and transforms elements of dataset to PyTorch tensors. |
|
||||
| [Ptv Transforms To Tensor](ptv_transforms_to_tensor.md) | Transforms elements of dataset to PyTorch tensors. |
|
||||
## PyTorch wrapper - Transform
|
||||
| Node | Description |
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Ptv Transforms Resize
|
||||
Resizes and transforms elements of dataset to PyTorch tensors.
|
||||
|
||||
## Input
|
||||
| Name | Data type |
|
||||
|---|---|
|
||||
| height | Int |
|
||||
| width | Int |
|
||||
|
||||
## Output
|
||||
| Data type |
|
||||
|---|
|
||||
| Ptvtransform |
|
||||
|
||||
<HR>
|
||||
Category: PyTorch wrapper - Training
|
||||
|
||||
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
|
||||
Reference in New Issue
Block a user