CityPedia: Mask-Grounded Concept Acquisition for Urban Visual Analysis

Technical report

Ruixuan Zhang Juexiao Zhang Zerun Liu Kaan Ozbay Chen Feng

New York University Corresponding authors

CityPedia encodes every frame of a city camera archive once into sparse codes. A new concept is acquired from a few masked exemplars, and the stored codes then answer where and when it appears, with no new pass over the archive.

Teaser figure of CityPedia

Abstract

Cameras in cities, from traffic surveillance to in-vehicle views, record continuously, and an analyst often learns which concept matters only after seeing a few cases of it, and then asks for every frame that shows it and where. Current tools serve this poorly at city scale, because models that operate on images run over the archive again for each new question, while a whole-image embedding does not show where a concept appears. CityPedia builds on the observation that frames are made of recurring visual concepts. A sparse autoencoder decomposes the patch tokens of a frozen vision-language model (VLM) into atoms learned without labels, and every frame is stored once as sparse codes, a sparse visual encyclopedia from which later questions are answered with no new pass over the archive. Because one concept activates different atoms in different images, a sparse head learns a weighted set of atoms from a few masked exemplars, and a graph adaptor regularizes this head with an atom co-occurrence graph so that fewer exemplars suffice. On three public urban datasets and four VLMs, CityPedia is able to ground concepts and retrieve them above zero-shot retrieval with the same VLM. On large-scale real-world footage from New York City, the codes measure where and when concepts appear, in agreement with third-party records of bus routes and the school calendar. Single concepts also combine into composite queries defined after encoding, such as a car in a bus lane.

Methodology

Method overview
Method overview. (1) A sparse autoencoder (SAE) learns to reconstruct the patch tokens of a frozen vision-language model. (2) Masks on a few images supply the targets for a sparse head over the shared dictionary of atoms, and the graph adaptor adds a penalty over a co-occurrence graph built from unlabeled codes.

1.1 Patch tokens, not one image embedding. The pooled output embedding of a VLM summarizes the whole image and gives up spatial detail, so a small object leaves little trace in it. CityPedia reads the P patch tokens \mathbf{h}_1(x),\dots,\mathbf{h}_P(x) of each image x from an intermediate block of a frozen VLM.

1.2 A sparse autoencoder over the tokens. The SAE maps a token \mathbf{h} to a sparse code \mathbf{z} and reconstructs it from the atoms of a learned dictionary:

\mathbf{z}=\phi\!\left(\mathbf{W}_{\mathrm{enc}}(\mathbf{h}-\mathbf{b}_{\mathrm{dec}})+\mathbf{b}_{\mathrm{enc}}\right),\qquad \hat{\mathbf{h}}=\mathbf{W}_{\mathrm{dec}}\,\mathbf{z}+\mathbf{b}_{\mathrm{dec}}

The operator \phi makes \mathbf{z} nonnegative with few nonzero entries. The SAE is trained without labels, only to reconstruct its input. With TopK, each patch keeps k active atoms.

1.3 One pass over the archive. CityPedia stores the patch code \mathbf{z}_p(x) of every patch once per image. Later questions read these codes and never the images.

TSP6K test images and their real codes (k = 32). A tile shows the patch where its atom is strongest. Pick an atom or a patch.

2.1 One atom is not one concept. The atoms are learned to reconstruct the input, and nothing aligns one atom with one concept. The atom that contributes most to the car head changes between images, so any single atom misses many cars. An unweighted union of atoms covers more of a concept but also marks more patches outside it.

2.2 A sparse head on the stored codes. A concept is given by B masked exemplars, so it needs no name. A linear head (\mathbf{w},b) gives patch p the probability

\pi_p=\sigma\!\left(\mathbf{w}^{\top}\mathbf{z}_p+b\right)

It is fit with a class-balanced logistic loss \mathcal{L}_{\mathrm{cls}}(\mathbf{w},b) on the exemplar patches, and an \ell_1 term keeps few atoms. The atoms with nonzero weight form the entry of the concept.

2.3 Two queries from one head. Grounding marks patch p of image x when \pi_p(x)\ge\tau. Retrieval scores an image by the mean of its m largest patch probabilities,

s(x)=\frac{1}{m}\sum_{p\in\mathrm{top}_m(x)}\pi_p(x)

so a small object can score high without resting on a single patch.

car mask, by pixel share of a patch inside the mask patches the head marks

The paper’s car head (B = 10, no graph term). Reading fewer atoms cuts this head short; it is not fit again. Pick an atom to see it alone.

3.1 A few exemplars show only some atoms. A head fit to a few exemplars learns weights only for the atoms active on their patches. It misses the atoms that the concept activates in images it has not seen.

3.2 A co-occurrence graph from unlabeled codes. Atoms that serve one concept tend to be active together. The graph is built from the training images without labels. It links atoms i and j by the positive point-wise mutual information \max\!\big(0,\log\tfrac{N\,n_{ij}}{n_i\,n_j}\big), where N counts the training patches, n_i those where atom i is active and n_{ij} those where both are. Each atom keeps its \kappa strongest links.

3.3 The graph adaptor. With \mathbf{L} the normalized Laplacian of the graph, the head solves

\min_{\mathbf{w},\,b}\ \mathcal{L}_{\mathrm{cls}}(\mathbf{w},b)+\lambda\lVert\mathbf{w}\rVert_1+\lambda_g\,\mathbf{w}^{\top}\mathbf{L}\,\mathbf{w}

The last term is small when linked atoms receive similar weights. An atom that is inactive on every exemplar patch can therefore take weight from its neighbors, so the head can respond to forms of the concept that no exemplar shows.

atom from the exemplars atom the graph term adds inactive on every exemplar car mask, by pixel marked without the graph term marked only with it

The paper’s car heads (B = 10) without the graph term and at the graph weight chosen on validation. A line links two atoms of the co-occurrence graph; the inner wire frame holds the atoms from the exemplars. The added atoms shown matter most on this image or link the most shown atoms. Drag to turn; pick an atom or a patch.

Results on public benchmarks

Grounding and retrieval on public benchmarks. CLIP ViT-L/14 on the test set, k = 32, B = 10. Composite columns give the mAP over queries “c1 next to c2”. † our implementation. ‡ reads the heads of CityPedia without the graph adaptor. § an upper bound that is not ranked. Zero-shot retrieval is in italics. Darker and lighter fill mark the best and second best per column.
All classes at once on the test set, two images per dataset
All classes at once on the test set, two images per dataset. The columns show the image, its annotation (GT), the PatchSAE readout and CityPedia. Each patch takes the color of its class in the legend, and a patch without a class shows the image in light gray. PatchSAE trains no head, and each class uses the single SAE atom that fits it best on the masked exemplars. CityPedia uses the sparse heads fit with the graph adaptor. Both read the same SAE (k = 32) and the same 10 masked exemplars. The images are the best cases for CityPedia under a fixed rule.

Grounding demo

All classes at once on one image

Each patch takes the class with the largest head score (k = 32, B = 10 masked exemplars). Compare the ground truth with PatchSAE, which uses the best single atom per class, and with CityPedia, which uses heads with the graph adaptor. Select a class in the legend to show only that class.

Composite query demo

Two concepts combined after encoding

Every head gives a patch map on the same stored codes. A composite query combines the maps of its two concepts with no new labels and no new pass over the images. The queries here are “c1 next to c2” on the test sets. Switch the layers to see each concept and their combination.

Case study, NYC archive

Where and when a concept appears in New York City

The archive holds 3,795,916 frames from 946 public NYC traffic cameras in February and March 2023. Every frame is encoded once. Each layer below is one query on the stored codes, drawn next to a record kept outside the archive. Drag to move, scroll to zoom, and select a camera.

Composite query demo

Two concepts combined on NYC frames

The same operation on the archive. A car in a bus lane combines the car head with a bus-lane region. Street parking combines the car head on two frames 15 minutes apart. Switch the layers to see each part and their combination on the frames that the paper studied.

MTA bus and school bus queries on the NYC archive
MTA bus and school bus queries on the NYC archive (day frames, February and March 2023). (a) Manhattan. Each dot gives the share of the camera's frames among the top 30,000 of the MTA bus query, and a ring marks a camera with frames among the 300 top school bus frames. The lines are MTA bus routes. (b) Hits per 10,000 frames by hour for the school bus query (top) and the MTA bus query (bottom). Shares and hits come from the query ranking and are not judged presence.
Bus-lane query on the NYC archive
Bus-lane query on the NYC archive. A camera near a lane is colored by the share of its frames among the top frames of the bus-lane query. Black rings mark cameras with a top frame that human experts judged to show a vehicle other than a bus in a bus lane. A matched frame is not a violation, because a frame cannot show whether a vehicle is turning or is allowed in the lane. The bottom panel repeats the four frames with car (blue) and bus-lane (orange) highlights from zero-shot SAM 3, from one PatchSAE atom per concept, and from CityPedia heads with the graph adaptor.

Rare events in the archive

Three event sequences from the supplementary material. In each, the head for people rises above the usual level of the camera view. The names of the marathon and the accident are the reading of a human expert.

The St Patrick's Day parade on Fifth Avenue, parade day, 11:30parade day, 11:30
The St Patrick's Day parade on Fifth Avenue, parade day, 12:15parade day, 12:15
The St Patrick's Day parade on Fifth Avenue, parade day, 13:30parade day, 13:30
The St Patrick's Day parade on Fifth Avenue, same view, previous Friday 11:30same view, previous Friday 11:30
The St Patrick's Day parade on Fifth Avenue. The first three frames come from the three assessable views of the parade route on the parade day, and the last shows the view of the first frame on the previous Friday. For day frames, the people head marks a share of the patches, and its mean between 11:00 and 16:30 ranks the parade day highest among Fridays on all three views.
Marathon event in Manhattan, 09:4509:45
Marathon event in Manhattan, 10:1510:15
Marathon event in Manhattan, 11:0011:00
Marathon event in Manhattan, one week later, 11:45one week later, 11:45
Marathon event in Manhattan. The sequence discovered by the rise of the people head marks this Sunday morning event, and a human expert verified a marathon in it. The first three frames come from that morning in time order, and the last shows the same view one week later.
A traffic accident on the bridge, 14:0014:00
A traffic accident on the bridge, 14:3014:30
A traffic accident on the bridge, 15:1515:15
A traffic accident on the bridge, 15:3015:30
A traffic accident on the bridge. The people head ranks this half-day window high against the camera's own history, and a human expert verified an accident with firefighters and a fire truck. The four frames come from one afternoon in time order, with the local time under each.

Acknowledgments

We thank Fan Zuo and Hongdao Meng for technical support, and Jing Zhang for discussion. This work was supported in part by NSF grants 2514030 and 2238968, by C2SMART, a Tier 1 University Transportation Center at New York University, and through the NYU IT High Performance Computing resources, services, and staff expertise. The contents of this paper reflect only the views of the authors, who are responsible for the facts, and do not represent the official views of any sponsoring agency.

BibTeX

@article{citypedia,
  title  = {CityPedia: Mask-Grounded Concept Acquisition for Urban Visual Analysis},
  author = {Zhang, Ruixuan and Zhang, Juexiao and Liu, Zerun and Ozbay, Kaan and Feng, Chen},
  note   = {Under review},
  year   = {2026}
}