Skip to content

Instantly share code, notes, and snippets.

@zwithz
Forked from geohot/extract.py
Created April 19, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwithz/fe2923e55a95a96002ee71ce1cbfd636 to your computer and use it in GitHub Desktop.
Save zwithz/fe2923e55a95a96002ee71ce1cbfd636 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