Skip to content

Commit

Permalink
add imagenet-2-ofrecord tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowingsun007 committed Jul 1, 2020
1 parent 24bce17 commit 5001c83
Show file tree
Hide file tree
Showing 7 changed files with 73,655 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# IDE
.idea

# C extensions
*.so

Expand Down
37 changes: 37 additions & 0 deletions Classification/tools/extract_trainval.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# usage: sh extract_trainval.sh your_path_to/imagenet
# 参数指定存放imagenet元素数据的文件夹路径

set -e
ROOT_DIR=$1 # your path to imagenet dataset root dir
echo "Imagenet dataset in dir:${ROOT_DIR}"

SYNSETS_FILE="imagenet_lsvrc_2015_synsets.txt"
TRAIN_TARBALL="${ROOT_DIR}/ILSVRC2012_img_train.tar"
TRAIN_OUTPUT_PATH="${ROOT_DIR}/train/"
VALIDATION_TARBALL="${ROOT_DIR}/ILSVRC2012_img_val.tar"
VALIDATION_OUTPUT_PATH="${ROOT_DIR}/validation/"

mkdir -p "${TRAIN_OUTPUT_PATH}"
mkdir -p "${VALIDATION_OUTPUT_PATH}"

# extract .tar file of validation
tar xf "${VALIDATION_TARBALL}" -C "${VALIDATION_OUTPUT_PATH}"

# extract .tar file of train
echo "Uncompressing individual train tar-balls in the training data."

while read SYNSET; do
# Uncompress into the directory.
tar xf "${TRAIN_TARBALL}" "${SYNSET}.tar"
if [ "$?" = "0" ];then
# Create a directory and delete anything there.
mkdir -p "${TRAIN_OUTPUT_PATH}/${SYNSET}"
rm -rf "${TRAIN_OUTPUT_PATH}/${SYNSET}/*"
echo "Processing: ${SYNSET}"
tar xf "${SYNSET}.tar" -C "${TRAIN_OUTPUT_PATH}/${SYNSET}/"
rm -f "${SYNSET}.tar"
echo "Finished processing: ${SYNSET}"
else
echo "${SYNSET}.tar doesn't exist!"
fi
done < "${SYNSETS_FILE}"
Loading

0 comments on commit 5001c83

Please sign in to comment.