initWorkspaceCaffeTools.m 3.2 KB

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