Skip to content

Commit

Permalink
fix generate_sub_average
Browse files Browse the repository at this point in the history
fix generate_sub_final_ensemble
update asanakoy bash scripts
fix main bash scritps
  • Loading branch information
asanakoy committed Oct 12, 2017
1 parent 205efdb commit a7e82d1
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 32 deletions.
3 changes: 2 additions & 1 deletion asanakoy/generate_sub_average.py
Expand Up @@ -42,7 +42,6 @@ def average_from_files(test_image_paths, probs_dirs, output_dir, should_save_mas
raise ValueError('{} not found'.format(dir_path))
if should_save_masks:
output_dir.mkdir(exist_ok=True)
print 'Number of samples:', len(test_image_paths)

all_rles = []
all_img_filenames = []
Expand Down Expand Up @@ -93,6 +92,7 @@ def main():
help='load pregenerated probs from folder?')
parser.add_argument('--net_name', choices=['scratch', 'vgg11v1'])
args = parser.parse_args()
print 'config.submissions_dir', config.submissions_dir

if args.net_name == 'vgg11v1':
probs_dirs = list()
Expand All @@ -118,6 +118,7 @@ def main():
else:
raise ValueError('Unknown net_name {}'.format(args.net_name))

probs_dirs = map(Path, probs_dirs)
with open(str(output_dir) + '.txt', mode='w') as f:
f.write('Following models were averaged:\n')
for l in probs_dirs:
Expand Down
5 changes: 4 additions & 1 deletion asanakoy/predict_scratch.sh
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -e # abort if any command fails

echo "PREDICT SCRATCH"
echo "---"

models_dir=$(python -c "import json, os; print os.path.expanduser(json.load(open('../config/config.json', 'r'))['models_dir'])")

BATCH=2 # batch size
Expand All @@ -18,4 +21,4 @@ for ((FOLD=0; FOLD<7; FOLD++)); do
python generate_sub.py -b=$BATCH -o "${o_dir}" --no_cudnn
done

python generate_sub_average.py --net_name=scratch -j=32
python generate_sub_average.py --net_name=scratch -j=4
5 changes: 4 additions & 1 deletion asanakoy/predict_vgg11v1.sh
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -e # abort if any command fails

echo "PREDICT VGG11v1"
echo "---"

models_dir=$(python -c "import json, os; print os.path.expanduser(json.load(open('../config/config.json', 'r'))['models_dir'])")

BATCH=2 # batch size
Expand All @@ -17,4 +20,4 @@ for ((FOLD=0; FOLD<7; FOLD++)); do
python generate_sub.py -b=$BATCH -o "${o_dir}" -net=vgg11v1 --no_cudnn
done

python generate_sub_average.py --net_name=vgg11v1 -j=32
python generate_sub_average.py --net_name=vgg11v1 -j=4
23 changes: 8 additions & 15 deletions asanakoy/train_scratch.sh
@@ -1,18 +1,16 @@
#!/usr/bin/env bash
set -e # abort if any command fails

echo "TRAIN SCRATCH"
echo "---"

epochs=250
should_gen_sub=1
models_dir=$(python -c "import json, os; print os.path.expanduser(json.load(open('../config/config.json', 'r'))['models_dir'])")

usage() { echo "Usage: $0 -f FOLD -b BATCH_SIZE -g GACC -e EPOCHS -n\n -n: to skip submission generation" 1>&2; exit 1; }
usage() { echo "Usage: $0 -b BATCH_SIZE -g GACC -e EPOCHS" 1>&2; exit 1; }

while getopts ":f:b:g:e:n" o; do
case "${o}" in
f)
i=${OPTARG}
((s >= 0 || s <= 6)) || usage
;;
b)
BATCH=${OPTARG}
;;
Expand All @@ -22,33 +20,31 @@ while getopts ":f:b:g:e:n" o; do
e)
epochs=${OPTARG}
;;
n)
should_gen_sub=0
;;
*)
echo "Unknown argument ${o}"
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${i}" ] || [ -z "${BATCH}" ] || [ -z "${gacc}" ] ; then
if [ -z "${BATCH}" ] || [ -z "${gacc}" ] ; then
echo "Not all reauired arguments were specified"
usage
fi

((BATCH == 1 || BATCH == 2 || BATCH == 4)) ||
{ echo "Wrong batch size! Only size 1, 2 or 4 is possible"; exit 1; }
((BATCH*gacc == 4)) ||
{ echo "Wrong batch size and GACC! BATCH * GACC must be equal 4! "; exit 1; }


for ((FOLD=i; FOLD<i+1; FOLD++)); do
for ((FOLD=0; FOLD<7; FOLD++)); do

echo "=========="
echo "FOLD $FOLD"
echo "BATCH $BATCH"
echo "gacc $gacc"
echo "epochs $epochs"
echo "should_gen_sub $should_gen_sub"
echo "=========="
echo ""

Expand All @@ -58,7 +54,4 @@ for ((FOLD=i; FOLD<i+1; FOLD++)); do
--lr=0.005 -opt=sgd --decay_step=100 --decay_gamma=0.5 \
-aug=2 --weight_decay=0.0005 \
-o="${o_dir}" --epochs=$epochs --no_cudnn

((should_gen_sub)) && python generate_sub.py -b=$BATCH \
-o "${o_dir}" --no_cudnn
done
34 changes: 31 additions & 3 deletions asanakoy/train_vgg11v1.sh
@@ -1,15 +1,41 @@
#!/usr/bin/env bash
set -e # abort if any command fails

BATCH=2
gacc=$((4/BATCH))
echo "TRAIN VGG11v1"
echo "---"

models_dir=$(python -c "import json, os; print os.path.expanduser(json.load(open('../config/config.json', 'r'))['models_dir'])")

usage() { echo "Usage: $0 -b BATCH_SIZE -g GACC"; exit 1; }

while getopts ":f:b:g:e:n" o; do
case "${o}" in
b)
BATCH=${OPTARG}
;;
g)
gacc=${OPTARG}
;;
*)
echo "Unknown argument ${o}"
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${BATCH}" ] || [ -z "${gacc}" ] ; then
echo "Not all reauired arguments were specified"
usage
fi

((BATCH == 1 || BATCH == 2 || BATCH == 4)) ||
{ echo "Wrong batch size! Only size 1, 2 or 4 is possible"; exit 1; }
((BATCH*gacc == 4)) ||
{ echo "Wrong batch size and GACC! BATCH * GACC must be equal 4! "; exit 1; }


# Calculate train car areas. To split on folds according to area
python calc_car_areas.py -j=2
python calc_car_area.py -j=2

for ((FOLD=0; FOLD<7; FOLD++)); do
echo "=========="
Expand All @@ -25,6 +51,8 @@ for ((FOLD=0; FOLD<7; FOLD++)); do
--lr=0.0001 -opt=adam --cyclic_lr=20 -aug=1 --no_cudnn --weight_decay=0 \
-o "$o_dir" --epochs=15

echo "Train after 15th epoch"
echo "-"
python run_train.py -net=vgg11v1 -imsize=1024 -b=$BATCH -gacc=$gacc -f=$FOLD -nf=7 -fv=2 \
--lr=0.0001 -opt=adam --cyclic_lr=20 -aug=0 --no_cudnn --weight_decay=0 \
-o "$o_dir" --epochs=60
Expand Down
9 changes: 4 additions & 5 deletions generate_sub_final_ensemble.py
Expand Up @@ -11,9 +11,9 @@
from sklearn.utils import gen_even_slices

import config
from data_utils import rle_encode
from data_utils import rle_to_string
from dataset import CARVANA
from asanakoy.data_utils import rle_encode
from asanakoy.data_utils import rle_to_string
from asanakoy.dataset import CARVANA


def load_from_files(test_image_paths, output_dir=None, is_quiet=False):
Expand Down Expand Up @@ -41,7 +41,6 @@ def average_from_files(test_image_paths, probs_dirs, output_dir, should_save_mas
if not dir_path.exists():
raise ValueError('{} not found'.format(dir_path))
output_dir.mkdir(exist_ok=True)
print 'Number of samples:', len(test_image_paths)

all_rles = []
all_img_filenames = []
Expand Down Expand Up @@ -101,7 +100,7 @@ def main():

probs_dirs = [
('test_scratch2', 1.0),
('test_vgg11v1_7folds_final', 1.0),
('test_vgg11v1_final', 1.0),
('albu/albu_sep27', 1.0),
('ternaus/ternaus_sep27', 1.0),
]
Expand Down
3 changes: 2 additions & 1 deletion predict.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# This script will run predict on test for all the networks and assemble a final submission file.

set -e # abort if any command fails
export PYTHONPATH=$(pwd):$PYTHONPATH

pushd asanakoy
Expand All @@ -10,6 +10,7 @@ popd

# TODO: albu, ternaus

echo "Generate final ensemble"
python generate_sub_final_ensemble.py -j=4
# TODO: fix van in final prediction using albu's script
# or include this fix in generate_sub_final_ensemble.py
9 changes: 6 additions & 3 deletions train.sh
@@ -1,8 +1,11 @@
#!/usr/bin/env bash
# This script will run training for all the networks.
set -e # abort if any command fails
export PYTHONPATH=$(pwd):$PYTHONPATH


bash asanakoy/train_scratch.sh
bash asanakoy/train_vgg11v1.sh
pushd asanakoy
bash train_scratch.sh -b1 -g4
bash train_vgg11v1.sh -b1 -g4
popd

# TODO: albu, ternaus
4 changes: 2 additions & 2 deletions train_and_predict.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# This script will run all trainings, run all predicts and assemble a final submission file.

bash train.sh
bash predict.sh
bash train.sh || exit 1
bash predict.sh || exit 1

0 comments on commit a7e82d1

Please sign in to comment.