Skip to content

Commit

Permalink
Merge pull request #11 from sony/feature/20180416-efficient-create-im…
Browse files Browse the repository at this point in the history
…agenet-files

Use extractfile in extracting imagenet tar
  • Loading branch information
TE-HidehoGomi authored Apr 27, 2018
2 parents 59893dd + 48c45f1 commit d5c9aaf
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions imagenet-classification/create_train_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
dst_dir = args.outdir

with tarfile.open(source_tar_file) as tf:
tar_tmp_dir = dst_dir + '/' + 'tmpdir'
tf.extractall(tar_tmp_dir)

for tar_file in tqdm.tqdm(os.listdir(tar_tmp_dir)):
name, ext = os.path.splitext(os.path.basename(tar_file))
category_dir = dst_dir + '/' + name
os.mkdir(category_dir)
with tarfile.open(tar_tmp_dir + '/' + tar_file) as tf:
tf.extractall(category_dir)

shutil.rmtree(tar_tmp_dir)
for tar_file_info in tqdm.tqdm(tf.getmembers()):
fullname = tar_file_info.name
name, ext = os.path.splitext(os.path.basename(fullname))
category_dir = dst_dir + '/' + name
os.mkdir(category_dir)
fileobj = tf.extractfile(tar_file_info)
with tarfile.open(fileobj=fileobj) as tf_class:
tf_class.extractall(category_dir)

0 comments on commit d5c9aaf

Please sign in to comment.