initWorkspaceCaffeTools.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function initWorkspaceCaffeTools
  2. % function initWorkspaceCaffeTools
  3. %
  4. % Author: Alexander Freytag
  5. %
  6. % BRIEF:
  7. % Add local subfolders and 3rd party libraries to Matlabs work space.
  8. % Needs to be adapted to your system!
  9. %
  10. %
  11. % Exemplary call from external position:
  12. % CAFFETOOLDIR = '/place/to/this/repository/';
  13. % currentDir = pwd;
  14. % cd ( CAFFETOOLDIR );
  15. % initWorkspaceCaffeTools;
  16. % cd ( currentDir );
  17. %
  18. %% setup paths of 3rd-party libraries in a user-specific manner
  19. CAFFEDIR = [];
  20. if strcmp( getenv('USER'), 'freytag')
  21. [~, s_hostname] = system( 'hostname' );
  22. s_hostname = s_hostname ( 1:(length(s_hostname)-1) ) ;
  23. s_dest_caffebuild = sprintf( '/home/freytag/lib/caffe_%s/matlab/', s_hostname );
  24. CAFFEDIR = s_dest_caffebuild;
  25. CAFFEDIR = '/home/freytag/lib/caffe_pollux_2016_08_23';
  26. elseif strcmp( getenv('USER'), 'rodner')
  27. [~, s_hostname] = system( 'hostname' );
  28. s_hostname = 'pollux';%s_hostname ( 1:(length(s_hostname)-1) ) ;
  29. s_dest_caffebuild = sprintf( '/home/freytag/lib/caffe_%s/matlab/', s_hostname );
  30. CAFFEDIR = s_dest_caffebuild;
  31. elseif strcmp( getenv('USER'), 'simon')
  32. [~, s_hostname] = system( 'hostname' );
  33. s_hostname = s_hostname ( 1:(length(s_hostname)-1) ) ;
  34. s_dest_caffebuild = sprintf( '/home/freytag/lib/caffe_%s/matlab/', s_hostname );
  35. CAFFEDIR = '/home/simon/Research/lib/caffe.current/matlab/';%s_dest_caffebuild;
  36. elseif strcmp( getenv('USER'), 'alex')
  37. CAFFEDIR = '/home/alex/lib/caffe/matlab/';
  38. else
  39. fprintf('Unknown user %s and unknown default settings', getenv('USER') );
  40. end
  41. %% make path to caffe known as global variable
  42. global s_path_to_caffe;
  43. s_path_to_caffe = CAFFEDIR;
  44. %% add paths which come with this repository
  45. %%
  46. % add main path
  47. b_recursive = false;
  48. b_overwrite = true;
  49. s_pathMain = fullfile(pwd);
  50. addPathSafely ( s_pathMain, b_recursive, b_overwrite )
  51. clear ( 's_pathMain' );
  52. %% 3rd party, untouched
  53. if ( isempty(CAFFEDIR) )
  54. fprintf('initWorkspaceCaffeTools-WARNING - no CAFFEDIR dir found on your machine. Code is available at http://caffe.berkeleyvision.org/installation.html \n');
  55. else
  56. b_recursive = true;
  57. b_overwrite = true;
  58. addPathSafely ( CAFFEDIR, b_recursive, b_overwrite );
  59. end
  60. %% clean up
  61. clear( 'CAFFEDIR' );
  62. end
  63. function addPathSafely ( s_path, b_recursive, b_overwrite )
  64. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  65. if ( b_overwrite )
  66. if ( b_recursive )
  67. rmpath( genpath( s_path ) );
  68. else
  69. rmpath( s_path );
  70. end
  71. else
  72. fprintf('initWorkspaceCaffeTools - %s already in your path but overwriting de-activated.\n', s_path);
  73. return;
  74. end
  75. end
  76. if ( b_recursive )
  77. addpath( genpath( s_path ) );
  78. else
  79. addpath( s_path );
  80. end
  81. end