From 12479900b6cc29857a55e8825011e2259e231d51 Mon Sep 17 00:00:00 2001 From: diego0020 Date: Wed, 29 Apr 2015 14:05:44 -0500 Subject: [PATCH] cnn utilities --- scripts/iterate_hws.sh | 25 +++++++++++++++++++++++++ scripts/run_mat.sh | 31 +++++++++++++++++++++++++++++++ scripts/setup_dir.sh | 32 ++++++++++++++++++++++++++++++++ scripts/test_all.m | 9 +++++++++ scripts/test_net.m | 28 ++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 scripts/iterate_hws.sh create mode 100644 scripts/run_mat.sh create mode 100644 scripts/setup_dir.sh create mode 100644 scripts/test_all.m create mode 100644 scripts/test_net.m diff --git a/scripts/iterate_hws.sh b/scripts/iterate_hws.sh new file mode 100644 index 0000000..b30620f --- /dev/null +++ b/scripts/iterate_hws.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +readonly base_dir="/home/imagine/cnn/scripts" +readonly hws_dir="/home/imagine/cnn/hws" +function do_something(){ +echo hola +echo $1 +echo $2 +echo +#cd $hws_dir +#cd $1 +#gedit $2.m +cd $base_dir +./run_mat.sh $1 $2 +} + +function main(){ + +while read p; do +do_something $p +done < train_funcs.txt + +} + +main diff --git a/scripts/run_mat.sh b/scripts/run_mat.sh new file mode 100644 index 0000000..c6d1ec1 --- /dev/null +++ b/scripts/run_mat.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +readonly matlab="/usr/local/MATLAB/R2014b/bin/matlab" +readonly ml_flags="-nodesktop -noFigureWindows -nosplash" +readonly t_limit="4h" +readonly base_dir="/home/imagine/cnn/hws" +readonly mega_log="/home/imagine/cnn/scripts/mega_log.txt" + +function main(){ +local folder=$1 +local script=$2 + +cd $base_dir +cd $folder + +rm -rf "textons-experiment" +rm "train_log.txt" +local command="$matlab $ml_flags -logfile train_log.txt -r $script" +echo $command +echo -e "\n\n $folder \n =========================\n$command \n\n ">> $mega_log + +timeout -s1 --foreground $t_limit $command <<< "exit" +#$command + +echo -e "\n -Time is up- \n" >> train_log.txt + +cat train_log.txt >> $mega_log + +} + +main $@ diff --git a/scripts/setup_dir.sh b/scripts/setup_dir.sh new file mode 100644 index 0000000..e30862a --- /dev/null +++ b/scripts/setup_dir.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +function setup_dir(){ + +local target_dir=$1 +readonly base_dir=/home/imagine/cnn/practical +ln -s $base_dir/* $target_dir +} + +function setup_all(){ +local all_dirs=$(ls -1 $1) +for d in ${all_dirs}; do +echo $1/$d +setup_dir $1/$d +done +} + +function main(){ +if [ $# -ne 1 ]; then + echo Requires one argument +else + if [ -d $1 ]; then + setup_all $1 + else + echo $1 is not a directory + fi +fi + + + +} +main $@ diff --git a/scripts/test_all.m b/scripts/test_all.m new file mode 100644 index 0000000..3c030d7 --- /dev/null +++ b/scripts/test_all.m @@ -0,0 +1,9 @@ +for i = 1:length(dir_names) +n=dir_names(i).name; +try + s=test_net(n); +catch + s=0; +end +course_scores{i}=struct('name',n,'score',s) +end \ No newline at end of file diff --git a/scripts/test_net.m b/scripts/test_net.m new file mode 100644 index 0000000..7c44e62 --- /dev/null +++ b/scripts/test_net.m @@ -0,0 +1,28 @@ +function total_score=test_net(folder) +%run('/home/imagine/cnn/practical/setup.m'); +test_db=load('home/imagine/cnn/scripts/test_textons'); +cd('/home/imagine/cnn/hws'); +cd(folder) +cd textons-experiment +epochs=dir('net-epoch-*.mat'); +net_t=load(epochs(end).name); +net=net_t.net; +if strcmp(net.layers{end}.type, 'softmaxloss') + net.layers(end)=[]; +end + +total_score=0; +for i=1:length(test_db.patches) +label=test_db.labels(1); +p0=test_db.patches{i}; +p1=reshape(p0,128,128,1,[]); +res=vl_simplenn(net,p1); +resl=squeeze(res(end).x); +score=zeros(size(p0,3),1); +pred=score; +for j=1:size(resl,2) + [score(j),pred(j)]=max(resl(:,j)); +end +round_score=sum(pred==label); +total_score=total_score+ round_score; +end \ No newline at end of file