#!/bin/bash

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

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

rm -rf $data_dir

mkdir -p $data_dir
mkdir -p $data_dir/train
mkdir -p $data_dir/val

tar -C $data_dir/train -xvf $file_train

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

tar -C $data_dir/val -xvf $file_val

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

python $ILSVRC2012_BASEDIR/HorovodKeras/Preprocessing/preprocess_imagenet_validation_data.py \
       $data_dir/val \
       $ILSVRC2012_BASEDIR/Dataset/Metadata/imagenet_2012_validation_synset_labels.txt

