caffe

Форк
0
41 строка · 1.7 Кб
1
classdef io
2
  % a class for input and output functions
3
  
4
  methods (Static)
5
    function im_data = load_image(im_file)
6
      % im_data = load_image(im_file)
7
      %   load an image from disk into Caffe-supported data format
8
      %   switch channels from RGB to BGR, make width the fastest dimension
9
      %   and convert to single
10
      %   returns im_data in W x H x C. For colored images, C = 3 in BGR
11
      %   channels, and for grayscale images, C = 1
12
      CHECK(ischar(im_file), 'im_file must be a string');
13
      CHECK_FILE_EXIST(im_file);
14
      im_data = imread(im_file);
15
      % permute channels from RGB to BGR for colored images
16
      if size(im_data, 3) == 3
17
        im_data = im_data(:, :, [3, 2, 1]);
18
      end
19
      % flip width and height to make width the fastest dimension
20
      im_data = permute(im_data, [2, 1, 3]);
21
      % convert from uint8 to single
22
      im_data = single(im_data);
23
    end
24
    function mean_data = read_mean(mean_proto_file)
25
      % mean_data = read_mean(mean_proto_file)
26
      %   read image mean data from binaryproto file
27
      %   returns mean_data in W x H x C with BGR channels
28
      CHECK(ischar(mean_proto_file), 'mean_proto_file must be a string');
29
      CHECK_FILE_EXIST(mean_proto_file);
30
      mean_data = caffe_('read_mean', mean_proto_file);
31
    end
32
    function write_mean(mean_data, mean_proto_file)
33
      % write_mean(mean_data, mean_proto_file)
34
      %   write image mean data to binaryproto file
35
      %   mean_data should be W x H x C with BGR channels
36
      CHECK(ischar(mean_proto_file), 'mean_proto_file must be a string');
37
      CHECK(isa(mean_data, 'single'), 'mean_data must be a SINGLE matrix');
38
      caffe_('write_mean', mean_data, mean_proto_file);
39
    end   
40
  end
41
end
42

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.