Last active
July 18, 2022 05:13
-
-
Save geohot/85da463f9252a64f957b to your computer and use it in GitHub Desktop.
extract imagenet ILSVRC2012 recursive tar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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