red-datasets-gdk-pixbuf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +7 -0
- data/README.md +35 -0
- data/Rakefile +21 -0
- data/doc/text/news.md +5 -0
- data/lib/datasets-gdk-pixbuf.rb +5 -0
- data/lib/datasets-gdk-pixbuf/cifar.rb +28 -0
- data/lib/datasets-gdk-pixbuf/version.rb +3 -0
- data/red-datasets-gdk-pixbuf.gemspec +45 -0
- data/test/helper.rb +16 -0
- data/test/run-test.rb +16 -0
- data/test/test-cifar.rb +78 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a8e1a72cafe0dbe7ee41224c8a02bf20ad0696b1ea59b23569933443991f97cc
|
4
|
+
data.tar.gz: 929476408cf9f08854a5b1e78e6b0456d6131b0afa494f0af68b1f87cabca85e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ac6edbbb3b7769b6d13989d2aace041d4474620a3824f451e75df19f716f19734888a535c875f1f50ef41e6693b46a8bb465eaa4bd2cc83924b766f9054ce19
|
7
|
+
data.tar.gz: f9810f4ed6a50f26240b582c81b6c2910760aab63d079fb562ab1d0453228baaf1db3b1a80d213a94e3e4d2a9b04002e648bbcaad25c7aa06f814a6ec325aacf
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2018 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
## Name
|
4
|
+
|
5
|
+
Red Datasets GDK Pixbuf
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
Red Datasets GDK Pixbuf adds [GDK Pixbuf](https://developer.gnome.org/gdk-pixbuf/stable/) object export feature to Red Datasets.
|
10
|
+
|
11
|
+
Red Datasets GDK Pixbuf adds `#to_gdk_pixbuf` method to some datasets in Red Datasets. You can get `GdkPixbuf::Pixbuf` objects from a dataset.
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
```console
|
16
|
+
% gem install red-datasets-gdk-pixbuf
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Here is an example to get images for CIFAR dataset by `#to_gdk_pixbuf`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "datasets"
|
25
|
+
|
26
|
+
cifar = Datasets::CIFAR.new
|
27
|
+
cifar.each.with_index do |record, i|
|
28
|
+
pixbuf = record.to_gdk_pixbuf
|
29
|
+
pixbuf.save("#{record.label}-#{i}.png")
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The MIT license. See `LICENSE.txt` for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/gem_helper"
|
5
|
+
|
6
|
+
base_dir = File.join(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
helper = Bundler::GemHelper.new(base_dir)
|
9
|
+
def helper.version_tag
|
10
|
+
version
|
11
|
+
end
|
12
|
+
|
13
|
+
helper.install
|
14
|
+
spec = helper.gemspec
|
15
|
+
|
16
|
+
desc "Run tests"
|
17
|
+
task :test do
|
18
|
+
ruby("test/run-test.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
task default: :test
|
data/doc/text/news.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "gdk_pixbuf2"
|
2
|
+
|
3
|
+
module DatasetsGdkPixbuf
|
4
|
+
module CIFARPixbufable
|
5
|
+
def to_gdk_pixbuf
|
6
|
+
n_channels = 3
|
7
|
+
width = 32
|
8
|
+
height = 32
|
9
|
+
rgb_data = pixels.each_slice(1024).to_a.transpose.flatten.pack("C*")
|
10
|
+
GdkPixbuf::Pixbuf.new(:data => rgb_data,
|
11
|
+
:row_stride => width * n_channels,
|
12
|
+
:width => width,
|
13
|
+
:height => height)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Datasets
|
19
|
+
class CIFAR
|
20
|
+
class Record10
|
21
|
+
include DatasetsGdkPixbuf::CIFARPixbufable
|
22
|
+
end
|
23
|
+
|
24
|
+
class Record100
|
25
|
+
include DatasetsGdkPixbuf::CIFARPixbufable
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
clean_white_space = lambda do |entry|
|
4
|
+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
|
5
|
+
end
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
|
8
|
+
require "datasets-gdk-pixbuf/version"
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "red-datasets-gdk-pixbuf"
|
12
|
+
spec.version = DatasetsGdkPixbuf::VERSION
|
13
|
+
spec.homepage = "https://github.com/red-data-tools/red-datasets-gdk-pixbuf"
|
14
|
+
spec.authors = ["Kouhei Sutou"]
|
15
|
+
spec.email = ["kou@clear-code.com"]
|
16
|
+
|
17
|
+
readme = File.read("README.md")
|
18
|
+
readme.force_encoding("UTF-8")
|
19
|
+
entries = readme.split(/^\#\#\s(.*)$/)
|
20
|
+
clean_white_space.call(entries[entries.index("Description") + 1])
|
21
|
+
description = clean_white_space.call(entries[entries.index("Description") + 1])
|
22
|
+
spec.summary, spec.description, = description.split(/\n\n+/, 3)
|
23
|
+
spec.license = "MIT"
|
24
|
+
spec.files = [
|
25
|
+
"README.md",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"Rakefile",
|
28
|
+
"Gemfile",
|
29
|
+
"#{spec.name}.gemspec",
|
30
|
+
]
|
31
|
+
spec.files += [".yardopts"]
|
32
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
33
|
+
spec.files += Dir.glob("image/*.*")
|
34
|
+
spec.files += Dir.glob("doc/text/*")
|
35
|
+
spec.test_files += Dir.glob("test/**/*")
|
36
|
+
|
37
|
+
spec.add_runtime_dependency("gdk_pixbuf2")
|
38
|
+
spec.add_runtime_dependency("red-datasets", ">= 0.0.3")
|
39
|
+
|
40
|
+
spec.add_development_dependency("bundler")
|
41
|
+
spec.add_development_dependency("rake")
|
42
|
+
spec.add_development_dependency("test-unit")
|
43
|
+
spec.add_development_dependency("yard")
|
44
|
+
spec.add_development_dependency("kramdown")
|
45
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "datasets-gdk-pixbuf"
|
2
|
+
|
3
|
+
require "test-unit"
|
4
|
+
|
5
|
+
module Helper
|
6
|
+
module Sandbox
|
7
|
+
def setup_sandbox
|
8
|
+
@tmp_dir = (Pathname.new(__dir__) + "tmp").expand_path
|
9
|
+
FileUtils.mkdir_p(@tmp_dir)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown_sandbox
|
13
|
+
FileUtils.rm_rf(@tmp_dir)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
require "pathname"
|
6
|
+
|
7
|
+
base_dir = Pathname.new(__FILE__).dirname.parent.expand_path
|
8
|
+
|
9
|
+
lib_dir = base_dir + "lib"
|
10
|
+
test_dir = base_dir + "test"
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(lib_dir.to_s)
|
13
|
+
|
14
|
+
require_relative "helper"
|
15
|
+
|
16
|
+
exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
|
data/test/test-cifar.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
class IrisTest < Test::Unit::TestCase
|
2
|
+
include Helper::Sandbox
|
3
|
+
|
4
|
+
def setup_raw_data(data)
|
5
|
+
setup_sandbox
|
6
|
+
|
7
|
+
def @dataset.cache_dir_path
|
8
|
+
@cache_dir_path
|
9
|
+
end
|
10
|
+
def @dataset.cache_dir_path=(path)
|
11
|
+
@cache_dir_path = path
|
12
|
+
end
|
13
|
+
@dataset.cache_dir_path = @tmp_dir
|
14
|
+
|
15
|
+
def @dataset.data=(data)
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
@dataset.data = data
|
19
|
+
|
20
|
+
def @dataset.download(output_path, url)
|
21
|
+
Zlib::GzipWriter.open(output_path) do |gz|
|
22
|
+
Gem::Package::TarWriter.new(gz) do |tar|
|
23
|
+
@data.each do |path, content|
|
24
|
+
if content == :directory
|
25
|
+
tar.mkdir(path, 0755)
|
26
|
+
else
|
27
|
+
tar.add_file_simple(path, 0644, content.bytesize) do |file|
|
28
|
+
file.write(content)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
teardown_sandbox
|
39
|
+
end
|
40
|
+
|
41
|
+
sub_test_case("cifar-10") do
|
42
|
+
def create_data(label, pixels)
|
43
|
+
[label].pack("C") + pixels.pack("C*")
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup
|
47
|
+
@dataset = Datasets::CIFAR.new(n_classes: 10)
|
48
|
+
directory = "cifar-10-batches-bin"
|
49
|
+
pixels = [255] * (32 * 32) + [0] * (32 * 32) + [127] * (32 * 32)
|
50
|
+
setup_raw_data(directory => :directory,
|
51
|
+
"#{directory}/data_batch_1.bin" => create_data(1, pixels))
|
52
|
+
end
|
53
|
+
|
54
|
+
test("#to_gdk_pixbuf") do
|
55
|
+
assert_equal([255, 0, 127] * (32 * 32),
|
56
|
+
@dataset.first.to_gdk_pixbuf.pixels)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
sub_test_case("cifar-100") do
|
61
|
+
def create_data(coarse_label, fine_label, pixels)
|
62
|
+
[coarse_label, fine_label].pack("C*") + pixels.pack("C*")
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup
|
66
|
+
@dataset = Datasets::CIFAR.new(n_classes: 100)
|
67
|
+
directory = "cifar-100-binary"
|
68
|
+
pixels = [255] * (32 * 32) + [0] * (32 * 32) + [127] * (32 * 32)
|
69
|
+
setup_raw_data(directory => :directory,
|
70
|
+
"#{directory}/train.bin" => create_data(1, 11, pixels))
|
71
|
+
end
|
72
|
+
|
73
|
+
test("#to_gdk_pixbuf") do
|
74
|
+
assert_equal([255, 0, 127] * (32 * 32),
|
75
|
+
@dataset.first.to_gdk_pixbuf.pixels)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: red-datasets-gdk-pixbuf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kouhei Sutou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gdk_pixbuf2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: red-datasets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: kramdown
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: 'Red Datasets GDK Pixbuf adds `#to_gdk_pixbuf` method to some datasets
|
112
|
+
in Red Datasets. You can get `GdkPixbuf::Pixbuf` objects from a dataset.
|
113
|
+
|
114
|
+
'
|
115
|
+
email:
|
116
|
+
- kou@clear-code.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".yardopts"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- doc/text/news.md
|
127
|
+
- lib/datasets-gdk-pixbuf.rb
|
128
|
+
- lib/datasets-gdk-pixbuf/cifar.rb
|
129
|
+
- lib/datasets-gdk-pixbuf/version.rb
|
130
|
+
- red-datasets-gdk-pixbuf.gemspec
|
131
|
+
- test/helper.rb
|
132
|
+
- test/run-test.rb
|
133
|
+
- test/test-cifar.rb
|
134
|
+
homepage: https://github.com/red-data-tools/red-datasets-gdk-pixbuf
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Red Datasets GDK Pixbuf adds [GDK Pixbuf](https://developer.gnome.org/gdk-pixbuf/stable/)
|
158
|
+
object export feature to Red Datasets.
|
159
|
+
test_files:
|
160
|
+
- test/helper.rb
|
161
|
+
- test/run-test.rb
|
162
|
+
- test/test-cifar.rb
|