initWorkspaceCaffeTools.m 3.4 KB

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