Friday, September 5, 2014

Script to create in a bash script

Here is a shell script I use to create multiple nohup commands and put them in bash script called scripts1to100.txt. Each nohup command runs a matlab function called  runFunctionWithVariablesAandB which takes a and b as inputs.

for i in {1..100};
 do
let a=(i-1)*100+1;
let b=i*100;
echo nohup matlab -nodisplay -nosplash -r \"runFunctionWithVariablesAandB\($a:$b\)\; exit\;\" \> \/home\/logs\/batch$i.log \& >>scriptsFor1to100.txt;
 done

Once script1to100.txt is ready, you can run it by calling 'bash script1to100.txt'

Note: This particular script launches 100 parallel runs of runFunctionWithVariablesAandB, each with a different set of inputs.

Tuesday, September 2, 2014

Inserting text in visual mode in vim

Steps:

1) Ctrl+v (takes you to visual mode)
2) up/down/left/right arrows to select location for inserting text.
3) Gto select all lines in the file
4) Actual commands for inserting: 'I' takes to insert mode
5) type the text you want to insert. It gets inserted in the first line
6) hit Esc. the inserting done in all the lines you selected.

Friday, August 29, 2014

Comparing strings

strcmp(var,'<string>')

Thursday, August 28, 2014

checking for a field in struct matlab

To check if stuct S has a field called 'fieldName', use:

isfield(S, 'fieldname')

Tuesday, August 19, 2014

Changes to run BING (objectness)

General changes to run on our servers:
-- In the objectness folder: change line 15:
from
set(OPENMP_FLAG "-fopenmp -std=c++11 -ftree-vectorize")
to
set(OPENMP_FLAG "-fopenmp -std=c++0x -ftree-vectorize")
--Put absolute path to the dataset as opposed to relativepath in Main.cpp


Specific changes to make it compaible with ImageNet:
in Objectness/CmFile.cpp line number: added these lines:
415                                     if (line.find (' ') != string::npos)
416                                     {
417                                       int position = line.find (' ');
418                                       strs.push_back(line.substr(0,position));
419                                     }
420                                       else
421                                       strs.push_back(line);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
The xml annotation file had some inconsistencies for imagenet:
                        ILSVRC2012_val_00029561.xml
                        ILSVRC2012_val_00047711
                        ILSVRC2012_val_00037916
                        ILSVRC2012_val_00027851
                        ILSVRC2012_val_00008272
                           ILSVRC2012_val_00004948
                            ILSVRC2012_val_00000400
                           ILSVRC2012_val_00008009
                          ILSVRC2012_val_00019545
                         ILSVRC2012_val_00032716
                         ILSVRC2012_val_00000922
                         ILSVRC2012_val_00023854
                         ILSVRC2012_val_00035744
  ILSVRC2012_val_00019316
ILSVRC2012_val_00021400
ILSVRC2012_val_00004522
ILSVRC2012_val_00006974
and many more. this cannot be done manually.!
(the coordinates cannot be 0 in matlab!)

%%%%%%%%%%%%%%%
The changes in everything above xml file issues can be ignored




Monday, August 11, 2014

deleting data from a cell in matlab

if A is a cell:
A{m,n}=[] creates an empty element in the (m,n) index
A(m,:)=[] deletes the entire m'th row, A ow has one less row 

Monday, August 4, 2014

Replacing some part of a string or remmoving a part of a string

a=<your_string>
 b=`echo $a | sed 's/<string_you_want_to_replace>//'

(you don't need to put any quotes around <string_you_want_to_replace>)

Sunday, July 20, 2014

some imp commands to be edited later..


 perl -pi -e 's/batchSIFTflow1/batchSIFTflowUsingDecaf/g' myBatchSIFTFLowDecaf*.m
 grep  batchSIFTflowUsingDecaf myBatchSIFTFLowDeca*.m
 perl -pi -e 's/gistL2/DecafL2/g' myBatchSIFTFLowDecaf*.m
 diff myBatchSIFTflow16.m myBatchSIFTFLowDecaf16.m
 sed 's/flow1/flowUsingDecaf/g' myBatchSIFTflow16.m | sed 's/,1,/,20,/g' | sed 's/gistL2/DecafL2/g' > tmp
 diff myBatchSIFTflow16.m tmp
 for i in {1..47}; do sed 's/flow1/flowUsingDecaf/g' myBatchSIFTflow$i.m | sed 's/,1,/,20,/g' | sed 's/gistL2/DecafL2/g' > myBatchSIFTFLowDecaf$i.m; done

Replacing strings in a file

 perl -pi -e 's/pattern/patternToReplace/g' fileName.ext

for i in {2..200}; do
sed 's/xx/'$i'/g' template.m > select-$i.m
done

Counting the files in all sub drectories of a folder

Assumptions:
Given a directory; it has n subdirectories and does not have any files. The subdirectories jsut have files and no folders.
You want to count all the files in the n sub directories.

here's a shell script:
filecount=0;
for i in $(ls);
do
cd $i;
a=$(ls | wc -l) ;
filecount=$[filecount+a];
echo $filecount;
cd ..;
done

adding numbers is a bash script

num=$[num1+num2]
there are many more options, but this is the simplest.
Note no spaces between any of the characters above

Tuesday, April 8, 2014

initializing cell arrays

a=cell(dim)

Monday, March 24, 2014

changing group permissions

chgroup -R <groupname> <file/foldername>

Sunday, March 16, 2014

Some useful commands.. to be edited later..

root@master:/home/cloudcv/detection_executable/PascalImagenetDetector/distrib# cat job.x

output_dir=$1
model_name=$2

./run_PascalImagenetBboxPredictor.sh /usr/local/MATLAB/MATLAB_Compiler_Runtime/v81/ "/home/cloudcv/detection_executable/input_images/im_folder_xx/" "/home/cloudcv/detection_executable/model/" "$output_dir" "0" "$model_name"


for i in {1..50}; do sed 's/xx/'$i'/g' job.x  > job.$i; done

Saturday, March 15, 2014

some printing formats..

for i in {0..10};do printf "%02d\n" $i; done

for i in {000..100};do echo $i; done

Wednesday, March 12, 2014

putty windows ssh using GUI option

http://www.ece.unm.edu/csg/email/XServer_Putty_Windows7-ECE.pdf

Monday, February 10, 2014

unix command to remove everything after a character in a string

suppose you want to remove everything in a string after the character  '_'
The command you would use would be:
i=<your string>
j=${i%%_*}


something i have used in the past.
for i in $(ls); do cd ../$i|cut -d '_' -f1; echo pwd; cd ../geo_color/;  done

Using visual bloc to paste chunks of data

I was having trouble pasting text selected using vim's visual block into a new file.
The copy command is 'y'
The paste command is 'p'
the delete command is 'd' or 'x'
However, the delete command seems to leave behind empty lines. use ':g/^$/d' to remove empty lines from a file
 

Thursday, February 6, 2014

Setting Environment variables

<variable> = value
export <variable>

Creating an AMI using starcluster

These instructions are pretty straightforward to follow. I found it very difficult to create one directly from amazon's documentation.

http://star.mit.edu/cluster/docs/0.93.3/manual/create_new_ami.html

Tuesday, January 28, 2014

Things to remember when using parfor

This website from matlab:
http://www.mathworks.com/help/distcomp/programming-considerations.html

-- cannot use clear inside the loop


specifically:

=========
Similarly, you cannot clear variables from a worker's workspace by executing clear inside a parfor statement:
parfor ii= 1:4
    <statements...>
    clear('X')  % cannot clear: transparency violation
    <statements...>
end
As a workaround, you can free up most of the memory used by a variable by setting its value to empty, presumably when it is no longer needed in your parfor statement:
parfor ii= 1:4
    <statements...>
    X = [];
    <statements...>
end
 =============