Skip to content

Instantly share code, notes, and snippets.

@mkolod
Last active August 26, 2020 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkolod/94b4a2d49491714962af22427d721c93 to your computer and use it in GitHub Desktop.
Save mkolod/94b4a2d49491714962af22427d721c93 to your computer and use it in GitHub Desktop.

ImageNet validation set fix:

  1. The training set is organized in directories, with each directory matching a class, e.g. "n01751748" matching "sea snake." However, the valset is a flat dir of JPEGs. The ImageNet labels provided in the devkit for the validation set (ILSVRC2012_validation_ground_truth.txt) are not consistent with the ordering used by PyTorch/TF/Keras/MXNet/Caffe, etc. for pre-trained models. For example, in the the above ground truth label file, "sea snake" is 490, but in PyTorch/TF, it's 65.
    Proof:
  2. Untar the valset file, you will get a flat dir of JPEGs.
  3. Pull in the unflattening script into the directory where the val images were unpacked:
    https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh
  4. Run the valprep.sh script - it will re-create the "n01440764" etc. directory structure familiar from the training set.
  5. DO NOT use the original ILSVRC 2012 ground truth validation labels to match JPEGs to classes. Instead, use the DL framework directory-class mapping (where "sea snake" is 0-indexed 65, NOT 490) to generate labels for directory-assigned images, with directories generated using valprep.sh. This will match pre-created TFRecord/lmdb/RecordIO etc. and will match the predictions of pre-trained models, e.g. from TorchVision.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment