AzureVision (version 1.0.2)

predict.customvision_model: Get predictions from a Custom Vision model

Description

Get predictions from a Custom Vision model

Usage

# S3 method for customvision_model
predict(object, images, type = c("class", "prob", "list"), ...)

# S3 method for classification_service predict(object, images, type = c("class", "prob", "list"), save_result = FALSE, ...)

# S3 method for object_detection_service predict(object, images, type = c("class", "prob", "list"), save_result = FALSE, ...)

Arguments

object

A Custom Vision object from which to get predictions. See 'Details' below.

images

The images for which to get predictions.

type

The type of prediction: either class membership (the default), the class probabilities, or a list containing all information returned by the prediction endpoint.

...

Further arguments passed to lower-level functions; not used.

save_result

For the predictive service methods, whether to store the predictions on the server for future use.

Details

AzureVision defines prediction methods for both Custom Vision model training objects (of class customvision_model) and prediction services (classification_service and object_detection_service). The method for model training objects calls the "quick test" endpoint, and is meant only for testing purposes.

The prediction endpoints accept a single image per request, so supplying multiple images to these functions will call the endpoints multiple times, in sequence. The images can be specified as:

  • A vector of local filenames. All common image file formats are supported.

  • A vector of publicly accessible URLs.

  • A raw vector, or a list of raw vectors, holding the binary contents of the image files.

See Also

train_model, publish_model, classification_service, object_detection_service

Examples

Run this code
# NOT RUN {
# predicting with the training endpoint
endp <- customvision_training_endpoint(url="endpoint_url", key="key")
myproj <- get_project(endp, "myproject")
mod <- get_model(myproj)

predict(mod, "testimage.jpg")
predict(mod, "https://mysite.example.com/testimage.jpg", type="prob")

imgraw <- readBin("testimage.jpg", "raw", file.size("testimage.jpg"))
predict(mod, imgraw, type="list")

# predicting with the prediction endpoint
# you'll need either the project object or the ID
proj_id <- myproj$project$id
pred_endp <- customvision_prediction_endpoint(url="endpoint_url", key="pred_key")
pred_svc <- classification_service(pred_endp, proj_id, "iteration1")
predict(pred_svc, "testimage.jpg")

# }

Run the code above in your browser using DataCamp Workspace