#!/bin/bash

file_train=$ILSVRC2012_BASEDIR/Dataset/RawData/ILSVRC2012_img_train.tar
file_val=$ILSVRC2012_BASEDIR/Dataset/RawData/ILSVRC2012_img_val.tar

echo "=========== Unzipping dataset to TMP `date` ============="

rm -rf $TMPDIR/input

mkdir -p $TMPDIR/input/train
mkdir -p $TMPDIR/input/val

tar -C $TMPDIR/input/train -xvf $file_train

for f in $TMPDIR/input/train/*.tar; do    d=`basename $f .tar`;   mkdir $TMPDIR/input/train/$d;   tar -C $TMPDIR/input/train/$d -xf $f; rm -f $f; done

tar -C $TMPDIR/input/val -xvf $file_val

echo "=========== Rearranging validation `date` =============="

python $ILSVRC2012_BASEDIR/Tensorflow1.1/Preprocessing/preprocess_imagenet_validation_data.py \
       $TMPDIR/input/val \
       $ILSVRC2012_BASEDIR/Dataset/Metadata/imagenet_2012_validation_synset_labels.txt

echo "=========== Processing training `date` =============="

python $ILSVRC2012_BASEDIR/Tensorflow1.1/Preprocessing/build_imagenet_data.py \
       --num_threads 128 \
       --train_directory $TMPDIR/input/train/ \
       --validation_directory $TMPDIR/input/val \
       --output_directory $ILSVRC2012_BASEDIR/Dataset/PostProcessedTFRecords \
       --imagenet_metadata_file $ILSVRC2012_BASEDIR/Dataset/Metadata/image_metadata_file.txt \
       --bounding_box_file $ILSVRC2012_BASEDIR/Dataset/Metadata/imagenet_2012_bounding_boxes.csv \
       --labels_file $ILSVRC2012_BASEDIR/Dataset/Metadata/synsets.txt

