Models

There are many methods to work with models.

Create Model

You can create your own model and train it with your own images and concepts. Once you train it to see how you would like it to see, you can then use that model to make predictions.

When you create a model you give it a name and an id. If you don't supply an id, one will be created for you.

js
python
java
csharp
objective-c
php
cURL
app.models.create("petsID").then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Create Model With Concepts

You can also create a model and initialize it with the concepts it will contain. You can always add and remove concepts later.

js
python
java
csharp
objective-c
php
cURL
app.models.create(
"petsID",
[
{ "id": "boscoe" }
]
).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Add Concepts To A Model

You can add concepts to a model at any point. As you add concepts to inputs, you may want to add them to your model.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel({model_id}).then(function(model) {
updateModel,
function(err) {
// there was an error
}
});
function updateModel(model) {
model.mergeConcepts({"id": "boscoe"}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}

Remove Concepts From A Model

Conversely, if you'd like to remove concepts from a model, you can also do that.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel({model_id}).then(function(model) {
updateModel,
function(err) {
// there was an error
}
});
function updateModel(model) {
model.deleteConcepts({"id": "boscoe"}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}

Update Concept Name

The code below showcases how to update a concept's name given its id.

js
python
java
csharp
objective-c
php
cURL
** Coming Soon

Update Model Name and Configuration

Here we will change the model name to 'newname' and the model's configuration to have concepts_mutually_exclusive=true and closed_environment=true.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel({model_id}).then(
updateModel,
function(err) {
// there was an error
}
);
function updateModel(model) {
model.update({
name: 'newname',
conceptsMutuallyExclusive: true,
closedEnvironment: true,
concepts: ['birds', 'hurd']
}).then(
}

Get Models

To get a list of all models including models you've created as well as public models:

js
python
java
csharp
objective-c
php
cURL
app.models.list().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Get Model By Id

All models have unique Ids. You can get a specific model by its id:

js
python
java
csharp
objective-c
php
cURL
app.models.get({model_id}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Get Model Output Info By Id

The output info of a model lists what concepts it contains.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel({model_id}).then(
getModelOutputInfo,
handleError
);
function getModelOutputInfo(model) {
model.getOutputInfo().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
}

List Model Versions

Every time you train a model, it creates a new version. You can list all the versions created.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel('{id}').then(
function(model) {
model.getVersions().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
},
function(err) {
// there was an error
}
);

Get Model Version By Id

To get a specific model version, you must provide the model_id as well as the version_id. You can inspect the model version status to determine if your model is trained or still training.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel('{id}').then(
function(model) {
model.getVersion('{version_id}').then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
},
function(err) {
// there was an error
}
);

Get Model Training Inputs

You can list all the inputs that were used to train the model.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel('{id}').then(
function(model) {
model.getInputs().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
},
function(err) {
// there was an error
}
);

Get Model Training Inputs By Version

You can also list all the inputs that were used to train a specific model version.

js
python
java
csharp
objective-c
php
cURL
app.models.initModel({id: '{model_id}', version: '{version_id}'}).then(
function(model) {
model.getInputs().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
},
function(err) {
// there was an error
}
);

Delete A Model

You can delete a model using the model_id.

js
python
java
csharp
objective-c
php
cURL
app.models.delete('{id}').then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Delete A Model Version

You can also delete a specific version of a model with the model_id and version_id.

js
python
java
csharp
objective-c
php
cURL
app.models.delete('{model_id}', '{version_id}').then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Delete All Models

If you would like to delete all models associated with an application, you can also do that. Please proceed with caution as these cannot be recovered.

js
python
java
csharp
objective-c
php
cURL
app.models.delete().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Train A Model

When you train a model, you are telling the system to look at all the images with concepts you've provided and learn from them. This train operation is asynchronous. It may take a few seconds for your model to be fully trained and ready.

Note: you can repeat this operation as often as you like. By adding more images with concepts and training, you can get the model to predict exactly how you want it to.

js
python
java
csharp
objective-c
php
cURL
app.models.train("{model_id}").then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
// or if you have an instance of a model
model.train().then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Predict With A Model

Once you have trained a model you are ready to use your new model to get predictions. The predictions returned will only contain the concepts that you told it to see.

js
python
java
csharp
objective-c
php
cURL
app.models.predict("{model_id}", ["https://samples.clarifai.com/puppy.jpg"]).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
// or if you have an instance of a model
model.predict("https://samples.clarifai.com/puppy.jpg").then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);

Search Models By Name And Type

You can search all your models by name and type of model.

js
python
java
csharp
objective-c
php
cURL
app.models.search('general-v1.3', 'concept').then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);