class Clarinet::Model

Constants

COLOR
FOOD
GENERAL
MAX_INPUT_COUNT
NSFW
TRAVEL
WEDDINGS

Attributes

app_id[R]

@return [String]

created_at[R]

@return [String] Created at timestamp

id[R]

@return [String] Model id

model_version[R]

@return [String]

name[R]

@return [String] Model name

output_info[R]

@return [Hash]

raw_data[R]

@return [Hash] Raw API data used to construct this instance

Public Class Methods

new(app, raw_data) click to toggle source

@!visibility private

# File lib/clarinet/model.rb, line 39
def initialize(app, raw_data)
  @app = app

  @raw_data = raw_data

  @id = raw_data[:id]
  @name = raw_data[:name]
  @created_at = raw_data[:created_at]
  @app_id = raw_data[:app_id]
  @output_info = raw_data[:output_info]

  @model_version = raw_data[:model_version]
end

Public Instance Methods

delete_concepts(concepts) click to toggle source

Remove concepts from a model @param concepts [Array<Hash>] List of concept hashes with id @return [Clarinet::Model] Model instance

# 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_info() click to toggle source

Returns all the model's output info @return [Clarinet::Model] Model instance with complete output_info data

# 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) click to toggle source

Merge concepts to a model @param (see delete_concepts) @return (see delete_concepts)

# 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) click to toggle source

Overwrite concepts in a model @param (see delete_concepts) @return (see delete_concepts)

# 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 = {}) click to toggle source

Returns model ouputs according to inputs @param inputs [String, Hash, Array<String>, Array<Hash>] An array of objects/object/string pointing to

an image resource. A string can either be a url or base64 image bytes. Object keys explained below:

@!macro predict_inputs

@option inputs [Hash] :image 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

@return [Hash] API response

# 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
train() click to toggle source

Create a new model version @note Training takes some time and the new version will not be immediately available. @return [Clarinet::Model] Model instance

# 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 }) click to toggle source

Returns a list of versions of the model @param options [Hash] Listing options @option options [Int] :page (1) The page number @option options [Int] :per_page (20) Number of models to return per page @return [Hash] API response

# File lib/clarinet/model.rb, line 84
def versions(options = { page: 1, per_page: 20 })
  @app.client.model_versions @id, options
end

Private Instance Methods

update(action, obj) click to toggle source
# File lib/clarinet/model.rb, line 122
def update(action, obj)
  model_data = obj.merge id: @id
  data = {
    models: [Clarinet::Utils.format_model(model_data)]
  }

  response_data = @app.client.models_update data
  Clarinet::Model.new @app, response_data[:models].first
end