Implementation:NVIDIA DALI Synset Mapping JSON
| Knowledge Sources | |
|---|---|
| Domains | Vision, Training |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Provides a JSON array mapping ImageNet class indices to human-readable synset labels for the EfficientNet training example.
Description
This is a static JSON data file containing an array of 1000 strings, where each string at position i corresponds to the human-readable label for ImageNet class index i. Each entry contains the primary class name followed by synonyms and scientific names separated by commas (for example, "tench, Tinca tinca" at index 0 and "goldfish, Carassius auratus" at index 1).
Unlike the Python dictionary variant (synsets.py) used in other DALI examples, this file uses JSON format for broader compatibility and is structured as a flat JSON array rather than a key-value mapping. The array ordering implicitly encodes the class index, making position-based lookup straightforward from any language or tool that supports JSON parsing.
This file is used by the EfficientNet PyTorch training example within the DALI repository to translate numeric prediction outputs into class names during evaluation and visualization.
Usage
Use this file when working with the EfficientNet example to convert model prediction indices to human-readable labels. Load it with any JSON parser and index the resulting array by class index.
Code Reference
Source Location
- Repository: NVIDIA_DALI
- File: docs/examples/use_cases/pytorch/efficientnet/LOC_synset_mapping.json
- Lines: 1-1000
Signature
[
"tench, Tinca tinca",
"goldfish, Carassius auratus",
"great white shark, white shark, man-eater, ...",
...
]
Import
import json
with open("LOC_synset_mapping.json", "r") as f:
synset_mapping = json.load(f)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| class_index | int | Yes | An integer in the range [0, 999] used as array index to look up the class label. |
Outputs
| Name | Type | Description |
|---|---|---|
| label | str | Human-readable class name string with comma-separated synonyms and scientific names. |
Usage Examples
Loading and querying the synset mapping
import json
with open("LOC_synset_mapping.json", "r") as f:
synset_mapping = json.load(f)
# Look up class 207 (golden retriever)
predicted_class = 207
label = synset_mapping[predicted_class]
print(f"Predicted: {label}")
# Output: "Predicted: golden retriever"
# Get total number of classes
print(f"Total classes: {len(synset_mapping)}")
# Output: "Total classes: 1000"
Annotating top-k predictions
import json
import torch
with open("LOC_synset_mapping.json", "r") as f:
synset_mapping = json.load(f)
# Suppose 'output' is model output tensor of shape [1, 1000]
probs = torch.softmax(output, dim=1)
top5_probs, top5_indices = torch.topk(probs, 5, dim=1)
for prob, idx in zip(top5_probs[0], top5_indices[0]):
print(f" {synset_mapping[idx.item()]}: {prob.item():.4f}")