#!/bin/bash

file_train=$ILSVRC2012_BASEDIR/Dataset/RawData/ILSVRC2012_img_train.tar
labels_train=$ILSVRC2012_BASEDIR/Dataset/Metadata/train.txt
output_train=$ILSVRC2012_BASEDIR/Dataset/PostProcessedLMDB/train

rm -rf $TMPDIR/input
rm -rf $output_train

mkdir -p $TMPDIR/input

echo "=========== Unzipping training dataset `date` ============="

tar -C $TMPDIR/input -xvf $file_train

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

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

GLOG_logtostderr=1 $CAFFE_BIN/convert_imageset --resize_height=256 --resize_width=256 --shuffle $TMPDIR/input/ $labels_train $output_train

echo "=========== Computing image mean file `date` =============="

$CAFFE_BIN/compute_image_mean $output_train $output_train/imagenet_mean.binaryproto
