Skip to content

Commit

Permalink
cnn utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
diego0020 committed Apr 29, 2015
1 parent 8b5fdff commit 1247990
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/iterate_hws.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/run_mat.sh
Original file line number Diff line number Diff line change
@@ -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 $@
32 changes: 32 additions & 0 deletions scripts/setup_dir.sh
Original file line number Diff line number Diff line change
@@ -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 $@
9 changes: 9 additions & 0 deletions scripts/test_all.m
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions scripts/test_net.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1247990

Please sign in to comment.