Replicating the Vision Transformer on the Terracotta Temples of Bishnupur

No JFT-300M, no TPU pod, no borrowed dataset. ViT-Base/16 assembled from PyTorch layers on a single 16GB M1, and pointed at ten 17th- and 18th-century temples in Bishnupur, Bankura, West Bengal, India, from a dataset I built by hand.
1. Start with the result
First, credit. The code in this post is not mine. It follows Daniel Bourke’s PyTorch Paper Replicating chapter from Zero to Mastery: Learn PyTorch closely, training utilities included. That chapter is the best walkthrough of the paper I know, so if you want every cell explained at length, keep it open alongside this. What’s mine is the data: ten temples, 1,935 images, sorted by hand. The data is what made the run worth writing up.
| model | weights at the start | parameters trained | test accuracy* | what it actually did |
|---|---|---|---|---|
| ViT-Base/16, built in the notebook | random | 85,806,346 | 14.9% | answered “Jor Bangla” for all 392 test photos |
ViT-B/16 from torchvision, frozen | ImageNet-1k | 7,690 | 88.9% | learned the temples |
* As logged by the notebook after epoch 10, on the 392-image test split.
The two torchinfo summaries agree to the parameter: 85,806,346 each. Same 1,543 training images, same ten epochs, same laptop. The only difference is where the weights started, and that difference is the ViT paper’s central claim, reproduced in miniature on a dataset of my own.
Unlike the Transformer and BERT posts, attention here is PyTorch’s own nn.MultiheadAttention. After building it by hand twice, what’s new in ViT is how a picture becomes tokens, and what the model does with very little data. That’s where this post spends its time.
2. Bishnupur, and the dataset
Bishnupur is a town in Bankura district, West Bengal, in eastern India, about 140 km (85 miles) northwest of Kolkata by road, and was the seat of the Malla kings of Mallabhum. The Mallas were Vaishnavas, and between the 17th and 18th centuries they filled their capital with temples. The ten in this dataset are only some of them; the ASI’s map in section 3 marks others too: Radha Binode, Malleshwar temples, etc. With little good building stone to hand, they built in what the red ground gave them: laterite stone, locally called makra, and laterite bricks, which Bankura still makes today. They covered the walls in carved terracotta: battles, dancers, the Ramayana and the Mahabharata, and above all scenes from Krishna’s life. The “Temples at Bishnupur” have been on UNESCO’s World Heritage tentative list since 1998. All ten in this dataset are ASI-protected Monuments of National Importance, notified in 1913 and 1914.
Read the class names and you are reading the names of one god. Shyam, Madan Mohan, Kalachand, Nandalal, Gobinda, Madhab: all names of Krishna, and Jor Bangla’s traditional name, Kestaraya, is one too. The classes differ not in who they were built for, but in how they were built.
That is also what makes this a hard vision problem. Seven of the ten classes are the same kind of building: the single-towered eka-ratna. Six of those seven are built of laterite stone, and five of the six stand within about 450 metres of each other. Every class shares the same red-brown palette of brick and laterite. The model can’t sort these by colour; it has to learn silhouettes, roof curves and the texture of the carving.
I assembled the dataset by hand: my own photographs from a visit in March 2025, plus images I collected one at a time. Every image was sorted into its temple’s folder by hand. An 80/20 split per class (seed 42) gives the training and test sets:
| class | temple | type, per the ASI board | built | images | train | test |
|---|---|---|---|---|---|---|
| 0 | Jor Bangla | brick, two dochala roofs joined lengthwise | 1655 | 308 | 246 | 62 |
| 1 | Jor Mandir | three laterite-stone eka-ratna temples | 1726 (north temple) | 212 | 169 | 43 |
| 2 | Kalachand | laterite-stone eka-ratna | 1656 | 126 | 100 | 26 |
| 3 | Madan Mohan | brick eka-ratna | 1694 | 167 | 133 | 34 |
| 4 | Nandalal | laterite-stone eka-ratna | late 18th c. | 142 | 113 | 29 |
| 5 | Radha Gobinda | laterite-stone eka-ratna | 1726 | 149 | 119 | 30 |
| 6 | Radha Madhab | laterite-stone eka-ratna | 1737 | 139 | 111 | 28 |
| 7 | Radha Shyam | laterite-stone eka-ratna | 1758 | 182 | 145 | 37 |
| 8 | Rasmancha | brick, truncated pyramidal roof | c. 1600 by tradition | 194 | 155 | 39 |
| 9 | Shyam Rai | brick pancha-ratna (five towers) | 1643 | 316 | 252 | 64 |
| total | 1,935 | 1,543 | 392 |
The class numbers are the labels the model sees. ImageFolder assigns them alphabetically by folder name, and they come up again when we read the results. The largest class is 2.5× the smallest (Shyam Rai 316, Kalachand 126).
The dataset is not public, and I’m not releasing it. The ten photographs below are the only images from it in this post. Nothing in the code depends on temples: point ImageFolder at any folder-per-class image set (yours, or the course’s pizza/steak/sushi) and every cell runs unchanged.
3. The ten temples
Under each photo is the text of the Archaeological Survey of India’s information board at that temple: the name, coordinates and description as written on site, transcribed from photographs. Capitals are normalised and obvious typos fixed; the separate protection-notice boards are left out. Visitors have been edited out of the photos. I photographed nine of the ten boards on 23 March 2025, between 1:19 and 3:01 in the afternoon.
The ASI also has an engraved map of the monuments it protects in the town. It puts the ten temples in three groups (the numbers are class labels). The distances are straight-line, worked out from the latitude and longitude printed on each board:
- North: Madan Mohan (3), on its own, about 950 m north of the centre group.
- Centre, by the old fort gate: Rasmancha (8), Shyam Rai (9), Jor Bangla (0) and Radha Shyam (7), within 635 m of each other. Jor Bangla and Radha Shyam stand 94 m apart.
- South, beside the Lal Bandh reservoir: Nandalal (4), Radha Gobinda (5), Jor Mandir (1), Radha Madhab (6) and Kalachand (2), within 432 m. All five are built of laterite stone.
End to end, from Madan Mohan to Kalachand, is 2.4 km.

The ASI’s map of Bishnupur’s centrally protected monuments, straightened from a photo and cropped to the temples, with the glare on the granite cleaned out. The red circles and class numbers are mine. North is up. Photo by the author, 23 March 2025.
3.1 Jor Bangla

Jor Bangla (class 0, 308 images). Photo by the author, March 2025.
JOR BANGLA TEMPLE · Lat. 23°04′18.10″ N, Long. 87°19′36.44″ E
Traditionally known as Kestaraya, this south-facing temple is famous for its structural features and exquisite terracotta embellishments. According to inscription, the temple was built by Raghunath Simha in 1655 CE. It is a composition of two large dochalas joined longitudinally: a small charchala, a brick replica of a four-sided roofed hut, marks its junction. Its outer dochala serves as the porch and the inner dochala as the sanctum. In the sanctum a stucco figure of six-armed Shri Chaitanya Deva is placed on a high pedestal against the back wall. The terracotta decoration includes scenes from the Mahabharata, Ramayana and Krishnalila. On walls east and west, timber frame on which dochalas rest has been efficiently translated into terracotta too.
The temple was declared as a monument of national importance vide BG 4063, dated 18.8.1913.
3.2 Jor Mandir

Jor Mandir (class 1, 212 images). Photo by the author, March 2025.
JORAMANDIR COMPLEX · Lat. 23°03′36.65″ N, Long. 87°19′18.81″ E
In the eighteenth century the Malla kings of Bishnupur built the Joramandir group of temples, a complex of three ekaratna temples made of laterite, square in plan and constructed on a raised plinth. Among these, the two on the south and north are a little larger than the one in the middle. The temple on the northern side was built by Gopalasimha and his wife Dhvajamanidevi in 1726, according to inscription. The central one is elaborately decorated with stucco work, depicting scenes from Ramayana and Krishnalila.
This group of temples were declared a monument of national importance vide BG 2351, dated 19.6.1914.
3.3 Kalachand

Kalachand (class 2, 126 images). Photo by the author, March 2025.
KALACHAND TEMPLE · Lat. 23°03′32.50″ N, Long. 87°19′33.33″ E
This laterite temple of eka-ratna type is raised on a low platform and stands with corridor around with three arched openings on all four sides. The single tower having saptaratha plan is topped by an amalaka and a pitcher, rises from the centre of the curved roof. The decorations are mainly low-relief carvings with Krishnalila as the main theme and other representations of Pauranic deities, ascetics and dancers. Chaitanya, the famous medieval Bengali religious reformer, finds his place in the sculptural panel on the left frontal wall. This temple was built under the patronage of the Malla king Raghunatha Simha in the year 1656 CE.
The temple was declared as a monument of national importance vide BG 2351, dated 19.6.1914.
3.4 Madan Mohan

Madan Mohan (class 3, 167 images). Photo by the author, March 2025.
MADAN MOHAN TEMPLE · Lat. 23°04′50″ N, Long. 87°19′24″ E
This brick built temple on a large laterite plinth was erected to enshrine the tutelary deity of the Mallas. The temple is much celebrated for the ornamentation works mainly on terracotta plaques which embellish its wall. The temple has covered porch with triple arched openings on the east, south and west and has a single tower on a sloping roof. The facade of the temple has scenes showing Krishnalila episodes, scenes showing dancers and dancing party and a row of ascetics. On the other three sides, the arches are fitted with plaques containing figures enclosed by very rich floral ornamentations. The area resting upon the arches are found covered with scenes depicting war while the lower panels are found decorated with figures of animals and birds, Krishnalila, Dasavatara scenes, legends and stories from the Puranas. The temple was built by Durjana Singha in 1694 CE as per inscriptional evidence.
The temple was declared as a monument of national importance vide BG 4063, dated 18.8.1913.
3.5 Nandalal

Nandalal (class 4, 142 images). Photo by the author, March 2025.
NANDALAL TEMPLE · Lat. 23°03′41.25″ N, Long. 87°19′22.96″ E
A laterite structure, the temple is of the ekaratna type. This south facing temple has ornamentation only on the space available by the sides of the three arched openings. The temple has no foundation inscription but from the style and general appearance it seems that the edifice was built sometime during the late 18th century.
The temple was declared as a monument of national importance vide BG 2351, dated 19.6.1914.
3.6 Radha Gobinda

Radha Gobinda (class 5, 149 images). Photo by the author, March 2025.
RADHAGOBINDA TEMPLE · Lat. 23°03′36.49″ N, Long. 87°19′23.23″ E
This east facing laterite temple of eka-ratna type is built on a square plan. The single tower rises from the center of the curved roof and topped by an amalaka and a pitcher. The temple has a triple arched facade with an oblong corridor right behind it. The entire front wall and the wall beneath the curved cornice are embellished with bas relief decoration. A brick built small chariot is found beside the temple. According to the temple inscription, the temple was built in 1726 CE during the reign of Krishna Simha.
The temple was declared as a monument of national importance vide BG 2351, dated 19.6.1914.
3.7 Radha Madhab

Radha Madhab (class 6, 139 images). Photo by the author, March 2025.
RADHAMADHAB TEMPLE · Lat. 23°03′34.59″ N, Long. 87°19′28.70″ E
This laterite temple of ekaratna type with triple-arched opening in the south has access to the oblong corridor. The eastern wall of the temple has another corridor which has a three arched opening. At the base of the temple there are depicted rows of birds, animals and Puranic episodes. On the side wall and lower part of the cornice exist elaborate sculptural reliefs shown in a very graceful manner. The major area of these decorations is filled with scenes showing the Krishnalila episodes, Dasavatara and floral designs. A unique feature of this temple is the presence of a bhogamandapa (hall of offerings) of the dochala type. The temple was built by Churamonidevi, a consort of the Malla king Krishna Singha, in 1737 CE.
The temple was declared as a monument of national importance vide BG 2351, dated 19.6.1914.
3.8 Radha Shyam

Radha Shyam (class 7, 182 images). Photo by the author, March 2025.
RADHASHYAM TEMPLE · Lat. 23°04′20.88″ N, Long. 87°19′35.11″ E
This eka-ratna type of temple built in laterite is noted for its stucco reliefs. Built on a square plan, the temple has a curved roof with a single tower above. The lime plaster known as pankha applied to cover the laterite walls reveals decorations including geometric and floral motifs of exquisite workmanship. Two rows of stucco figures set up within square blocks are fixed along the side walls and the lower part of the cornice. Similar decorations can also be noticed along the sides of the three arched openings. The inner portion of the three arched porch are also decorated. The front wall of the sanctum is found decorated with scenes from the Ramayana, Anantasayin Vishnu and widely recurring figures of Radha Krishna. According to the dedicatory inscription of this temple, it was erected in the year 1758 CE by the Malla ruler Chaitanya Singha.
The temple was declared as a monument of national importance vide BG 2351, dated 19.06.1914.
3.9 Rasmancha

Rasmancha (class 8, 194 images). Photo by the author, March 2025.
RASHMANCHA · Lat. 23°04′06.16″ N, Long. 87°19′19.52″ E
Built on a laterite plinth, the monument is an impressive brick built square structure with a small shrine at the center and three corridors around it. A triple-arched facade occurs on its four sides. The shrine in the center is approached through central arched opening on the south. The monument has a truncated pyramidal roof. Tradition suggests that the monument was built in c. 1600 CE. However, the blind arcade on the face of the plinth and many other architectural characteristics may suggest a later date, possibly in the late seventeenth century. The building was used for putting up idols from other temples on the occasion of Ras festival every year.
The temple was declared as a monument of national importance vide BG 2351, dated 19.6.1914.
3.10 Shyam Rai

Shyam Rai (class 9, 316 images). Photo by the author, March 2025.
SHYAMRAI TEMPLE · Lat. 23°04′16.03″ N, Long. 87°19′26.60″ E
This brick-built pancha-ratna temple has on each of the four sides a porch showing three arches for entrance. This temple is famous for its highly ornamental decorations in terracotta, found all over the temple. It is decorated with floral designs and Krishnalila scenes where the rasa-mandala and other episodes are accommodated within circular panels. There are also scenes of social life, episodes from Pauranic literature, the Ramayana and the Mahabharata and stories from Saiva or Sakta legends. An inscription placed on the main entrance of the temple states that this temple was built for the pleasure of Sri Radhika and Sri Krishna. It also credits the Malla king Raghunath Simha, son and successor of Virahambira, as the patron of the monument, dedicated in 1643 CE.
The temple was declared as a monument of national importance vide BG 4063, dated 18.8.1913.
4. What ViT is
The Vision Transformer (Dosovitskiy et al., An Image is Worth 16x16 Words, ICLR 2021) asks a blunt question: what if you designed nothing specifically for images? Cut the picture into a grid of 16 × 16-pixel squares, flatten each square into a vector, and hand the sequence to the same Transformer encoder that reads sentences. In the paper’s words: “Image patches are treated the same way as tokens (words) in an NLP application.”

Jor Bangla as ViT reads it: 14 × 14 = 196 patches, each 16 × 16 pixels at the model’s 224 × 224 input. One photograph, one 196-word sentence. Photo by the author, March 2025.
For a 224 × 224 photo that’s (224 / 16)² = 196 patches. Each patch holds 16 × 16 × 3 = 768 raw numbers, and a learned linear projection maps it to a vector of size D. In ViT-Base, D is also 768. That’s a coincidence of the Base size, not a rule: ViT-Large projects the same 768-number patches to 1,024. The paper’s three sizes (Table 1):
| model | layers | hidden size D | MLP size | heads | params |
|---|---|---|---|---|---|
| ViT-Base (built here, patch 16) | 12 | 768 | 3072 | 12 | 86M |
| ViT-Large | 24 | 1024 | 4096 | 16 | 307M |
| ViT-Huge | 32 | 1280 | 5120 | 16 | 632M |
5. Why ViT matters in this series
The Transformer introduced the architecture for translation. BERT kept only the encoder and showed that pre-training once and fine-tuning everywhere beats training per task. ViT is the step where the architecture stops being about language at all. Almost every part of it is borrowed, and the paper says so:
| Transformer (2017) | BERT (2018) | ViT (2020) | |
|---|---|---|---|
| stack | encoder + decoder | encoder only | encoder only |
| tokens | byte-pair subwords | WordPiece subwords | 16 × 16 patches, via a Conv2d |
| positions | sinusoidal, fixed | learned, 1D | learned, 1D |
| readout | decoder → softmax | pooled [CLS] | [class] token (Eq. 4) |
| LayerNorm | after each sub-layer | after each sub-layer | before each sub-layer |
| activation | ReLU | GELU | GELU |
| pre-training | none | self-supervised (MLM + NSP) | supervised (ImageNet-21k, JFT-300M) |
The [class] token is lifted straight from BERT: “Similar to BERT’s [class] token, we prepend a learnable embedding to the sequence of embedded patches.” The authors even tried BERT’s objective on pixels. They corrupted 50% of patch embeddings, 80% of those to a learnable [mask], 10% to a random other patch and 10% left as they were, “very similar to the one used for language by Devlin et al.” That’s the same 80/10/10 trick from the BERT post. Predicting each corrupted patch’s mean colour, ViT-B/16 reached 79.9% on ImageNet: 2 points better than training from scratch, but still 4 behind supervised pre-training.
The bigger reason ViT matters is what it made possible. Once an image is a sequence of tokens, it can share a model with text. That is why ViTs sit inside so much of what came next: CLIP’s image encoders, the vision tower LLaVA connects to a language model, and SAM’s image encoder. For anyone who has built BERT, nothing after the patch embedding is new. That is the point.
6. The architecture, and where 85,806,346 parameters live
The whole model is four equations from the paper, each marked on the diagram:
Eq. 1 turns the image into 197 tokens. Eqs. 2 and 3 are one encoder block, repeated 12 times. Eq. 4 reads the answer off token 0, the [class] token, and ignores the other 196. Here is where the parameters sit:
| part | parameters |
|---|---|
| patch embedding: Conv2d, 768 kernels of 3 × 16 × 16, plus biases | 590,592 |
[class] token (768) + position embedding (197 × 768) | 152,064 |
| 12 encoder blocks × 7,087,872 | 85,054,464 |
| classifier head: LayerNorm + Linear(768 → 10) | 9,226 |
| total | 85,806,346 |
99.1% of the model is the encoder blocks. The part that makes it a vision model, the patch embedding, is under 0.7%.
7. Walking the notebook
The notebook (ViT/ViT.ipynb) goes in the same order as the course chapter. Here is the flow, with the shapes that come out of each step.
7.1 Split, count, load
DatasetSplitter copies each temple folder in data/ into dataset/train and dataset/test at 80/20, with a fixed seed. It skips the copy if dataset/ already exists, so re-running is safe. A counting cell then checks that train + test = total for every class (✅ on all ten, 1,935 = 1,543 + 392).
Images are resized to 224 × 224, the training resolution in the paper’s Table 3, and turned into tensors. That’s the whole transform; there’s no normalisation and no augmentation. create_dataloaders wraps both splits in ImageFolder with batch size 32 (the paper used 4,096), giving 49 training batches and 13 test batches. The training loader shuffles; the test loader doesn’t. Remember that.
A batch comes out as (32, 3, 224, 224): PyTorch is channels-first. To plot one, image.permute(1, 2, 0) reorders it to the (224, 224, 3) that matplotlib expects.
7.2 Eq. 1: from photo to 196 tokens
The notebook first does the arithmetic by hand: (224 * 224) / 16**2 = 196 patches, each 16 * 16 * 3 = 768 numbers, so the patch sequence for one image is (196, 768). Then it slices a row of patches out of a temple photo, and then all 196 of them: the grid in the figure above.
The trick that makes this cheap: a Conv2d with kernel size = stride = 16 is “cut into patches + multiply by E”, in one operation. Each of its 768 kernels sees exactly one 3 × 16 × 16 patch at a time, never overlapping, so the output is one 768-vector per patch, laid out on a 14 × 14 grid. The convolution output-size formula confirms it: ⌊(224 + 2·0 − 16) / 16 + 1⌋ = 14. Flatten the grid and swap two axes, and you have a sequence:
class PatchEmbedding(nn.Module): # abridged from the notebook
def __init__(self, in_channels=3, patch_size=16, embedding_dim=768):
super().__init__()
self.patcher = nn.Conv2d(in_channels, embedding_dim,
kernel_size=patch_size, stride=patch_size, padding=0)
self.flatten = nn.Flatten(start_dim=2, end_dim=3)
def forward(self, x): # (B, 3, 224, 224)
x = self.patcher(x) # (B, 768, 14, 14) one 768-vector per patch
x = self.flatten(x) # (B, 768, 196)
return x.permute(0, 2, 1) # (B, 196, 768) sequence-first, like text
One quirk if you run it: the shape check in the notebook’s forward reads the notebook-level patch_size, not self.patch_size. It’s harmless here because both are 16.
7.3 The [class] token and the position embedding
A single learnable (1, 1, 768) vector is prepended with torch.cat(..., dim=1), so the sequence goes from 196 to 197 tokens. A learnable (1, 197, 768) position embedding is then added, and it broadcasts across the batch. The demo cells initialise both with torch.ones so you can watch them land: in the printed tensor, the [class] row reads 2.0000 all the way across (one from the token, one from its position). The real model uses torch.randn.
7.4 Eqs. 2 and 3: the encoder block
MultiHeadSelfAttentionBlock is LayerNorm followed by nn.MultiheadAttention(768, 12, batch_first=True), with query = key = value = the normalised input. MLPBlock is LayerNorm → Linear(768, 3072) → GELU → Dropout → Linear(3072, 768) → Dropout. The block adds the residuals:
def forward(self, x):
x = self.msa_block(x) + x # Eq. 2: LN → MSA, then add the input back
x = self.mlp_block(x) + x # Eq. 3: LN → MLP, then add the input back
return x
Input and output are both (1, 197, 768), and torchinfo counts 7,087,872 parameters. The notebook then shows that PyTorch’s nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, activation="gelu", batch_first=True, norm_first=True) is the same block with the same 7,087,872 parameters. norm_first=True is the pre-LN choice from the table above. The default, False, would give you BERT’s ordering instead.
7.5 Assembling ViT
def forward(self, x): # abridged
class_token = self.class_embedding.expand(x.shape[0], -1, -1) # (B, 1, 768), a view, no copy
x = self.patch_embedding(x) # (B, 196, 768)
x = torch.cat((class_token, x), dim=1) # (B, 197, 768)
x = self.embedding_dropout(self.position_embedding + x) # Eq. 1
x = self.transformer_encoder(x) # Eqs. 2–3, × 12
return self.classifier(x[:, 0]) # Eq. 4: token 0 only → (B, 10)
transformer_encoder is an nn.Sequential of 12 independent blocks, and classifier is LayerNorm → Linear(768, 10). The class defaults to 1,000 outputs for ImageNet; the notebook builds it with num_classes=10.
7.6 Training it from scratch
The optimiser follows the paper’s Table 3 row for ViT-B on ImageNet-21k: Adam with β₁ = 0.9, β₂ = 0.999, learning rate 10⁻³ and weight decay 0.03. The paper never names its loss, so it’s CrossEntropyLoss, the obvious choice for single-label classification. Then ten epochs of engine.train.
7.7 Transfer learning with torchvision’s ViT-B/16
weights = torchvision.models.ViT_B_16_Weights.DEFAULT # = IMAGENET1K_V1
pretrained_vit = torchvision.models.vit_b_16(weights=weights).to(device)
for p in pretrained_vit.parameters():
p.requires_grad = False # freeze all 85.8M
pretrained_vit.heads = nn.Linear(768, len(class_names)).to(device) # train only these 7,690
transforms = weights.transforms() # resize 256 → centre crop 224 → ImageNet mean/std
The last line matters as much as the weights. A pretrained model expects its inputs prepared the way its training data was, so this run uses torchvision’s transforms (resize to 256, centre-crop to 224, normalise with ImageNet’s mean and standard deviation), not the bare resize from section 7.1. Adam at 10⁻³ again (no weight decay this time), same ten epochs. On the M1’s GPU (mps) it took 28.5 minutes, about 171 seconds an epoch, even though only the head was learning: every image still has to go forward through all 12 frozen blocks.
7.8 Save and predict
save_model writes the state_dict, 327 MB on disk. pred_and_plot_image then classifies a photo kept in dataset/custom_testing/.
8. Results: same parameters, opposite outcomes
The pretrained model was at 71.9% test accuracy after one epoch and 88.9% after ten, with training accuracy above 97%. The from-scratch model’s log is stranger:
| epoch | train loss | test loss | test acc (logged) | identical to always answering… |
|---|---|---|---|---|
| 1 | 2.8157 | 2.4768 | 0.2115 | Shyam Rai |
| 2 | 2.3958 | 2.4621 | 0.2115 | Shyam Rai |
| 3 | 2.3695 | 2.3375 | 0.2115 | Shyam Rai |
| 4 | 2.3295 | 2.3077 | 0.0889 | Radha Shyam |
| 5 | 2.3074 | 2.3127 | 0.0817 | Madan Mohan |
| 6 | 2.3204 | 2.4019 | 0.0889 | Radha Shyam |
| 7 | 2.3192 | 2.3154 | 0.2115 | Shyam Rai |
| 8 | 2.3172 | 2.2871 | 0.1490 | Jor Bangla |
| 9 | 2.2964 | 2.3223 | 0.0697 | Nandalal |
| 10 | 2.2949 | 2.2770 | 0.1490 | Jor Bangla |
The same five accuracy values keep coming back, and that’s not noise. Each is the exact score of a model that gives one answer for all 392 test photos. The test DataLoader isn’t shuffled, so ImageFolder serves the photos sorted by class. engine.test_step averages accuracy per batch, not per image. Under that metric, “always Shyam Rai” (the last class, which fills the final batches) scores exactly 0.2115, and “always Jor Bangla” scores exactly 0.1490. Every logged value matches one class’s signature to four decimal places. At the end of every epoch, the model was a constant. Counted per image, “always Shyam Rai” is 64/392 = 16.3% and “always Jor Bangla” is 62/392 = 15.8%.
The loss tells the same story. A model that knows nothing, guessing uniformly over ten classes, scores ln 10 = 2.303. A model that knows only how common each temple is in the training set scores 2.252 on this test split. The run finished at 2.277. It learned roughly how often each temple appears, and nothing about what any of them looks like.
9. Why the from-scratch ViT learned nothing
9.1 Only 1,543 images for 85.8 million parameters
That’s about 55,600 parameters per training image. The paper warns about exactly this, and not even at our scale. Its smallest pre-training set is ImageNet, about 840 times larger than ours, and even there: “When trained on mid-sized datasets such as ImageNet without strong regularization, these models yield modest accuracies of a few percentage points below ResNets of comparable size.” ViT only wins at 14M–300M images: “We find that large scale training trumps inductive bias.”
The inductive bias it means is what a CNN gets for free and a ViT doesn’t. A convolution assumes that nearby pixels belong together and that a carved panel is the same panel wherever it appears. ViT assumes almost nothing. In the paper’s words, “the position embeddings at initialization time carry no information about the 2D positions of the patches and all spatial relations between the patches have to be learned from scratch.” Before it can tell Kalachand from Radha Madhab, a fresh ViT has to learn that patch 15 sits directly below patch 1. With 1,543 photographs of very similar buildings, it never got that far.
9.2 The recipe was never the paper’s either
| ViT-B on ImageNet-21k (paper, Table 3) | this notebook | |
|---|---|---|
| training images | 14M | 1,543 |
| batch size | 4,096 | 32 |
| learning-rate warmup | 10,000 steps | none |
| total optimiser steps | ≈ 300,000 (90 epochs) | 490 (10 epochs) |
| learning-rate schedule | linear decay | constant 10⁻³ |
| input preprocessing | — | resize + ToTensor, no normalisation |
The paper’s warmup alone is 10,000 steps. This entire run was 490. An 85.8M-parameter Transformer took Adam’s full learning rate from its very first step, on batches 128 times smaller than the paper’s. Collapsing onto one answer is the textbook result. The notebook’s own closing note lists the missing pieces (warmup, decay, gradient clipping, and above all data), and none of them can be fixed by training longer on the same 1,543 images.
9.3 Why the frozen one works
torchvision’s IMAGENET1K_V1 weights were “trained from scratch by using a modified version of DeIT’s training recipe” on ImageNet-1k, where they score 81.07% top-1. By the time they reach Bishnupur, the 12 blocks already turn any photograph into a [class] vector that encodes edges, textures, arches and silhouettes. Freezing them leaves one decision to learn: a 768 → 10 linear map, 7,690 numbers, which 1,543 images can pin down comfortably. Same architecture, same data, same ten epochs, and the only thing that changed is everything the weights had already seen.
10. Where it falls short, and what’s next
- The metric is batch-averaged. That’s fine with a shuffled loader, but misleading with a class-sorted one, as the table above shows. The fix is to count correct predictions per image. Both headline accuracies here are the notebook’s logged numbers.
- No confusion matrix yet. For this dataset the real question is whether the model mixes up the six laterite-stone eka-ratna temples, five of which share one neighbourhood. That’s the next cell to write.
- Only the head was trained. Unfreezing the last two or three blocks with a small learning rate, plus augmentation (crops, flips, colour jitter), is the standard next step from 88.9%.
- The classes are imbalanced 2.5×. A per-class accuracy table would show whether Kalachand’s 100 training images are enough.
11. Closing
The interesting part of this project was never going to be the architecture. After the Transformer and BERT, a ViT is a Conv2d and a [class] token away. It was finding out what a model with no built-in idea of “nearby” does with 1,543 photographs of very similar buildings. The answer: nothing at all, until it has seen a million other pictures first. The paper’s headline is that large-scale training trumps inductive bias. The temples showed the other half: without the scale, there’s nothing to trump with.
12. References
- Dosovitskiy, A., Beyer, L., Kolesnikov, A., et al. (2021). An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. ICLR 2021. arXiv:2010.11929
- Bourke, D. Zero to Mastery: Learn PyTorch, chapter 08, PyTorch Paper Replicating. The source of the notebook’s code and training utilities.
- PyTorch.
torchvision.models.vit_b_16,ViT_B_16_Weights.IMAGENET1K_V1. - Devlin, J., Chang, M.-W., Lee, K., Toutanova, K. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. NAACL. arXiv:1810.04805
- Vaswani, A., et al. (2017). Attention Is All You Need. NeurIPS. arXiv:1706.03762
- Archaeological Survey of India. Information boards at the temples of Bishnupur, Bankura, West Bengal, India; transcribed on site, March 2025.
- UNESCO World Heritage Centre. Temples at Bishnupur, West Bengal, Tentative List, ref. 1087.
- Sahapedia. Terracotta Temples of Bishnupur.