Ptv Image Folder Dataset
Train a classifier on your own photos
- transform
- PTVDATASET
This is the node behind the pack's "train on your images" story - the dog-vs-cat classifier tutorial, and by extension anything where you have folders of photos and want a CNN that tells them apart. It's the direct replacement for Ptv Dataset Loader when the dataset is your own disk instead of a torchvision download. If you've ever wanted a custom image classifier trained entirely inside ComfyUI, this is the entry node.
How it works
It's a thin wrapper around torchvision's ImageFolder. That class imposes one iron rule on your directory layout: the root folder must contain one subfolder per class, and the subfolder name is the label. For the pack's dog/cat tutorial:
dog_and_cat
train
cats
dogs
val
cats
dogs
Point root at train, and every image under cats/ gets label 0, every image under dogs/ label 1. No CSV, no annotation file, no mapping table - the folder structure is the ground truth. Each sample comes out as (image, label) and the label is derived automatically from which subfolder it lived in.
The inputs that matter
- root - relative paths resolve under the pack's
datasets/folder; absolute paths work too. - transform - an optional
PTVTRANSFORMfrom the pack's transform nodes (Ptv Transforms To Tensor,Ptv Transforms Resize,Ptv Transforms Data Augment). Leave it empty and you get raw PIL images, which most trainers won't thank you for - wire inTo Tensorat minimum.
Output is a PTVDATASET, which flows into Pt Data Loader and then a training node like Pt Train Classification Model.
The layout gotchas
- Class subfolders or nothing. A flat folder of images fails immediately -
ImageFolderhas no classes to infer. If you get "Found 0 files or directories", your structure is wrong. - Don't forget
transform. The model needs tensors of a consistent size. The tutorial's expectation is you chainPtv Transforms Resize(fixedheight/width) or the data-augment pipeline before the trainer. A bare dataset works for MNIST-style tensors but not for arbitrary photo folders. - Relative root is relative to the pack, not to ComfyUI's
input/folder - the classic first-run confusion when paths "should" work.
Install
Same as every node in this pack:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI, or search "ComfyUI-Pt-Wrapper" in ComfyUI Manager.
Common issues
- "Found 0 images in folders" - wrong root, or no class subfolders.
- Trainer errors on image shape - you skipped the resize/ToTensor transform, so images arrive as varying-size PIL objects.
- OOM - your photos are huge; resize them (e.g. 256×256) in the transform before they ever hit the model.
The pack's own tutorial downloads a ready-made HowToSD/dog_and_cat dataset from Hugging Face, so you can run the whole pipeline before pointing it at your own photos. Do that once, then swap in your folders.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| root | STRING | — | |
| transformopt | PTVTRANSFORM | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTVDATASET | PTVDATASET | — |