Skip to content

Instantly share code, notes, and snippets.

@rlan
Forked from sharma0611/imagenet.sh
Last active July 30, 2021 11:06
Show Gist options
  • Save rlan/30718a3749f935e3e3aa97acfd91ba73 to your computer and use it in GitHub Desktop.
Save rlan/30718a3749f935e3e3aa97acfd91ba73 to your computer and use it in GitHub Desktop.
ImageNet Preparation for PyTorch torch vision.datasets.imagenet
#!/bin/bash
#
# These files should exist:
# $ ls
# ILSVRC2012_devkit_t12.tar.gz ILSVRC2012_img_train.tar ILSVRC2012_img_val.tar
#
# When this script is finished:
# $ ls
# imagenet ILSVRC2012_devkit_t12.tar.gz ILSVRC2012_img_train.tar ILSVRC2012_img_val.tar
# $ ls imagenet
# ILSVRC2012_devkit_t12.tar.gz train val
mkdir imagenet && cd imagenet
cp ../ILSVRC2012_devkit_t12.tar.gz .
# Extract the training data
mkdir train && cd train
tar -xvf ../../ILSVRC2012_img_train.tar
find . -name "*.tar" | while read NAME ; do mkdir -p "${NAME%.tar}"; tar -xvf "${NAME}" -C "${NAME%.tar}"; rm -f "${NAME}"; done
cd ..
# Extract the validation data and move images to subfolders:
mkdir val && cd val
tar -xvf ../../ILSVRC2012_img_val.tar
wget -qO- <https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh> | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment