Image-text dataset loader loses captions when the image extension occurs earlier in the path
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Expected Behavior
`Load Image-Text Dataset from Folder` should read the `.txt` file beside each image, including when an image extension also appears in a directory name or earlier in the filename.
### Actual Behavior
At `4989cdd95487531b50438c6a091dffa06e4af4b2`, `train.png/photo.png` loads the image but returns an empty caption even though `train.png/photo.txt` exists. `photo.png.crop.png` with `photo.png.crop.txt` has the same problem. The caption lookup replaces every occurrence of `.png`, so it instead looks for `train.txt/photo.txt` or `photo.txt.crop.txt`.
### Steps to Reproduce
Run this script from a ComfyUI checkout with its Python dependencies installed. It calls the built-in node directly; no custom nodes, server, model, or GPU are loaded.
```python
import tempfile
from pathlib import Path
from PIL import Image
import folder_paths
from comfy_extras.nodes_dataset import LoadImageTextDataSetFromFolderNode
with tempfile.TemporaryDirectory() as directory:
folder_paths.set_input_directory(directory)
folder = Path(directory) / "train.png"
folder.mkdir()
Image.new("RGB", (8, 8), (255, 0, 0)).save(folder / "photo.png")
(folder / "photo.txt").write_text("A red image", encoding="utf-8")
images, captions = LoadImageTextDataSetFromFolderNode.execute("train.png").result
print(len(images), captions)
```
Expected: `1 ['A red image']`. Actual: `1 ['']`.
### Debug Logs
Direct node execution on macOS with Python 3.12; the three-case reproduction completed without an exception:
```json
{"folder": "dataset", "filename": "photo.png", "image_count": 1, "captions": ["A red image"]}
{"folder": "train.png", "filename": "photo.png", "image_count": 1, "captions": [""]}
{"folder": "dataset", "filename": "photo.png.crop.png", "image_count": 1, "captions": [""]}
```
There is no server startup log because this reproduction invokes the node directly.
Contributor guide
Research direction
Start at LoadImageTextDataSetFromFolderNode.execute in comfy_extras.nodes_dataset and run the provided direct-node reproduction from a ComfyUI checkout. Done means the loader returns the captions for images in folders or filenames containing image extensions, including train.png/photo.png and photo.png.crop.png.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100