ruby-dnn 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dnn/core/layers.rb +7 -4
- data/lib/dnn/ext/cifar10_loader/cifar10_loader.c +16 -15
- data/lib/dnn/ext/rb_stb_image/rb_stb_image.c +58 -29
- data/lib/dnn/lib/cifar10.rb +0 -1
- data/lib/dnn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c2ef751fa76ea2918c5f706e1828eba514385b831dc042fa561a08d38da977a
|
|
4
|
+
data.tar.gz: b906f6a9c63620378b284a2be3ca3bb8e007534b945493b9f8323f77c012cd0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94e7af50f4cdc556b252e3afed0703aa7d9e9d519f2e1e24253a1a27b388fe9d00444edfc271343365dc39e8a02d326df27e923216834509cb639986576664de
|
|
7
|
+
data.tar.gz: 5fc8acfeed67fff5b41247ab6c3f03b68f96f48bdda877951e23d1fb12f2cc6c113a6102b8b531cd41d1c596d2ab6fa96a243607d38182d804ab1f5396e5439c
|
data/lib/dnn/core/layers.rb
CHANGED
|
@@ -19,10 +19,12 @@ module DNN
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
# Forward propagation.
|
|
22
|
-
|
|
22
|
+
# Classes that inherit from this class must implement this method.
|
|
23
|
+
# def forward() end
|
|
23
24
|
|
|
24
25
|
# Backward propagation.
|
|
25
|
-
|
|
26
|
+
# Classes that inherit from this class must implement this method.
|
|
27
|
+
# def backward() end
|
|
26
28
|
|
|
27
29
|
# Get the shape of the layer.
|
|
28
30
|
def shape
|
|
@@ -102,11 +104,12 @@ module DNN
|
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
|
|
107
|
+
# It is a superclass of all connection layers.
|
|
105
108
|
class Connection < HasParamLayer
|
|
106
109
|
include Initializers
|
|
107
110
|
|
|
108
|
-
attr_reader :l1_lambda
|
|
109
|
-
attr_reader :l2_lambda
|
|
111
|
+
attr_reader :l1_lambda # L1 regularization
|
|
112
|
+
attr_reader :l2_lambda # L2 regularization
|
|
110
113
|
|
|
111
114
|
def initialize(weight_initializer: nil,
|
|
112
115
|
bias_initializer: nil,
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
|
+
#include <stdint.h>
|
|
2
3
|
#include <stdlib.h>
|
|
3
4
|
|
|
4
5
|
#define CIFAR10_WIDTH 32
|
|
5
6
|
#define CIFAR10_HEIGHT 32
|
|
6
7
|
#define CIFAR10_CHANNEL 3
|
|
7
8
|
|
|
8
|
-
VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
static VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
|
|
10
|
+
uint8_t* bin = (uint8_t*)StringValuePtr(rb_bin);
|
|
11
|
+
int32_t num_datas = FIX2INT(rb_num_datas);
|
|
11
12
|
VALUE rb_x_bin;
|
|
12
13
|
VALUE rb_y_bin;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
int32_t i;
|
|
15
|
+
int32_t j = 0;
|
|
16
|
+
int32_t k = 0;
|
|
17
|
+
int32_t size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
|
|
18
|
+
int32_t x_bin_size = num_datas * size;
|
|
19
|
+
int32_t y_bin_size = num_datas;
|
|
20
|
+
uint8_t* x_bin;
|
|
21
|
+
uint8_t* y_bin;
|
|
21
22
|
|
|
22
|
-
x_bin = (
|
|
23
|
-
y_bin = (
|
|
23
|
+
x_bin = (uint8_t*)malloc(x_bin_size);
|
|
24
|
+
y_bin = (uint8_t*)malloc(y_bin_size);
|
|
24
25
|
for (i = 0; i < num_datas; i++) {
|
|
25
26
|
y_bin[i] = bin[j];
|
|
26
27
|
j++;
|
|
@@ -28,8 +29,8 @@ VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
|
|
|
28
29
|
j += size;
|
|
29
30
|
k += size;
|
|
30
31
|
}
|
|
31
|
-
rb_x_bin = rb_str_new(x_bin, x_bin_size);
|
|
32
|
-
rb_y_bin = rb_str_new(y_bin, y_bin_size);
|
|
32
|
+
rb_x_bin = rb_str_new((char*)x_bin, x_bin_size);
|
|
33
|
+
rb_y_bin = rb_str_new((char*)y_bin, y_bin_size);
|
|
33
34
|
free(x_bin);
|
|
34
35
|
free(y_bin);
|
|
35
36
|
return rb_ary_new3(2, rb_x_bin, rb_y_bin);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
|
+
#include <stdint.h>
|
|
2
3
|
|
|
3
4
|
#define STB_IMAGE_IMPLEMENTATION
|
|
4
5
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
@@ -6,13 +7,13 @@
|
|
|
6
7
|
#include "stb_image.h"
|
|
7
8
|
#include "stb_image_write.h"
|
|
8
9
|
|
|
9
|
-
//STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp);
|
|
10
|
-
VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
|
|
10
|
+
// STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp);
|
|
11
|
+
static VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
|
|
11
12
|
char* filename = StringValuePtr(rb_filename);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
int32_t x, y, n;
|
|
14
|
+
int32_t req_comp = FIX2INT(rb_req_comp);
|
|
15
|
+
uint8_t* data;
|
|
16
|
+
int32_t ch;
|
|
16
17
|
VALUE rb_x, rb_y, rb_n;
|
|
17
18
|
VALUE rb_data;
|
|
18
19
|
|
|
@@ -26,42 +27,68 @@ VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
|
|
|
26
27
|
return rb_ary_new3(4, rb_data, rb_x, rb_y, rb_n);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
//STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int 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) {
|
|
30
|
+
// STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
|
31
|
+
static 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) {
|
|
31
32
|
char* filename = StringValuePtr(rb_filename);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
int32_t w = FIX2INT(rb_w);
|
|
34
|
+
int32_t h = FIX2INT(rb_h);
|
|
35
|
+
int32_t comp = FIX2INT(rb_comp);
|
|
36
|
+
uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
|
|
37
|
+
int32_t stride_in_bytes = FIX2INT(rb_stride_in_bytes);
|
|
38
|
+
int32_t result;
|
|
38
39
|
|
|
39
40
|
result = stbi_write_png(filename, w, h, comp, data, stride_in_bytes);
|
|
40
41
|
return INT2FIX(result);
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
//STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
|
44
|
-
VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
|
|
44
|
+
// STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
|
45
|
+
static VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
|
|
45
46
|
char* filename = StringValuePtr(rb_filename);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
int32_t w = FIX2INT(rb_w);
|
|
48
|
+
int32_t h = FIX2INT(rb_h);
|
|
49
|
+
int32_t comp = FIX2INT(rb_comp);
|
|
50
|
+
uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
|
|
51
|
+
int32_t result;
|
|
51
52
|
|
|
52
53
|
result = stbi_write_bmp(filename, w, h, comp, data);
|
|
53
54
|
return INT2FIX(result);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
//STBIWDEF int
|
|
57
|
-
VALUE
|
|
57
|
+
// STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
|
58
|
+
static VALUE rb_stbi_write_tga(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
|
|
58
59
|
char* filename = StringValuePtr(rb_filename);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
int32_t w = FIX2INT(rb_w);
|
|
61
|
+
int32_t h = FIX2INT(rb_h);
|
|
62
|
+
int32_t comp = FIX2INT(rb_comp);
|
|
63
|
+
uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
|
|
64
|
+
int32_t result;
|
|
65
|
+
|
|
66
|
+
result = stbi_write_tga(filename, w, h, comp, data);
|
|
67
|
+
return INT2FIX(result);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
|
71
|
+
static VALUE rb_stbi_write_hdr(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
|
|
72
|
+
char* filename = StringValuePtr(rb_filename);
|
|
73
|
+
int32_t w = FIX2INT(rb_w);
|
|
74
|
+
int32_t h = FIX2INT(rb_h);
|
|
75
|
+
int32_t comp = FIX2INT(rb_comp);
|
|
76
|
+
float* data = (float*)StringValuePtr(rb_data);
|
|
77
|
+
int32_t result;
|
|
78
|
+
|
|
79
|
+
result = stbi_write_hdr(filename, w, h, comp, data);
|
|
80
|
+
return INT2FIX(result);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
|
84
|
+
static 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) {
|
|
85
|
+
char* filename = StringValuePtr(rb_filename);
|
|
86
|
+
int32_t w = FIX2INT(rb_w);
|
|
87
|
+
int32_t h = FIX2INT(rb_h);
|
|
88
|
+
int32_t comp = FIX2INT(rb_comp);
|
|
89
|
+
uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
|
|
90
|
+
int32_t quality = FIX2INT(rb_quality);
|
|
91
|
+
int32_t result;
|
|
65
92
|
|
|
66
93
|
result = stbi_write_jpg(filename, w, h, comp, data, quality);
|
|
67
94
|
return INT2FIX(result);
|
|
@@ -74,5 +101,7 @@ void Init_rb_stb_image() {
|
|
|
74
101
|
rb_define_module_function(rb_stb, "stbi_load", rb_stbi_load, 2);
|
|
75
102
|
rb_define_module_function(rb_stb, "stbi_write_png", rb_stbi_write_png, 6);
|
|
76
103
|
rb_define_module_function(rb_stb, "stbi_write_bmp", rb_stbi_write_bmp, 5);
|
|
104
|
+
rb_define_module_function(rb_stb, "stbi_write_tga", rb_stbi_write_tga, 5);
|
|
105
|
+
rb_define_module_function(rb_stb, "stbi_write_hdr", rb_stbi_write_hdr, 5);
|
|
77
106
|
rb_define_module_function(rb_stb, "stbi_write_jpg", rb_stbi_write_jpg, 6);
|
|
78
107
|
}
|
data/lib/dnn/lib/cifar10.rb
CHANGED
data/lib/dnn/version.rb
CHANGED
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.7.
|
|
4
|
+
version: 0.7.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- unagiootoro
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: numo-narray
|