initWorkspaceCaffeTools.m 2.5 KB

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