Skip to content

Instantly share code, notes, and snippets.

@geohot
Last active July 18, 2022 05:13
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save geohot/85da463f9252a64f957b to your computer and use it in GitHub Desktop.
Save geohot/85da463f9252a64f957b to your computer and use it in GitHub Desktop.
extract imagenet ILSVRC2012 recursive tar
# extract ILSVRC2012 without killing your SSD
import tarfile
import os
import sys
def mkdir(x):
try:
os.makedirs(x)
except OSError, e:
pass
def extract(dat):
mkdir(dat)
tar = tarfile.open("ILSVRC2012_img_"+dat+".tar")
for tarinfo in tar:
basedir = dat+"/"+tarinfo.name.split(".")[0]+"/"
print "extracting %11d to %s" % (tarinfo.size, basedir)
mkdir(basedir)
ifile = tar.extractfile(tarinfo)
itar = tarfile.open(mode="r", fileobj=ifile)
itar.extractall(path=basedir)
itar.close()
ifile.close()
tar.close()
extract(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment