Efficient Representation of Natural Image Patches
This repository contains code to reproduce the main experiments from:
Efficient Representation of Natural Image Patches
https://arxiv.org/abs/2210.13004
Since 2011, I’ve been exploring the following question in my spare time—mostly as an intellectual challenge, and just for fun:
If you were an engineer tasked with designing the visual system of an organism, what would you do?
Why? Fundamentally because I want to understand how our brains process information—and because:
“What I cannot create, I do not understand.”
— Richard Feynman
There are too many intricacies in biological systems.
One can easily get lost in the dendritic forests or stuck in the ion channels.
So I kept asking: What are the fundamental goals of information processing? Are there principles that help us extract the essentials from the complexities?
The question itself is too big. It’s tempting to simplify by making many assumptions.
But what Poisson, Gauss, and Bayes can’t tell you is: while making a problem calculable, are you also making your model unrealistic?
So I approached it by imagining a minimal system: first with just one input pixel, then two, and eventually small image patches—always trying to make as few assumptions as possible. I wanted to see how far I could get.
A checkpoint in this decade-long, exciting, and sometimes lonely journey is summarized in the note above.
Repository structure
two_pixel/ – Jupyter notebooks for the two‑pixel case analyzed in the paper. See two_pixel/README.md.
image_patch/ – code and scripts for training and analyzing the image-patch case in the paper. See image_patch/README.md for details.
pyproject.toml and uv.lock – Python dependencies and their locked versions.
Data
Download the COCO 2017 image archive for the experiment you want to run and extract it to a directory of your choice. The experiments use the images directly. Official COCO download list
- Image patches. Download
unlabeled2017.zip (about 19 GB) and set image_path in image_patch/config.yaml to the extracted unlabeled2017/ directory. Training saves checkpoints in image_patch/ when run from that folder. The results script and feature-map notebook expect checkpoint_epoch_4.pt there with the default config. Image-patch guide
- Two pixels. For the real-image experiment, download
val2017.zip (about 1 GB). In generate_gray_image_patches.ipynb, point image_folder and the example filename to your extracted val2017/ images, and set output_folder to a writable directory. End both folder paths with /. Set fname in maximized_entropy_representation_of_image_patches.ipynb to the generated .pickle file. The synthetic notebook generates its own data. Two-pixel guide
Setup
Install uv, then run this from the repository root to create .venv with Python 3.12 and CPU PyTorch. uv installation guide
uv sync
For an NVIDIA GPU with a CUDA 13.0-compatible driver, select the CUDA wheels when syncing.
uv sync --no-group cpu --group cuda
After syncing, activate .venv from the repository root. Do this once per terminal session.
source .venv/bin/activate
Use python and jupyter directly in that terminal. For image-patch training, set device in image_patch/config.yaml to cpu or cuda:0 to match your setup, then run the following commands.
cd image_patch
python train_image_encoder.py
After pulling dependency updates, rerun the sync command for your setup.
Two directions I am looking for collaborators
There are two directions I would be very happy to find collaborators to work on.
EvenCodeTokenizer
Goal: turn the IPU-based binary representation into a practical image / video tokenizer for downstream models (e.g., vision transformers, multimodal LLMs, robotics pipelines (VLAs)).
If you are interested in making the tokenizer more robust and benchmarking it, and you have access to GPUs, please email me.
Comparison with real neural recordings
Goal: systematically compare the IPU’s binary population codes with real neural data from early visual areas (retina, LGN, V1, V2, etc.).
If you work with neural data (or have access to relevant datasets) and are interested in testing the theory against real recordings, please contact me.
Citation
If you use this code or build on these ideas, please cite:
@misc{guo2024efficientrepresentationnaturalimage,
title = {Efficient Representation of Natural Image Patches},
author = {Cheng Guo},
year = {2024},
eprint = {2210.13004},
archivePrefix = {arXiv},
primaryClass = {cs.CV},
url = {https://arxiv.org/abs/2210.13004},
}
评论