Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
This documentation page is also available as an interactive notebook. You can launch the notebook in Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the above links.
Convert Pixeltable data to PyTorch DataLoader format for model training.

Problem

You have prepared training data—images with labels, text with embeddings, or multimodal data—and need to export it for PyTorch model training.

Solution

What’s in this recipe:
  • Convert query results to PyTorch Dataset
  • Use with DataLoader for batch training
  • Export to Parquet for external tools
You use query.to_pytorch_dataset() to create an iterable dataset compatible with PyTorch DataLoader.

Setup

Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘pytorch_demo’.
<pixeltable.catalog.dir.Dir at 0x16c534ad0>

Create sample training data

Created table ‘training_data’.
Inserting rows into `training_data`: 3 rows [00:00, 659.03 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.

Export to PyTorch dataset

Added 3 column values with 0 errors.
torch.Size([2, 3, 224, 224])

Export to Parquet for external tools

Explanation

Export methods:
Image format options:
DataLoader tips:
  • Data is cached to disk for efficient repeated loading
  • Use num_workers > 0 for parallel data loading
  • Filter/transform data before export to reduce size

See also

Last modified on June 24, 2026