Class: DeepdetectRuby::Train
- Inherits:
-
Object
- Object
- DeepdetectRuby::Train
- Defined in:
- lib/train.rb
Class Method Summary collapse
-
.delete_job(options = {}) ⇒ Object
options = { service: “service name”, job: 1 }.
-
.get_status(options = {}) ⇒ Object
end launch.
- .launch(options = {}, is_custom_data = false) ⇒ Object
Class Method Details
.delete_job(options = {}) ⇒ Object
options = { service: “service name”, job: 1 }
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/train.rb', line 115 def self.delete_job( = {}) debug = DeepdetectRuby.[:debug] server_index = [:server_index] || 1 dede_host = DeepdetectRuby::DedeServer.get_server(server_index) [:job] = ![:job].nil? ? [:job] : 1 dede_api_url = "#{dede_host}/train?service=#{[:service]}" dede_api_url = "#{dede_api_url}&job=#{[:job]}" puts "\n-------------> Starting to delete_job DeepDetect training #{dede_api_url}....\n" if debug begin object = HTTParty.delete(dede_api_url) object_info = JSON.parse(object.body) object_info.extend DeepSymbolizable return object_info.deep_symbolize rescue Exception => e puts "\n[DeepdetectRuby Train - delete_job]. #{e.to_s} \n" end end |
.get_status(options = {}) ⇒ Object
end launch
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/train.rb', line 92 def self.get_status( = {}) debug = DeepdetectRuby.[:debug] server_index = [:server_index] || 1 dede_host = DeepdetectRuby::DedeServer.get_server(server_index) [:job] = ![:job].nil? ? [:job] : 1 [:timeout] = ![:timeout].nil? ? [:timeout] : 20 dede_api_url = "#{dede_host}/train?service=#{[:service]}" dede_api_url = "#{dede_api_url}&job=#{[:job]}" dede_api_url = "#{dede_api_url}&timeout=#{[:timeout]}" puts "\n-------------> Starting to get_status DeepDetect training #{dede_api_url}....\n" if debug begin object = HTTParty.get(dede_api_url) object_info = JSON.parse(object.body) object_info.extend DeepSymbolizable return object_info.deep_symbolize rescue Exception => e puts "\n[DeepdetectRuby Train - get_status]. #{e.to_s} \n" end end |
.launch(options = {}, is_custom_data = false) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/train.rb', line 3 def self.launch( = {}, is_custom_data = false) begin debug = DeepdetectRuby.[:debug] server_index = [:server_index] || 1 dede_host = DeepdetectRuby::DedeServer.get_server(server_index) dede_api_url = "#{dede_host}/train" puts "\n-------------> Starting to launch DeepDetect training #{dede_api_url}....\n" if debug [:service] = ![:service].nil? ? [:service] : "" [:async] = ![:async].nil? ? [:async] : true [:gpu] = ![:gpu].nil? ? [:gpu] : true [:batch_size] = ![:batch_size].nil? ? [:batch_size] : 128 [:test_batch_size] = ![:test_batch_size].nil? ? [:test_batch_size] : 64 [:test_interval] = ![:test_interval].nil? ? [:test_interval] : 500 [:iterations] = ![:iterations].nil? ? [:iterations] : 10001 [:base_lr] = ![:base_lr].nil? ? [:base_lr] : 0.0001 [:stepsize] = ![:stepsize].nil? ? [:stepsize] : 1000 [:gamma] = ![:gamma].nil? ? [:gamma] : 0.9 [:connector] = ![:connector].nil? ? [:connector] : "image" [:test_split] = ![:test_split].nil? ? [:test_split] : 0.1 [:shuffle] = ![:shuffle].nil? ? [:shuffle] : true [:width] = ![:width].nil? ? [:width] : 224 [:height] = ![:height].nil? ? [:height] : 224 [:repository] = ![:repository].nil? ? [:repository] : "" [:finetuning] = ![:finetuning].nil? ? [:finetuning] : false [:solver_type] = ![:solver_type].nil? ? [:solver_type] : "SGD" # options[:solver_type] = "NESTEROV" if options[:finetuning] [:snapshot] = ![:snapshot].nil? ? [:snapshot] : 2000 [:measure_index] = ![:measure_index].nil? ? [:measure_index] : 1 measure = ["acc", "mcll", "f1"] if [:measure_index] == 1 measure = ["acc-5", "mcll", "f1"] elsif [:measure_index] == 2 measure = ["acc", "mcll", "cmdiag"] end data = { "service" => "#{[:service]}", "async" => [:async], "parameters" => { "mllib" => { "gpu" => [:gpu], "net" => { "batch_size" => [:batch_size], "test_batch_size" => [:test_batch_size] }, "solver" => { "test_interval" => [:test_interval], "iterations" => [:iterations], "base_lr" => [:base_lr], "stepsize" => [:stepsize], "gamma" => [:gamma], "test_initialization" => true, "solver_type" => "#{[:solver_type]}", "snapshot" => [:snapshot] } }, "input" => { "connector" => "#{[:connector]}", "test_split" => [:test_split], "shuffle" => [:shuffle], "width" => [:width], "height" => [:height] }, "output" => { "measure" => measure } }, "data" => [ "#{[:repository]}" ] } puts "\nparams data: #{data.to_json} \n" if debug data = if is_custom_data dede_body = { :body => data.to_json, :headers => { "Content-Type" => 'application/json' } } object = HTTParty.post(dede_api_url, dede_body) object_info = JSON.parse(object.body) object_info.extend DeepSymbolizable return object_info.deep_symbolize rescue Exception => e puts "\n[DeepdetectRuby Train - launch training]. #{e.to_s} \n" end end |