ruby-dnn 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dnn/ext/cifar10_loader/cifar10_loader.c +43 -0
  3. data/lib/dnn/ext/cifar10_loader/extconf.rb +3 -0
  4. data/lib/dnn/ext/rb_stb_image/rb_stb_image.c +18 -36
  5. data/lib/dnn/lib/cifar10.rb +8 -6
  6. data/lib/dnn/lib/image_io.rb +9 -7
  7. data/lib/dnn/lib/mnist.rb +3 -2
  8. data/lib/dnn/version.rb +1 -1
  9. data/ruby-dnn.gemspec +1 -1
  10. metadata +5 -63
  11. data/lib/dnn/ext/dataset_loader/dataset_loader.c +0 -90
  12. data/lib/dnn/ext/dataset_loader/extconf.rb +0 -3
  13. data/lib/dnn/ext/dataset_loader/numo/compat.h +0 -23
  14. data/lib/dnn/ext/dataset_loader/numo/extconf.h +0 -13
  15. data/lib/dnn/ext/dataset_loader/numo/intern.h +0 -117
  16. data/lib/dnn/ext/dataset_loader/numo/narray.h +0 -430
  17. data/lib/dnn/ext/dataset_loader/numo/ndloop.h +0 -94
  18. data/lib/dnn/ext/dataset_loader/numo/template.h +0 -149
  19. data/lib/dnn/ext/dataset_loader/numo/types/bit.h +0 -33
  20. data/lib/dnn/ext/dataset_loader/numo/types/complex.h +0 -409
  21. data/lib/dnn/ext/dataset_loader/numo/types/complex_macro.h +0 -377
  22. data/lib/dnn/ext/dataset_loader/numo/types/dcomplex.h +0 -44
  23. data/lib/dnn/ext/dataset_loader/numo/types/dfloat.h +0 -42
  24. data/lib/dnn/ext/dataset_loader/numo/types/float_def.h +0 -34
  25. data/lib/dnn/ext/dataset_loader/numo/types/float_macro.h +0 -186
  26. data/lib/dnn/ext/dataset_loader/numo/types/int16.h +0 -24
  27. data/lib/dnn/ext/dataset_loader/numo/types/int32.h +0 -24
  28. data/lib/dnn/ext/dataset_loader/numo/types/int64.h +0 -24
  29. data/lib/dnn/ext/dataset_loader/numo/types/int8.h +0 -24
  30. data/lib/dnn/ext/dataset_loader/numo/types/int_macro.h +0 -41
  31. data/lib/dnn/ext/dataset_loader/numo/types/real_accum.h +0 -486
  32. data/lib/dnn/ext/dataset_loader/numo/types/robj_macro.h +0 -75
  33. data/lib/dnn/ext/dataset_loader/numo/types/robject.h +0 -27
  34. data/lib/dnn/ext/dataset_loader/numo/types/scomplex.h +0 -44
  35. data/lib/dnn/ext/dataset_loader/numo/types/sfloat.h +0 -43
  36. data/lib/dnn/ext/dataset_loader/numo/types/uint16.h +0 -21
  37. data/lib/dnn/ext/dataset_loader/numo/types/uint32.h +0 -21
  38. data/lib/dnn/ext/dataset_loader/numo/types/uint64.h +0 -21
  39. data/lib/dnn/ext/dataset_loader/numo/types/uint8.h +0 -21
  40. data/lib/dnn/ext/dataset_loader/numo/types/uint_macro.h +0 -32
  41. data/lib/dnn/ext/dataset_loader/numo/types/xint_macro.h +0 -189
  42. data/lib/dnn/ext/rb_stb_image/numo/compat.h +0 -23
  43. data/lib/dnn/ext/rb_stb_image/numo/extconf.h +0 -13
  44. data/lib/dnn/ext/rb_stb_image/numo/intern.h +0 -117
  45. data/lib/dnn/ext/rb_stb_image/numo/narray.h +0 -430
  46. data/lib/dnn/ext/rb_stb_image/numo/ndloop.h +0 -94
  47. data/lib/dnn/ext/rb_stb_image/numo/template.h +0 -149
  48. data/lib/dnn/ext/rb_stb_image/numo/types/bit.h +0 -33
  49. data/lib/dnn/ext/rb_stb_image/numo/types/complex.h +0 -409
  50. data/lib/dnn/ext/rb_stb_image/numo/types/complex_macro.h +0 -377
  51. data/lib/dnn/ext/rb_stb_image/numo/types/dcomplex.h +0 -44
  52. data/lib/dnn/ext/rb_stb_image/numo/types/dfloat.h +0 -42
  53. data/lib/dnn/ext/rb_stb_image/numo/types/float_def.h +0 -34
  54. data/lib/dnn/ext/rb_stb_image/numo/types/float_macro.h +0 -186
  55. data/lib/dnn/ext/rb_stb_image/numo/types/int16.h +0 -24
  56. data/lib/dnn/ext/rb_stb_image/numo/types/int32.h +0 -24
  57. data/lib/dnn/ext/rb_stb_image/numo/types/int64.h +0 -24
  58. data/lib/dnn/ext/rb_stb_image/numo/types/int8.h +0 -24
  59. data/lib/dnn/ext/rb_stb_image/numo/types/int_macro.h +0 -41
  60. data/lib/dnn/ext/rb_stb_image/numo/types/real_accum.h +0 -486
  61. data/lib/dnn/ext/rb_stb_image/numo/types/robj_macro.h +0 -75
  62. data/lib/dnn/ext/rb_stb_image/numo/types/robject.h +0 -27
  63. data/lib/dnn/ext/rb_stb_image/numo/types/scomplex.h +0 -44
  64. data/lib/dnn/ext/rb_stb_image/numo/types/sfloat.h +0 -43
  65. data/lib/dnn/ext/rb_stb_image/numo/types/uint16.h +0 -21
  66. data/lib/dnn/ext/rb_stb_image/numo/types/uint32.h +0 -21
  67. data/lib/dnn/ext/rb_stb_image/numo/types/uint64.h +0 -21
  68. data/lib/dnn/ext/rb_stb_image/numo/types/uint8.h +0 -21
  69. data/lib/dnn/ext/rb_stb_image/numo/types/uint_macro.h +0 -32
  70. data/lib/dnn/ext/rb_stb_image/numo/types/xint_macro.h +0 -189
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f0d01c2a4696fdf876c6f247a7ea7e41bd57f4d42d2e0065a3703c4faf5a7cc
4
- data.tar.gz: 29bcebf1ae90f3b6f72dd391fbba9118162dc49f490b801d1e634f736cc580a4
3
+ metadata.gz: 8156ccf7edaf425d09a1463bb1c9280a1eeddaa67448323a19d301d451a78a0f
4
+ data.tar.gz: 851e5aa8c87fd60ee9d5296f995c9b884a1bcaed823ab9e5d034f0b7b52d740b
5
5
  SHA512:
6
- metadata.gz: b7b01228b299fbf42ec74f0d4678e6ffd62775a606ecadba3253ce76fd62166699851450d359f13022b01023219b8f710ef75c75af6c1096591df180a49edd62
7
- data.tar.gz: 2eb11ae75136aa6be186d81c1fe8c04d585167ce31feccdd26406d58cafd6f333080c871723ad533e9f3ad0fb677c08180ee9925e99040f093f90a08a7f24631
6
+ metadata.gz: 520b9dc2ff534d36d86af82750b12a1772d29b487cfc18e02425f14c006e9fc1a15c525a0f1cfbe1ce541d2c7cac0cc7649a0542f3b9448634daf9869471f5d3
7
+ data.tar.gz: 2ffe038bc5e5b69c61f32f99e9b21df8b2321b32148c6226d85e9aa82cedd8bade8bcbdab66c983a827a923ab3d3e449bb03cedb4c52f9b34fcbd1a732220e43
@@ -0,0 +1,43 @@
1
+ #include <ruby.h>
2
+ #include <stdlib.h>
3
+
4
+ #define CIFAR10_WIDTH 32
5
+ #define CIFAR10_HEIGHT 32
6
+ #define CIFAR10_CHANNEL 3
7
+
8
+ VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
9
+ char* bin = StringValuePtr(rb_bin);
10
+ int num_datas = FIX2INT(rb_num_datas);
11
+ VALUE rb_x_bin;
12
+ VALUE rb_y_bin;
13
+ int i;
14
+ int j = 0;
15
+ int k = 0;
16
+ int size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
17
+ int x_bin_size = num_datas * size;
18
+ int y_bin_size = num_datas;
19
+ char* x_bin;
20
+ char* y_bin;
21
+
22
+ x_bin = (char*)malloc(x_bin_size);
23
+ y_bin = (char*)malloc(y_bin_size);
24
+ for (i = 0; i < num_datas; i++) {
25
+ y_bin[i] = bin[j];
26
+ j++;
27
+ memcpy(&x_bin[k], &bin[j], size);
28
+ j += size;
29
+ k += size;
30
+ }
31
+ rb_x_bin = rb_str_new(x_bin, x_bin_size);
32
+ rb_y_bin = rb_str_new(y_bin, y_bin_size);
33
+ free(x_bin);
34
+ free(y_bin);
35
+ return rb_ary_new3(2, rb_x_bin, rb_y_bin);
36
+ }
37
+
38
+ void Init_cifar10_loader() {
39
+ VALUE rb_dnn = rb_define_module("DNN");
40
+ VALUE rb_cifar10 = rb_define_module_under(rb_dnn, "CIFAR10");
41
+
42
+ rb_define_singleton_method(rb_cifar10, "load_binary", cifar10_load_binary, 2);
43
+ }
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("cifar10_loader")
@@ -1,5 +1,4 @@
1
1
  #include <ruby.h>
2
- #include "numo/narray.h"
3
2
 
4
3
  #define STB_IMAGE_IMPLEMENTATION
5
4
  #define STB_IMAGE_WRITE_IMPLEMENTATION
@@ -12,79 +11,62 @@ VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
12
11
  char* filename = StringValuePtr(rb_filename);
13
12
  int x, y, n;
14
13
  int req_comp = FIX2INT(rb_req_comp);
15
- unsigned char* pixels;
16
- narray_data_t* na_data;
17
- char script[64];
14
+ unsigned char* data;
18
15
  int ch;
19
16
  VALUE rb_x, rb_y, rb_n;
20
- VALUE rb_pixels;
17
+ VALUE rb_data;
21
18
 
22
- pixels = stbi_load(filename, &x, &y, &n, req_comp);
19
+ data = stbi_load(filename, &x, &y, &n, req_comp);
23
20
  rb_x = INT2FIX(x);
24
21
  rb_y = INT2FIX(y);
25
22
  rb_n = INT2FIX(n);
26
23
  ch = req_comp == 0 ? n : req_comp;
27
- sprintf(script, "Numo::UInt8.zeros(%d, %d, %d)", y, x, ch);
28
- rb_pixels = rb_eval_string(&script[0]);
29
- na_data = RNARRAY_DATA(rb_pixels);
30
- memcpy(na_data->ptr, pixels, na_data->base.size);
31
- stbi_image_free(pixels);
32
- return rb_ary_new3(4, rb_pixels, rb_x, rb_y, rb_n);
24
+ rb_data = rb_str_new((char*)data, y * x * ch);
25
+ stbi_image_free(data);
26
+ return rb_ary_new3(4, rb_data, rb_x, rb_y, rb_n);
33
27
  }
34
28
 
35
29
  //STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
36
- VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_pixels, VALUE rb_stride_in_bytes) {
30
+ VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_stride_in_bytes) {
37
31
  char* filename = StringValuePtr(rb_filename);
38
32
  int w = FIX2INT(rb_w);
39
33
  int h = FIX2INT(rb_h);
40
34
  int comp = FIX2INT(rb_comp);
41
- unsigned char* pixels;
35
+ unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
42
36
  int stride_in_bytes = FIX2INT(rb_stride_in_bytes);
43
- narray_data_t* na_data;
44
37
  int result;
45
38
 
46
- na_data = RNARRAY_DATA(rb_pixels);
47
- pixels = (unsigned char*)malloc(na_data->base.size);
48
- memcpy(pixels, na_data->ptr, na_data->base.size);
49
- result = stbi_write_png(filename, w, h, comp, pixels, stride_in_bytes);
50
- stbi_image_free(pixels);
39
+ result = stbi_write_png(filename, w, h, comp, data, stride_in_bytes);
40
+ stbi_image_free(data);
51
41
  return INT2FIX(result);
52
42
  }
53
43
 
54
44
  //STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
55
- VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_pixels) {
45
+ VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
56
46
  char* filename = StringValuePtr(rb_filename);
57
47
  int w = FIX2INT(rb_w);
58
48
  int h = FIX2INT(rb_h);
59
49
  int comp = FIX2INT(rb_comp);
60
- unsigned char* pixels;
61
- narray_data_t* na_data;
50
+ unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
62
51
  int result;
63
52
 
64
- na_data = RNARRAY_DATA(rb_pixels);
65
- pixels = (unsigned char*)malloc(na_data->base.size);
66
- memcpy(pixels, na_data->ptr, na_data->base.size);
67
- result = stbi_write_bmp(filename, w, h, comp, pixels);
68
- stbi_image_free(pixels);
53
+ result = stbi_write_bmp(filename, w, h, comp, data);
54
+ stbi_image_free(data);
69
55
  return INT2FIX(result);
70
56
  }
71
57
 
72
58
  //STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
73
- VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_pixels, VALUE rb_quality) {
59
+ VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_quality) {
74
60
  char* filename = StringValuePtr(rb_filename);
75
61
  int w = FIX2INT(rb_w);
76
62
  int h = FIX2INT(rb_h);
77
63
  int comp = FIX2INT(rb_comp);
78
- unsigned char* pixels;
64
+ unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
79
65
  int quality = FIX2INT(rb_quality);
80
- narray_data_t* na_data;
81
66
  int result;
82
67
 
83
- na_data = RNARRAY_DATA(rb_pixels);
84
- pixels = (unsigned char*)malloc(na_data->base.size);
85
- memcpy(pixels, na_data->ptr, na_data->base.size);
86
- result = stbi_write_jpg(filename, w, h, comp, pixels, quality);
87
- stbi_image_free(pixels);
68
+ result = stbi_write_jpg(filename, w, h, comp, data, quality);
69
+ stbi_image_free(data);
88
70
  return INT2FIX(result);
89
71
  }
90
72
 
@@ -1,5 +1,5 @@
1
1
  require "dnn"
2
- require "dnn/ext/dataset_loader/dataset_loader"
2
+ require "dnn/ext/cifar10_loader/cifar10_loader"
3
3
  require "open-uri"
4
4
  require "zlib"
5
5
  require "archive/tar/minitar"
@@ -13,7 +13,7 @@ module DNN
13
13
 
14
14
  class DNN_CIFAR10_DownloadError < DNN_Error; end
15
15
 
16
- private_class_method :_cifar10_load
16
+ private_class_method :load_binary
17
17
 
18
18
  def self.downloads
19
19
  return if Dir.exist?(__dir__ + "/" + CIFAR10_DIR)
@@ -42,8 +42,9 @@ module DNN
42
42
  raise DNN_CIFAR10_LoadError.new(%`file "#{fname}" is not found.`) unless File.exist?(fname)
43
43
  bin << File.binread(fname)
44
44
  end
45
- x_train, y_train = _cifar10_load(bin, 50000)
46
- x_train = x_train.transpose(0, 2, 3, 1).clone
45
+ x_bin, y_bin = load_binary(bin, 50000)
46
+ x_train = Numo::UInt8.from_binary(x_bin).reshape(50000, 3, 32, 32).transpose(0, 2, 3, 1).clone
47
+ y_train = Numo::UInt8.from_binary(y_bin)
47
48
  [x_train, y_train]
48
49
  end
49
50
 
@@ -52,8 +53,9 @@ module DNN
52
53
  fname = __dir__ + "/#{CIFAR10_DIR}/test_batch.bin"
53
54
  raise DNN_CIFAR10_LoadError.new(%`file "#{fname}" is not found.`) unless File.exist?(fname)
54
55
  bin = File.binread(fname)
55
- x_test, y_test = _cifar10_load(bin, 10000)
56
- x_test = x_test.transpose(0, 2, 3, 1).clone
56
+ x_bin, y_bin = load_binary(bin, 10000)
57
+ x_test = Numo::UInt8.from_binary(x_bin).reshape(10000, 3, 32, 32).transpose(0, 2, 3, 1).clone
58
+ y_test = Numo::UInt8.from_binary(y_bin)
57
59
  [x_test, y_test]
58
60
  end
59
61
  end
@@ -5,26 +5,28 @@ module DNN
5
5
  module ImageIO
6
6
  def self.read(file_name)
7
7
  raise ImageIO::ReadError.new("#{file_name} is not found.") unless File.exist?(file_name)
8
- img, = Stb.stbi_load(file_name, 3)
9
- img
8
+ bin, w, h, n = Stb.stbi_load(file_name, 3)
9
+ img = Numo::UInt8.from_binary(bin)
10
+ img.reshape(h, w, 3)
10
11
  end
11
12
 
12
13
  def self.write(file_name, img, quality: 100)
13
- img = img.clone
14
14
  if img.shape.length == 2
15
15
  img = Numo::UInt8[img, img, img].transpose(1, 2, 0).clone
16
16
  elsif img.shape[2] == 1
17
17
  img = img.shape(img.shape[0], img.shape[1])
18
18
  img = Numo::UInt8[img, img, img].transpose(1, 2, 0).clone
19
19
  end
20
+ h, w, ch = img.shape
21
+ bin = img.to_binary
20
22
  case file_name
21
23
  when /\.png$/
22
- stride_in_bytes = img.shape[0] * img.shape[2]
23
- Stb.stbi_write_png(file_name, *img.shape, img, stride_in_bytes)
24
+ stride_in_bytes = w * ch
25
+ Stb.stbi_write_png(file_name, w, h, ch, bin, stride_in_bytes)
24
26
  when /\.bmp$/
25
- Stb.stbi_write_bmp(file_name, *img.shape, img)
27
+ Stb.stbi_write_bmp(file_name, w, h, ch, bin)
26
28
  when /\.jpg$/
27
- Stb.stbi_write_jpg(file_name, *img.shape, img, quality)
29
+ Stb.stbi_write_jpg(file_name, w, h, ch, bin, quality)
28
30
  end
29
31
  rescue => ex
30
32
  raise ImageIO::WriteError.new(ex.message)
data/lib/dnn/lib/mnist.rb CHANGED
@@ -73,7 +73,8 @@ module DNN
73
73
  Zlib::GzipReader.open(file_name) do |f|
74
74
  magic, num_images = f.read(8).unpack("N2")
75
75
  rows, cols = f.read(8).unpack("N2")
76
- images = _mnist_load_images(f.read, num_images, cols, rows)
76
+ images = Numo::UInt8.from_binary(f.read)
77
+ images = images.reshape(num_images, cols, rows)
77
78
  end
78
79
  images
79
80
  end
@@ -82,7 +83,7 @@ module DNN
82
83
  labels = nil
83
84
  Zlib::GzipReader.open(file_name) do |f|
84
85
  magic, num_labels = f.read(8).unpack("N2")
85
- labels = _mnist_load_labels(f.read, num_labels)
86
+ labels = Numo::UInt8.from_binary(f.read)
86
87
  end
87
88
  labels
88
89
  end
data/lib/dnn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/ruby-dnn.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.description = %q{ruby-dnn is a ruby deep learning library.}
14
14
  spec.homepage = "https://github.com/unagiootoro/ruby-dnn.git"
15
15
  spec.license = "MIT"
16
- spec.extensions = ["lib/dnn/ext/dataset_loader/extconf.rb", "lib/dnn/ext/rb_stb_image/extconf.rb"]
16
+ spec.extensions = ["lib/dnn/ext/cifar10_loader/extconf.rb", "lib/dnn/ext/rb_stb_image/extconf.rb"]
17
17
 
18
18
  spec.add_dependency "numo-narray"
19
19
  spec.add_dependency "archive-tar-minitar"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dnn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - unagiootoro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-21 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
@@ -85,7 +85,7 @@ email:
85
85
  - ootoro838861@outlook.jp
86
86
  executables: []
87
87
  extensions:
88
- - lib/dnn/ext/dataset_loader/extconf.rb
88
+ - lib/dnn/ext/cifar10_loader/extconf.rb
89
89
  - lib/dnn/ext/rb_stb_image/extconf.rb
90
90
  extra_rdoc_files: []
91
91
  files:
@@ -112,67 +112,9 @@ files:
112
112
  - lib/dnn/core/model.rb
113
113
  - lib/dnn/core/optimizers.rb
114
114
  - lib/dnn/core/util.rb
115
- - lib/dnn/ext/dataset_loader/dataset_loader.c
116
- - lib/dnn/ext/dataset_loader/extconf.rb
117
- - lib/dnn/ext/dataset_loader/numo/compat.h
118
- - lib/dnn/ext/dataset_loader/numo/extconf.h
119
- - lib/dnn/ext/dataset_loader/numo/intern.h
120
- - lib/dnn/ext/dataset_loader/numo/narray.h
121
- - lib/dnn/ext/dataset_loader/numo/ndloop.h
122
- - lib/dnn/ext/dataset_loader/numo/template.h
123
- - lib/dnn/ext/dataset_loader/numo/types/bit.h
124
- - lib/dnn/ext/dataset_loader/numo/types/complex.h
125
- - lib/dnn/ext/dataset_loader/numo/types/complex_macro.h
126
- - lib/dnn/ext/dataset_loader/numo/types/dcomplex.h
127
- - lib/dnn/ext/dataset_loader/numo/types/dfloat.h
128
- - lib/dnn/ext/dataset_loader/numo/types/float_def.h
129
- - lib/dnn/ext/dataset_loader/numo/types/float_macro.h
130
- - lib/dnn/ext/dataset_loader/numo/types/int16.h
131
- - lib/dnn/ext/dataset_loader/numo/types/int32.h
132
- - lib/dnn/ext/dataset_loader/numo/types/int64.h
133
- - lib/dnn/ext/dataset_loader/numo/types/int8.h
134
- - lib/dnn/ext/dataset_loader/numo/types/int_macro.h
135
- - lib/dnn/ext/dataset_loader/numo/types/real_accum.h
136
- - lib/dnn/ext/dataset_loader/numo/types/robj_macro.h
137
- - lib/dnn/ext/dataset_loader/numo/types/robject.h
138
- - lib/dnn/ext/dataset_loader/numo/types/scomplex.h
139
- - lib/dnn/ext/dataset_loader/numo/types/sfloat.h
140
- - lib/dnn/ext/dataset_loader/numo/types/uint16.h
141
- - lib/dnn/ext/dataset_loader/numo/types/uint32.h
142
- - lib/dnn/ext/dataset_loader/numo/types/uint64.h
143
- - lib/dnn/ext/dataset_loader/numo/types/uint8.h
144
- - lib/dnn/ext/dataset_loader/numo/types/uint_macro.h
145
- - lib/dnn/ext/dataset_loader/numo/types/xint_macro.h
115
+ - lib/dnn/ext/cifar10_loader/cifar10_loader.c
116
+ - lib/dnn/ext/cifar10_loader/extconf.rb
146
117
  - lib/dnn/ext/rb_stb_image/extconf.rb
147
- - lib/dnn/ext/rb_stb_image/numo/compat.h
148
- - lib/dnn/ext/rb_stb_image/numo/extconf.h
149
- - lib/dnn/ext/rb_stb_image/numo/intern.h
150
- - lib/dnn/ext/rb_stb_image/numo/narray.h
151
- - lib/dnn/ext/rb_stb_image/numo/ndloop.h
152
- - lib/dnn/ext/rb_stb_image/numo/template.h
153
- - lib/dnn/ext/rb_stb_image/numo/types/bit.h
154
- - lib/dnn/ext/rb_stb_image/numo/types/complex.h
155
- - lib/dnn/ext/rb_stb_image/numo/types/complex_macro.h
156
- - lib/dnn/ext/rb_stb_image/numo/types/dcomplex.h
157
- - lib/dnn/ext/rb_stb_image/numo/types/dfloat.h
158
- - lib/dnn/ext/rb_stb_image/numo/types/float_def.h
159
- - lib/dnn/ext/rb_stb_image/numo/types/float_macro.h
160
- - lib/dnn/ext/rb_stb_image/numo/types/int16.h
161
- - lib/dnn/ext/rb_stb_image/numo/types/int32.h
162
- - lib/dnn/ext/rb_stb_image/numo/types/int64.h
163
- - lib/dnn/ext/rb_stb_image/numo/types/int8.h
164
- - lib/dnn/ext/rb_stb_image/numo/types/int_macro.h
165
- - lib/dnn/ext/rb_stb_image/numo/types/real_accum.h
166
- - lib/dnn/ext/rb_stb_image/numo/types/robj_macro.h
167
- - lib/dnn/ext/rb_stb_image/numo/types/robject.h
168
- - lib/dnn/ext/rb_stb_image/numo/types/scomplex.h
169
- - lib/dnn/ext/rb_stb_image/numo/types/sfloat.h
170
- - lib/dnn/ext/rb_stb_image/numo/types/uint16.h
171
- - lib/dnn/ext/rb_stb_image/numo/types/uint32.h
172
- - lib/dnn/ext/rb_stb_image/numo/types/uint64.h
173
- - lib/dnn/ext/rb_stb_image/numo/types/uint8.h
174
- - lib/dnn/ext/rb_stb_image/numo/types/uint_macro.h
175
- - lib/dnn/ext/rb_stb_image/numo/types/xint_macro.h
176
118
  - lib/dnn/ext/rb_stb_image/rb_stb_image.c
177
119
  - lib/dnn/ext/rb_stb_image/stb_image.h
178
120
  - lib/dnn/ext/rb_stb_image/stb_image_write.h
@@ -1,90 +0,0 @@
1
- #include <ruby.h>
2
- #include <stdlib.h>
3
- #include "numo/narray.h"
4
-
5
- #define CIFAR10_WIDTH 32
6
- #define CIFAR10_HEIGHT 32
7
- #define CIFAR10_CHANNEL 3
8
-
9
- VALUE mnist_load_images(VALUE self, VALUE rb_bin, VALUE rb_num_images, VALUE rb_cols, VALUE rb_rows) {
10
- char* bin = StringValuePtr(rb_bin);
11
- int num_images = FIX2INT(rb_num_images);
12
- int cols = FIX2INT(rb_cols);
13
- int rows = FIX2INT(rb_rows);
14
- int i;
15
- int j;
16
- char script[64];
17
- VALUE rb_na;
18
- narray_data_t* na_data;
19
-
20
- sprintf(script, "Numo::UInt8.zeros(%d, %d, %d)", num_images, cols, rows);
21
- rb_na = rb_eval_string(&script[0]);
22
- na_data = RNARRAY_DATA(rb_na);
23
-
24
- for (i = 0; i < num_images; i++) {
25
- j = i * cols * rows;
26
- memcpy(&na_data->ptr[j], &bin[j], cols * rows);
27
- }
28
- return rb_na;
29
- }
30
-
31
- VALUE mnist_load_labels(VALUE self, VALUE rb_bin, VALUE rb_num_labels) {
32
- char* bin = StringValuePtr(rb_bin);
33
- int num_labels = FIX2INT(rb_num_labels);
34
- char script[64];
35
- VALUE rb_na;
36
- narray_data_t* na_data;
37
-
38
- sprintf(script, "Numo::UInt8.zeros(%d)", num_labels);
39
- rb_na = rb_eval_string(&script[0]);
40
- na_data = RNARRAY_DATA(rb_na);
41
-
42
- memcpy(na_data->ptr, bin, num_labels);
43
- return rb_na;
44
- }
45
-
46
- VALUE cifar10_load(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
47
- char* bin = StringValuePtr(rb_bin);
48
- int num_datas = FIX2INT(rb_num_datas);
49
- char script[64];
50
- VALUE rb_na_x;
51
- VALUE rb_na_y;
52
- VALUE rb_xy;
53
- narray_data_t* na_data_x;
54
- narray_data_t* na_data_y;
55
- int i;
56
- int j = 0;
57
- int k = 0;
58
- int size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
59
-
60
- sprintf(script, "Numo::UInt8.zeros(%d, %d, %d, %d)", num_datas, CIFAR10_CHANNEL, CIFAR10_WIDTH, CIFAR10_HEIGHT);
61
- rb_na_x = rb_eval_string(&script[0]);
62
- na_data_x = RNARRAY_DATA(rb_na_x);
63
- for(i = 0; i < 64; i++) {
64
- script[i] = 0;
65
- }
66
- sprintf(script, "Numo::UInt8.zeros(%d)", num_datas);
67
- rb_na_y = rb_eval_string(&script[0]);
68
- na_data_y = RNARRAY_DATA(rb_na_y);
69
-
70
- for (i = 0; i < num_datas; i++) {
71
- na_data_y->ptr[i] = bin[j];
72
- j++;
73
- memcpy(&na_data_x->ptr[k], &bin[j], size);
74
- j += size;
75
- k += size;
76
- }
77
-
78
- rb_xy = rb_ary_new3(2, rb_na_x, rb_na_y);
79
- return rb_xy;
80
- }
81
-
82
- void Init_dataset_loader() {
83
- VALUE rb_dnn = rb_define_module("DNN");
84
- VALUE rb_mnist = rb_define_module_under(rb_dnn, "MNIST");
85
- VALUE rb_cifar10 = rb_define_module_under(rb_dnn, "CIFAR10");
86
-
87
- rb_define_singleton_method(rb_mnist, "_mnist_load_images", mnist_load_images, 4);
88
- rb_define_singleton_method(rb_mnist, "_mnist_load_labels", mnist_load_labels, 2);
89
- rb_define_singleton_method(rb_cifar10, "_cifar10_load", cifar10_load, 2);
90
- }