BigML Bindings: 101 - Images Object DetectionΒΆ

Following the schema described in the prediction workflow, document, this is the code snippet that shows the minimal workflow to create a deepnet and produce a single prediction.

from bigml.api import BigML
# step 0: creating a connection to the service (default credentials)
api = BigML()
# step 1: creating a source from the data in your local
# "data/images/" file, that contains a collection of images
# and an "annotations.json" file with the corresponding annotations per
# image describing the regions labeled in the image
source = api.create_source("data/images/")
# waiting for the source to be finished. Results will be stored in `source`
# step 3: creating a dataset from the previously created `source`
dataset = api.create_dataset(source)
# waiting for the dataset to be finished
# step 5: creating a deepnet
deepnet = api.create_deepnet(dataset)
# waiting for the deepnet to be finished
# the new input data to predict for
input_data = "data/images/cats_test/pexels-pixabay-33358.jpg"
# creating a single prediction
prediction = api.create_prediction(deepnet, input_data)

In the previous code, the api.ok method is used to wait for the resource to be finished before calling the next create method or accessing the resource properties. In the first case, we could skip that api.ok`call because the next `create method would internally do the waiting when needed.

You can also predict locally using the Deepnet class in the deepnet module. A simple example of that is:

from bigml.deepnet import Deepnet
local_deepnet = Deepnet("deepnet/5968ec46983efc21b000001c")
# predicting for some input data
input_data = "data/images/cats_test/pexels-pixabay-33358.jpg"