ibm_watson.visual_recognition_v4 module

Provide images to the IBM Watson™ Visual Recognition service for analysis. The service detects objects based on a set of images with training data.

class VisualRecognitionV4(version, authenticator=None)[source]

Bases: ibm_cloud_sdk_core.base_service.BaseService

The Visual Recognition V4 service.

default_service_url = 'https://gateway.watsonplatform.net/visual-recognition/api'
analyze(collection_ids, features, *, images_file=None, image_url=None, threshold=None, **kwargs)[source]

Analyze images.

Analyze images by URL, by file, or both against your own collection. Make sure that training_status.objects.ready is true for the feature before you use a collection to analyze images. Encode the image and .zip file names in UTF-8 if they contain non-ASCII characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters.

Parameters
  • collection_ids (list[str]) – The IDs of the collections to analyze.

  • features (list[str]) – The features to analyze.

  • images_file (list[FileWithMetadata]) – (optional) An array of image files (.jpg or .png) or .zip files with images. - Include a maximum of 20 images in a request. - Limit the .zip file to 100 MB. - Limit each image file to 10 MB. You can also include an image with the image_url parameter.

  • image_url (list[str]) – (optional) An array of URLs of image files (.jpg or .png). - Include a maximum of 20 images in a request. - Limit each image file to 10 MB. - Minimum width and height is 30 pixels, but the service tends to perform better with images that are at least 300 x 300 pixels. Maximum is 5400 pixels for either height or width. You can also include images with the images_file parameter.

  • threshold (float) – (optional) The minimum score a feature must have to be returned.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

create_collection(*, name=None, description=None, **kwargs)[source]

Create a collection.

Create a collection that can be used to store images. To create a collection without specifying a name and description, include an empty JSON object in the request body. Encode the name and description in UTF-8 if they contain non-ASCII characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters.

Parameters
  • name (str) – (optional) The name of the collection. The name can contain alphanumeric, underscore, hyphen, and dot characters. It cannot begin with the reserved prefix sys-.

  • description (str) – (optional) The description of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

list_collections(**kwargs)[source]

List collections.

Retrieves a list of collections for the service instance.

Parameters

headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

get_collection(collection_id, **kwargs)[source]

Get collection details.

Get details of one collection.

Parameters
  • collection_id (str) – The identifier of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

update_collection(collection_id, *, name=None, description=None, **kwargs)[source]

Update a collection.

Update the name or description of a collection. Encode the name and description in UTF-8 if they contain non-ASCII characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters.

Parameters
  • collection_id (str) – The identifier of the collection.

  • name (str) – (optional) The name of the collection. The name can contain alphanumeric, underscore, hyphen, and dot characters. It cannot begin with the reserved prefix sys-.

  • description (str) – (optional) The description of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

delete_collection(collection_id, **kwargs)[source]

Delete a collection.

Delete a collection from the service instance.

Parameters
  • collection_id (str) – The identifier of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

add_images(collection_id, *, images_file=None, image_url=None, training_data=None, **kwargs)[source]

Add images.

Add images to a collection by URL, by file, or both. Encode the image and .zip file names in UTF-8 if they contain non-ASCII characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters.

Parameters
  • collection_id (str) – The identifier of the collection.

  • images_file (list[FileWithMetadata]) – (optional) An array of image files (.jpg or .png) or .zip files with images. - Include a maximum of 20 images in a request. - Limit the .zip file to 100 MB. - Limit each image file to 10 MB. You can also include an image with the image_url parameter.

  • image_url (list[str]) – (optional) The array of URLs of image files (.jpg or .png). - Include a maximum of 20 images in a request. - Limit each image file to 10 MB. - Minimum width and height is 30 pixels, but the service tends to perform better with images that are at least 300 x 300 pixels. Maximum is 5400 pixels for either height or width. You can also include images with the images_file parameter.

  • training_data (str) – (optional) Training data for a single image. Include training data only if you add one image with the request. The object property can contain alphanumeric, underscore, hyphen, space, and dot characters. It cannot begin with the reserved prefix sys- and must be no longer than 32 characters.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

list_images(collection_id, **kwargs)[source]

List images.

Retrieves a list of images in a collection.

Parameters
  • collection_id (str) – The identifier of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

get_image_details(collection_id, image_id, **kwargs)[source]

Get image details.

Get the details of an image in a collection.

Parameters
  • collection_id (str) – The identifier of the collection.

  • image_id (str) – The identifier of the image.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

delete_image(collection_id, image_id, **kwargs)[source]

Delete an image.

Delete one image from a collection.

Parameters
  • collection_id (str) – The identifier of the collection.

  • image_id (str) – The identifier of the image.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

get_jpeg_image(collection_id, image_id, *, size=None, **kwargs)[source]

Get a JPEG file of an image.

Download a JPEG representation of an image.

Parameters
  • collection_id (str) – The identifier of the collection.

  • image_id (str) – The identifier of the image.

  • size (str) – (optional) The image size. Specify thumbnail to return a version that maintains the original aspect ratio but is no larger than 200 pixels in the larger dimension. For example, an original 800 x 1000 image is resized to 160 x 200 pixels.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

train(collection_id, **kwargs)[source]

Train a collection.

Start training on images in a collection. The collection must have enough training data and untrained data (the training_status.objects.data_changed is true). If training is in progress, the request queues the next training job.

Parameters
  • collection_id (str) – The identifier of the collection.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

add_image_training_data(collection_id, image_id, *, objects=None, **kwargs)[source]

Add training data to an image.

Add, update, or delete training data for an image. Encode the object name in UTF-8 if it contains non-ASCII characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters. Elements in the request replace the existing elements. - To update the training data, provide both the unchanged and the new or changed values. - To delete the training data, provide an empty value for the training data.

Parameters
  • collection_id (str) – The identifier of the collection.

  • image_id (str) – The identifier of the image.

  • objects (list[TrainingDataObject]) – (optional) Training data for specific objects.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

get_training_usage(*, start_time=None, end_time=None, **kwargs)[source]

Get training usage.

Information about the completed training events. You can use this information to determine how close you are to the training limits for the month.

Parameters
  • start_time (str) – (optional) The earliest day to include training events. Specify dates in YYYY-MM-DD format. If empty or not specified, the earliest training event is included.

  • end_time (str) – (optional) The most recent day to include training events. Specify dates in YYYY-MM-DD format. All events for the day are included. If empty or not specified, the current day is used. Specify the same value as start_time to request events for a single day.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

delete_user_data(customer_id, **kwargs)[source]

Delete labeled data.

Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with the customer ID. You associate a customer ID with data by passing the X-Watson-Metadata header with a request that passes data. For more information about personal data and customer IDs, see [Information security](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-information-security).

Parameters
  • customer_id (str) – The customer ID for which all data is to be deleted.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

class AnalyzeEnums[source]

Bases: object

class Features[source]

Bases: enum.Enum

The features to analyze.

OBJECTS = 'objects'
class GetJpegImageEnums[source]

Bases: object

class Size[source]

Bases: enum.Enum

The image size. Specify thumbnail to return a version that maintains the original aspect ratio but is no larger than 200 pixels in the larger dimension. For example, an original 800 x 1000 image is resized to 160 x 200 pixels.

FULL = 'full'
THUMBNAIL = 'thumbnail'
class AnalyzeResponse(images, *, warnings=None, trace=None)[source]

Bases: object

Results for all images.

Attr list[Image] images

Analyzed images.

Attr list[Warning] warnings

(optional) Information about what might cause less than optimal output.

Attr str trace

(optional) A unique identifier of the request. Included only when an error or warning is returned.

class Collection(collection_id, name, description, created, updated, image_count, training_status)[source]

Bases: object

Details about a collection.

Attr str collection_id

The identifier of the collection.

Attr str name

The name of the collection.

Attr str description

The description of the collection.

Attr datetime created

Date and time in Coordinated Universal Time (UTC) that the collection was created.

Attr datetime updated

Date and time in Coordinated Universal Time (UTC) that the collection was most recently updated.

Attr int image_count

Number of images in the collection.

Attr TrainingStatus training_status

Training status information for the collection.

class CollectionObjects(collection_id, objects)[source]

Bases: object

The objects in a collection that are detected in an image.

Attr str collection_id

The identifier of the collection.

Attr list[ObjectDetail] objects

The identified objects in a collection.

class CollectionsList(collections)[source]

Bases: object

A container for the list of collections.

Attr list[Collection] collections

The collections in this service instance.

class DetectedObjects(*, collections=None)[source]

Bases: object

Container for the list of collections that have objects detected in an image.

Attr list[CollectionObjects] collections

(optional) The collections with identified objects.

class Error(code, message, *, more_info=None, target=None)[source]

Bases: object

Details about an error.

Attr str code

Identifier of the problem.

Attr str message

An explanation of the problem with possible solutions.

Attr str more_info

(optional) A URL for more information about the solution.

Attr ErrorTarget target

(optional) Details about the specific area of the problem.

class CodeEnum[source]

Bases: enum.Enum

Identifier of the problem.

INVALID_FIELD = 'invalid_field'
INVALID_HEADER = 'invalid_header'
INVALID_METHOD = 'invalid_method'
MISSING_FIELD = 'missing_field'
SERVER_ERROR = 'server_error'
class ErrorTarget(type, name)[source]

Bases: object

Details about the specific area of the problem.

Attr str type

The parameter or property that is the focus of the problem.

Attr str name

The property that is identified with the problem.

class TypeEnum[source]

Bases: enum.Enum

The parameter or property that is the focus of the problem.

FIELD = 'field'
PARAMETER = 'parameter'
HEADER = 'header'
class Image(source, dimensions, objects, *, errors=None)[source]

Bases: object

Details about an image.

Attr ImageSource source

The source type of the image.

Attr ImageDimensions dimensions

Height and width of an image.

Attr DetectedObjects objects

Container for the list of collections that have objects detected in an image.

Attr list[Error] errors

(optional) A container for the problems in the request.

class ImageDetails(source, *, image_id=None, updated=None, created=None, dimensions=None, errors=None, training_data=None)[source]

Bases: object

Details about an image.

Attr str image_id

(optional) The identifier of the image.

Attr datetime updated

(optional) Date and time in Coordinated Universal Time (UTC) that the image was most recently updated.

Attr datetime created

(optional) Date and time in Coordinated Universal Time (UTC) that the image was created.

Attr ImageSource source

The source type of the image.

Attr ImageDimensions dimensions

(optional) Height and width of an image.

Attr list[Error] errors

(optional)

Attr TrainingDataObjects training_data

(optional) Training data for all objects.

class ImageDetailsList(*, images=None, warnings=None, trace=None)[source]

Bases: object

List of information about the images.

Attr list[ImageDetails] images

(optional) The images in the collection.

Attr list[Warning] warnings

(optional) Information about what might cause less than optimal output.

Attr str trace

(optional) A unique identifier of the request. Included only when an error or warning is returned.

class ImageDimensions(*, height=None, width=None)[source]

Bases: object

Height and width of an image.

Attr int height

(optional) Height in pixels of the image.

Attr int width

(optional) Width in pixels of the image.

class ImageSource(type, *, filename=None, archive_filename=None, source_url=None, resolved_url=None)[source]

Bases: object

The source type of the image.

Attr str type

The source type of the image.

Attr str filename

(optional) Name of the image file if uploaded. Not returned when the image is passed by URL.

Attr str archive_filename

(optional) Name of the .zip file of images if uploaded. Not returned when the image is passed directly or by URL.

Attr str source_url

(optional) Source of the image before any redirects. Not returned when the image is uploaded.

Attr str resolved_url

(optional) Fully resolved URL of the image after redirects are followed. Not returned when the image is uploaded.

class TypeEnum[source]

Bases: enum.Enum

The source type of the image.

FILE = 'file'
URL = 'url'
class ImageSummary(*, image_id=None, updated=None)[source]

Bases: object

Basic information about an image.

Attr str image_id

(optional) The identifier of the image.

Attr datetime updated

(optional) Date and time in Coordinated Universal Time (UTC) that the image was most recently updated.

class ImageSummaryList(images)[source]

Bases: object

List of images.

Attr list[ImageSummary] images

The images in the collection.

class Location(top, left, width, height)[source]

Bases: object

Defines the location of the bounding box around the object.

Attr int top

Y-position of top-left pixel of the bounding box.

Attr int left

X-position of top-left pixel of the bounding box.

Attr int width

Width in pixels of of the bounding box.

Attr int height

Height in pixels of the bounding box.

class ObjectDetail(object, location, score)[source]

Bases: object

Details about an object in the collection.

Attr str object

The label for the object.

Attr Location location

Defines the location of the bounding box around the object.

Attr float score

Confidence score for the object in the range of 0 to 1. A higher score indicates greater likelihood that the object is depicted at this location in the image.

class ObjectTrainingStatus(ready, in_progress, data_changed, latest_failed, description)[source]

Bases: object

Training status for the objects in the collection.

Attr bool ready

Whether you can analyze images in the collection with the objects feature.

Attr bool in_progress

Whether training is in progress.

Attr bool data_changed

Whether there are changes to the training data since the most recent training.

Attr bool latest_failed

Whether the most recent training failed.

Attr str description

Details about the training. If training is in progress, includes information about the status. If training is not in progress, includes a success message or information about why training failed.

class TrainingDataObject(*, object=None, location=None)[source]

Bases: object

Details about the training data.

Attr str object

(optional) The name of the object.

Attr Location location

(optional) Defines the location of the bounding box around the object.

class TrainingDataObjects(*, objects=None)[source]

Bases: object

Training data for all objects.

Attr list[TrainingDataObject] objects

(optional) Training data for specific objects.

class TrainingEvent(*, type=None, collection_id=None, completion_time=None, status=None, image_count=None)[source]

Bases: object

Details about the training event.

Attr str type

(optional) Trained object type. Only objects is currently supported.

Attr str collection_id

(optional) Identifier of the trained collection.

Attr datetime completion_time

(optional) Date and time in Coordinated Universal Time (UTC) that training on the collection finished.

Attr str status

(optional) Training status of the training event.

Attr int image_count

(optional) The total number of images that were used in training for this training event.

class TypeEnum[source]

Bases: enum.Enum

Trained object type. Only objects is currently supported.

OBJECTS = 'objects'
class StatusEnum[source]

Bases: enum.Enum

Training status of the training event.

FAILED = 'failed'
SUCCEEDED = 'succeeded'
class TrainingEvents(*, start_time=None, end_time=None, completed_events=None, trained_images=None, events=None)[source]

Bases: object

Details about the training events.

Attr datetime start_time

(optional) The starting day for the returned training events in Coordinated Universal Time (UTC). If not specified in the request, it identifies the earliest training event.

Attr datetime end_time

(optional) The ending day for the returned training events in Coordinated Universal Time (UTC). If not specified in the request, it lists the current time.

Attr int completed_events

(optional) The total number of training events in the response for the start and end times.

Attr int trained_images

(optional) The total number of images that were used in training for the start and end times.

Attr list[TrainingEvent] events

(optional) The completed training events for the start and end time.

class TrainingStatus(objects)[source]

Bases: object

Training status information for the collection.

Attr ObjectTrainingStatus objects

Training status for the objects in the collection.

class Warning(code, message, *, more_info=None)[source]

Bases: object

Details about a problem.

Attr str code

Identifier of the problem.

Attr str message

An explanation of the problem with possible solutions.

Attr str more_info

(optional) A URL for more information about the solution.

class CodeEnum[source]

Bases: enum.Enum

Identifier of the problem.

INVALID_FIELD = 'invalid_field'
INVALID_HEADER = 'invalid_header'
INVALID_METHOD = 'invalid_method'
MISSING_FIELD = 'missing_field'
SERVER_ERROR = 'server_error'
class FileWithMetadata(data, *, filename=None, content_type=None)[source]

Bases: object

A file with its associated metadata.

Attr file data

The data / content for the file.

Attr str filename

(optional) The filename of the file.

Attr str content_type

(optional) The content type of the file.