initWorkspaceCaffeTools.m 3.1 KB

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