Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use arg parse #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ dmypy.json
# Pyre type checker
.pyre/

# ignore the data directory
data/
src/ILSVRC2012_devkit_t12.tar.gz
src/ILSVRC2012_devkit_t12/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ respectively.

```bash
$ cd ./src
$ python build_classification_localization_data.py
$ python build-imagenet-datasets.py
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@

Sample usage:

$ python build_classification_localization_data.py
Default behavior is to build all of the train, val, and test datasets.

$ python build-imagenet-datasets.py

You can also choose to build only some of the datasets.

$ python build-imagenet-datasets.py --no-val --no-test # only builds train
$ python build-imagenet-datasets.py --no-train --no-test # only build val

"""
import argparse
import glob
import os
import tarfile
Expand Down Expand Up @@ -79,19 +87,22 @@ def extract_validation_images(prefix):
print("Successfully extracted validation images!")


if __name__ == "__main__":

# extract the images from the provided .tar files
_prefix = f"{DATA_DIR}/jpeg" # the TESTING_TAR includes a test/ dir already
if not os.path.isdir(_prefix):
os.makedirs(_prefix)
extract_testing_images(_prefix)
parser = argparse.ArgumentParser()
parser.add_argument("--train", default=True, action="store_true")
parser.add_argument("--no-train", dest="train", action="store_false")
parser.add_argument("--val", default=True, action="store_true")
parser.add_argument("--no-val", dest="val", action="store_false")
parser.add_argument("--test", default=True, action="store_true")
parser.add_argument("--no-test", dest="test", action="store_false")
args = parser.parse_args()

if args.train:
_prefix = f"{DATA_DIR}/jpeg/train"
if not os.path.isdir(_prefix):
os.makedirs(_prefix)
extract_training_images(_prefix)

if args.val:
_prefix = f"{DATA_DIR}/jpeg/val"
if not os.path.isdir(_prefix):
os.makedirs(_prefix)
Expand All @@ -118,4 +129,9 @@ def extract_validation_images(prefix):
dst_image_path = f"{synset_path}/{validation_image}"
os.rename(src_image_path, dst_image_path)
assert(len(glob.glob(f"{prefix}/*.JPEG")) == 0)
print("Successfully built the Imagenet classification and localization data set!")

if args.test:
_prefix = f"{DATA_DIR}/jpeg" # the TESTING_TAR includes a test/ dir already
if not os.path.isdir(_prefix):
os.makedirs(_prefix)
extract_testing_images(_prefix)