class Clarinet::Model
Constants
- COLOR
- FOOD
- GENERAL
- MAX_INPUT_COUNT
- NSFW
- TRAVEL
- WEDDINGS
Attributes
@return [String]
@return [String] Created at timestamp
@return [String] Model
id
@return [String]
@return [String] Model
name
@return [Hash]
@return [Hash] Raw API data used to construct this instance
Public Class Methods
@!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
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
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 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 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
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
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
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
# 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