deepdetect_ruby 1.0.1

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.
data/lib/train.rb ADDED
@@ -0,0 +1,133 @@
1
+ module DeepdetectRuby
2
+ class Train
3
+ def self.launch(options = {}, is_custom_data = false)
4
+ begin
5
+ debug = DeepdetectRuby.options[:debug]
6
+ server_index = options[:server_index] || 1
7
+ dede_host = DeepdetectRuby::DedeServer.get_server(server_index)
8
+ dede_api_url = "#{dede_host}/train"
9
+ puts "\n-------------> Starting to launch DeepDetect training #{dede_api_url}....\n" if debug
10
+
11
+ options[:service] = !options[:service].nil? ? options[:service] : ""
12
+ options[:async] = !options[:async].nil? ? options[:async] : true
13
+ options[:gpu] = !options[:gpu].nil? ? options[:gpu] : true
14
+ options[:batch_size] = !options[:batch_size].nil? ? options[:batch_size] : 128
15
+ options[:test_batch_size] = !options[:test_batch_size].nil? ? options[:test_batch_size] : 64
16
+ options[:test_interval] = !options[:test_interval].nil? ? options[:test_interval] : 500
17
+ options[:iterations] = !options[:iterations].nil? ? options[:iterations] : 10001
18
+ options[:base_lr] = !options[:base_lr].nil? ? options[:base_lr] : 0.0001
19
+ options[:stepsize] = !options[:stepsize].nil? ? options[:stepsize] : 1000
20
+ options[:gamma] = !options[:gamma].nil? ? options[:gamma] : 0.9
21
+ options[:connector] = !options[:connector].nil? ? options[:connector] : "image"
22
+ options[:test_split] = !options[:test_split].nil? ? options[:test_split] : 0.1
23
+ options[:shuffle] = !options[:shuffle].nil? ? options[:shuffle] : true
24
+ options[:width] = !options[:width].nil? ? options[:width] : 224
25
+ options[:height] = !options[:height].nil? ? options[:height] : 224
26
+ options[:repository] = !options[:repository].nil? ? options[:repository] : ""
27
+
28
+ options[:finetuning] = !options[:finetuning].nil? ? options[:finetuning] : false
29
+ options[:solver_type] = !options[:solver_type].nil? ? options[:solver_type] : "SGD"
30
+ # options[:solver_type] = "NESTEROV" if options[:finetuning]
31
+ options[:snapshot] = !options[:snapshot].nil? ? options[:snapshot] : 2000
32
+ options[:measure_index] = !options[:measure_index].nil? ? options[:measure_index] : 1
33
+
34
+ measure = ["acc", "mcll", "f1"]
35
+ if options[:measure_index] == 1
36
+ measure = ["acc-5", "mcll", "f1"]
37
+ elsif options[:measure_index] == 2
38
+ measure = ["acc", "mcll", "cmdiag"]
39
+ end
40
+
41
+ data = {
42
+ "service" => "#{options[:service]}",
43
+ "async" => options[:async],
44
+ "parameters" => {
45
+ "mllib" => {
46
+ "gpu" => options[:gpu],
47
+ "net" => {
48
+ "batch_size" => options[:batch_size],
49
+ "test_batch_size" => options[:test_batch_size]
50
+ },
51
+ "solver" => {
52
+ "test_interval" => options[:test_interval],
53
+ "iterations" => options[:iterations],
54
+ "base_lr" => options[:base_lr],
55
+ "stepsize" => options[:stepsize],
56
+ "gamma" => options[:gamma],
57
+ "test_initialization" => true,
58
+ "solver_type" => "#{options[:solver_type]}",
59
+ "snapshot" => options[:snapshot]
60
+ }
61
+ },
62
+ "input" => {
63
+ "connector" => "#{options[:connector]}",
64
+ "test_split" => options[:test_split],
65
+ "shuffle" => options[:shuffle],
66
+ "width" => options[:width],
67
+ "height" => options[:height]
68
+ },
69
+ "output" => {
70
+ "measure" => measure
71
+ }
72
+ },
73
+ "data" => [
74
+ "#{options[:repository]}"
75
+ ]
76
+ }
77
+ puts "\nparams data: #{data.to_json} \n" if debug
78
+ data = options if is_custom_data
79
+ dede_body = {
80
+ :body => data.to_json,
81
+ :headers => { "Content-Type" => 'application/json' }
82
+ }
83
+ object = HTTParty.post(dede_api_url, dede_body)
84
+ object_info = JSON.parse(object.body)
85
+ object_info.extend DeepSymbolizable
86
+ return object_info.deep_symbolize
87
+ rescue Exception => e
88
+ puts "\n[DeepdetectRuby Train - launch training]. #{e.to_s} \n"
89
+ end
90
+ end # end launch
91
+
92
+ def self.get_status(options = {})
93
+ debug = DeepdetectRuby.options[:debug]
94
+ server_index = options[:server_index] || 1
95
+ dede_host = DeepdetectRuby::DedeServer.get_server(server_index)
96
+ options[:job] = !options[:job].nil? ? options[:job] : 1
97
+ options[:timeout] = !options[:timeout].nil? ? options[:timeout] : 20
98
+ dede_api_url = "#{dede_host}/train?service=#{options[:service]}"
99
+ dede_api_url = "#{dede_api_url}&job=#{options[:job]}"
100
+ dede_api_url = "#{dede_api_url}&timeout=#{options[:timeout]}"
101
+
102
+ puts "\n-------------> Starting to get_status DeepDetect training #{dede_api_url}....\n" if debug
103
+
104
+ begin
105
+ object = HTTParty.get(dede_api_url)
106
+ object_info = JSON.parse(object.body)
107
+ object_info.extend DeepSymbolizable
108
+ return object_info.deep_symbolize
109
+ rescue Exception => e
110
+ puts "\n[DeepdetectRuby Train - get_status]. #{e.to_s} \n"
111
+ end
112
+ end # end get_status
113
+
114
+ # options = { service: "service name", job: 1 }
115
+ def self.delete_job(options = {})
116
+ debug = DeepdetectRuby.options[:debug]
117
+ server_index = options[:server_index] || 1
118
+ dede_host = DeepdetectRuby::DedeServer.get_server(server_index)
119
+ options[:job] = !options[:job].nil? ? options[:job] : 1
120
+ dede_api_url = "#{dede_host}/train?service=#{options[:service]}"
121
+ dede_api_url = "#{dede_api_url}&job=#{options[:job]}"
122
+ puts "\n-------------> Starting to delete_job DeepDetect training #{dede_api_url}....\n" if debug
123
+ begin
124
+ object = HTTParty.delete(dede_api_url)
125
+ object_info = JSON.parse(object.body)
126
+ object_info.extend DeepSymbolizable
127
+ return object_info.deep_symbolize
128
+ rescue Exception => e
129
+ puts "\n[DeepdetectRuby Train - delete_job]. #{e.to_s} \n"
130
+ end
131
+ end
132
+ end
133
+ end
data/test_script.md ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "mllib": "caffe",
3
+ "description": "trees classification",
4
+ "type": "supervised",
5
+ "parameters": {
6
+ "input": {
7
+ "connector": "image",
8
+ "height": 224,
9
+ "width": 224
10
+ },
11
+ "mllib": {
12
+ "nclasses": 304
13
+ }
14
+ },
15
+ "model": {
16
+ "repository": "/home/tamnguyen/models/trees"
17
+ }
18
+ }
19
+
20
+ {
21
+ "mllib": "caffe",
22
+ "description": "trees classification",
23
+ "type": "supervised",
24
+ "parameters": {
25
+ "input": {
26
+ "connector": "image",
27
+ "height": 224,
28
+ "width": 224
29
+ },
30
+ "mllib": {
31
+ "nclasses": 304
32
+ }
33
+ },
34
+ "model": {
35
+ "repository": "/home/tamnguyen/models/trees"
36
+ }
37
+ }
38
+ ------------------------------------
39
+ Post training
40
+ {
41
+ "service": "trees",
42
+ "async": true,
43
+ "parameters": {
44
+ "mllib": {
45
+ "gpu": true,
46
+ "net": {
47
+ "batch_size": 32
48
+ },
49
+ "solver": {
50
+ "test_interval": 500,
51
+ "iterations": 200,
52
+ "base_lr": 0.001,
53
+ "stepsize": 1000,
54
+ "gamma": 0.9
55
+ }
56
+ },
57
+ "input": {
58
+ "connector": "image",
59
+ "test_split": 0.1,
60
+ "shuffle": true,
61
+ "width": 224,
62
+ "height": 224
63
+ },
64
+ "output": {
65
+ "measure": [
66
+ "acc",
67
+ "mcll",
68
+ "f1"
69
+ ]
70
+ }
71
+ },
72
+ "data": [
73
+ "/home/ubuntu/projects/docs/category/tree_3"
74
+ ]
75
+ }
76
+ ------------------------------------
77
+ Test create a service
78
+ DeepdetectRuby::Service.create({"name": "trees", "mllib": "caffe", "description": "trees classification", "type": "supervised", "connector": "image", "height": 224, "width": 224, "nclasses": 890, "repository": "/home/tamnguyen/models/trees"})
79
+
80
+ Test get a service information
81
+ DeepdetectRuby::Service.get_info("trees")
82
+
83
+ Test delete a service information
84
+ DeepdetectRuby::Service.get_info("trees")
85
+
86
+ Test predict
87
+ DeepdetectRuby::Predict.predict({service: "trees", image_url: "http://mamnonhanhphuc.edu.vn/upload/images/THOTRUYENTHIEUNHI/2012/su-tich-cay-chuoi1.jpg"})
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deepdetect_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tam Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
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
+ description: DeepdetectRuby, a library for Ruby apps
56
+ email:
57
+ - ntamvl@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - deepdetect_ruby.gemspec
73
+ - docs/Finetuning.md
74
+ - docs/convolutional_neural_networks.py
75
+ - docs/dd_client.py
76
+ - docs/finetuning_googlenet.py
77
+ - docs/rsync_for_selfie_f4.sh
78
+ - docs/sync_file.sh
79
+ - docs/sync_mirrorshot.sh
80
+ - lib/configuration.rb
81
+ - lib/dede_server.rb
82
+ - lib/deep_symbolize.rb
83
+ - lib/deepdetect_ruby.rb
84
+ - lib/deepdetect_ruby/version.rb
85
+ - lib/info.rb
86
+ - lib/predict.rb
87
+ - lib/service.rb
88
+ - lib/train.rb
89
+ - test_script.md
90
+ homepage: https://github.com/ntamvl/deepdetect-ruby
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: DeepdetectRuby, a library for Ruby apps
114
+ test_files: []