Class: Clarinet::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/clarinet/model.rb

Constant Summary collapse

GENERAL =
'aaa03c23b3724a16a56b629203edc62c'
FOOD =
'bd367be194cf45149e75f01d59f77ba7'
TRAVEL =
'eee28c313d69466f836ab83287a54ed9'
NSFW =
'e9576d86d2004ed1a38ba0cf39ecb4b1'
WEDDINGS =
'c386b7a870114f4a87477c0824499348'
COLOR =
'eeed0b6733a644cea07cf4c60f87ebb7'
MAX_INPUT_COUNT =
128

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_idString (readonly)



30
31
32
# File 'lib/clarinet/model.rb', line 30

def app_id
  @app_id
end

#created_atString (readonly)



27
28
29
# File 'lib/clarinet/model.rb', line 27

def created_at
  @created_at
end

#idString (readonly)



21
22
23
# File 'lib/clarinet/model.rb', line 21

def id
  @id
end

#model_versionString (readonly)



36
37
38
# File 'lib/clarinet/model.rb', line 36

def model_version
  @model_version
end

#nameString (readonly)



24
25
26
# File 'lib/clarinet/model.rb', line 24

def name
  @name
end

#output_infoHash (readonly)



33
34
35
# File 'lib/clarinet/model.rb', line 33

def output_info
  @output_info
end

#raw_dataHash (readonly)



18
19
20
# File 'lib/clarinet/model.rb', line 18

def raw_data
  @raw_data
end

Instance Method Details

#delete_concepts(concepts) ⇒ Clarinet::Model

Remove concepts from a model



91
92
93
94
# File 'lib/clarinet/model.rb', line 91

def delete_concepts(concepts)
  concepts = [concepts] unless concepts.is_a? Array
  update 'remove', { concepts: concepts }
end

#get_output_infoClarinet::Model

Returns all the model’s output info



55
56
57
58
# File 'lib/clarinet/model.rb', line 55

def get_output_info
  response_data = @app.client.model_output_info @id
  Clarinet::Model.new @app, response_data[:model]
end

#merge_concepts(concepts) ⇒ Clarinet::Model

Merge concepts to a model



99
100
101
102
# File 'lib/clarinet/model.rb', line 99

def merge_concepts(concepts)
  concepts = [concepts] unless concepts.is_a? Array
  update 'merge', { concepts: concepts }
end

#overwrite_concepts(concepts) ⇒ Clarinet::Model

Overwrite concepts in a model



107
108
109
110
# File 'lib/clarinet/model.rb', line 107

def overwrite_concepts(concepts)
  concepts = [concepts] unless concepts.is_a? Array
  update 'merge', { concepts: concepts }
end

#predict(inputs, config = {}) ⇒ Hash

Returns model ouputs according to inputs

Options Hash (inputs):

  • :image (Hash)

    Object with at least :url or :base64 key as explained below:

    • :url (String) A publicly accessibly

    • :base64 (String) Base64 string representing image bytes

    • :crop (Array<Float>) An array containing the percent to be cropped from top, left, bottom and right



69
70
71
72
73
74
75
76
77
# File 'lib/clarinet/model.rb', line 69

def predict(inputs, config = {})
  video = config[:video] || false
  config.delete :video

  inputs = [inputs] unless inputs.is_a? Array
  inputs = inputs.map { |input| Clarinet::Utils.format_media_predict(input) }

  @app.client.outputs id, inputs, config
end

#trainClarinet::Model

Note:

Training takes some time and the new version will not be immediately available.

Create a new model version



115
116
117
118
# File 'lib/clarinet/model.rb', line 115

def train
  response_data = @app.client.model_train @id
  Clarinet::Model.new @app, response_data[:model]
end

#versions(options = { page: 1, per_page: 20 }) ⇒ Hash

Returns a list of versions of the model

Options Hash (options):

  • :page (Int) — default: 1

    The page number

  • :per_page (Int) — default: 20

    Number of models to return per page



84
85
86
# File 'lib/clarinet/model.rb', line 84

def versions(options = { page: 1, per_page: 20 })
  @app.client.model_versions @id, options
end