Skip to content

Commit 8b79044

Browse files
Merge pull request #394 from watson-developer-cloud/codegen/visual-recognition
Regenerate visual recognition
2 parents 7d6d8fa + cfdc398 commit 8b79044

1 file changed

Lines changed: 49 additions & 15 deletions

File tree

watson_developer_cloud/visual_recognition_v3.py

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class VisualRecognitionV3(WatsonService):
4141
"""The Visual Recognition V3 service."""
4242

4343
default_url = 'https://gateway-a.watsonplatform.net/visual-recognition/api'
44-
VERSION_DATE_2016_05_20 = '2016-05-20'
4544

4645
def __init__(self, version, url=default_url, api_key=None):
4746
"""
@@ -75,25 +74,33 @@ def __init__(self, version, url=default_url, api_key=None):
7574
self.version = version
7675

7776
#########################
78-
# general
77+
# General
7978
#########################
8079

8180
def classify(self,
8281
images_file=None,
8382
parameters=None,
8483
accept_language=None,
8584
images_file_content_type=None,
86-
images_filename=None):
85+
images_filename=None,
86+
url=None,
87+
threshold=None,
88+
owners=None,
89+
classifier_ids=None):
8790
"""
8891
Classify images.
8992
9093
Classify images with built-in or custom classifiers.
9194
9295
:param file images_file: An image file (.jpg, .png) or .zip file with images. Maximum image size is 10 MB. Include no more than 20 images and limit the .zip file to 100 MB. 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. You can also include images with the `url` property in the **parameters** object.
93-
:param str parameters: A JSON object that specifies additional request options. The parameter can be sent as a string or a file, and can include these inputs: - **url**: A string with the image URL to analyze. Must be in .jpg, or .png format. The minimum recommended pixel density is 32X32 pixels per inch, and the maximum image size is 10 MB. You can also include images in the **images_file** parameter. - **threshold**: A floating point value that specifies the minimum score a class must have to be displayed in the response. The default threshold for returning scores from a classifier is `0.5`. Set the threshold to `0.0` to ignore the classification score and return all values. - **owners**: An array of the categories of classifiers to apply. Use `IBM` to classify against the `default` general classifier, and use `me` to classify against your custom classifiers. To analyze the image against both classifier categories, set the value to both `IBM` and `me`. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids** is empty. - **classifier_ids**: Specifies which classifiers to apply and overrides the **owners** parameter. You can specify both custom and built-in classifiers. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The following built-in classifier IDs require no training: - `default`: Returns classes from thousands of general tags. - `food`: (Beta) Enhances specificity and accuracy for images of food items. - `explicit`: (Beta) Evaluates whether the image might be pornographic. Example: `{\"classifier_ids\":[\"CarsvsTrucks_1479118188\",\"explicit\"],\"threshold\":0.6}`.
96+
:param str parameters: (Deprecated) A JSON object that specifies additional request options. The parameter can be sent as a string or a file, and can include these inputs: - **url**: A string with the image URL to analyze. Must be in .jpg, or .png format. The minimum recommended pixel density is 32X32 pixels per inch, and the maximum image size is 10 MB. You can also include images in the **images_file** parameter. - **threshold**: A floating point value that specifies the minimum score a class must have to be displayed in the response. The default threshold for returning scores from a classifier is `0.5`. Set the threshold to `0.0` to ignore the classification score and return all values. - **owners**: An array of the categories of classifiers to apply. Use `IBM` to classify against the `default` general classifier, and use `me` to classify against your custom classifiers. To analyze the image against both classifier categories, set the value to both `IBM` and `me`. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids** is empty. - **classifier_ids**: Specifies which classifiers to apply and overrides the **owners** parameter. You can specify both custom and built-in classifiers. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The following built-in classifier IDs require no training: - `default`: Returns classes from thousands of general tags. - `food`: (Beta) Enhances specificity and accuracy for images of food items. - `explicit`: (Beta) Evaluates whether the image might be pornographic. Example: `{\"classifier_ids\":[\"CarsvsTrucks_1479118188\",\"explicit\"],\"threshold\":0.6}`.
9497
:param str accept_language: Specifies the language of the output class names. Can be `en` (English), `ar` (Arabic), `de` (German), `es` (Spanish), `it` (Italian), `ja` (Japanese), or `ko` (Korean). Classes for which no translation is available are omitted. The response might not be in the specified language under these conditions: - English is returned when the requested language is not supported. - Classes are not returned when there is no translation for them. - Custom classifiers returned with this method return tags in the language of the custom classifier.
9598
:param str images_file_content_type: The content type of images_file.
9699
:param str images_filename: The filename for images_file.
100+
:param str url: A string with the image URL to analyze. Must be in .jpg, or .png format. The minimum recommended pixel density is 32X32 pixels per inch, and the maximum image size is 10 MB. You can also include images in the **images_file** parameter.
101+
:param float threshold: A floating point value that specifies the minimum score a class must have to be displayed in the response. The default threshold for returning scores from a classifier is `0.5`. Set the threshold to `0.0` to ignore the classification score and return all values.
102+
:param list[str] owners: An array of the categories of classifiers to apply. Use `IBM` to classify against the `default` general classifier, and use `me` to classify against your custom classifiers. To analyze the image against both classifier categories, set the value to both `IBM` and `me`. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids** is empty.
103+
:param list[str] classifier_ids: The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids** is empty. - **classifier_ids**: Specifies which classifiers to apply and overrides the **owners** parameter. You can specify both custom and built-in classifiers. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are empty. The following built-in classifier IDs require no training: - `default`: Returns classes from thousands of general tags. - `food`: (Beta) Enhances specificity and accuracy for images of food items. - `explicit`: (Beta) Evaluates whether the image might be pornographic. Example: `\"classifier_ids=\"CarsvsTrucks_1479118188\",\"explicit\"`.
97104
:return: A `dict` containing the `ClassifiedImages` response.
98105
:rtype: dict
99106
"""
@@ -105,31 +112,51 @@ def classify(self,
105112
images_filename = images_file.name
106113
mime_type = images_file_content_type or 'application/octet-stream'
107114
images_file_tuple = (images_filename, images_file, mime_type)
115+
108116
parameters_tuple = None
109-
if parameters:
117+
if parameters is not None:
110118
parameters_tuple = (None, parameters, 'text/plain')
119+
120+
url_tuple = None
121+
if url is not None:
122+
url_tuple = (None, url, 'text/plain')
123+
threshold_tuple = None
124+
if threshold is not None:
125+
threshold_tuple = (None, threshold, 'application/json')
126+
owners_tuple = None
127+
if owners is not None:
128+
owners_tuple = (None, owners, 'application/json')
129+
classifier_ids_tuple = None
130+
if classifier_ids is not None:
131+
classifier_ids_tuple = (None, classifier_ids, 'application/json')
132+
111133
url = '/v3/classify'
112134
response = self.request(
113135
method='POST',
114136
url=url,
115137
headers=headers,
116138
params=params,
117139
files={
140+
'parameters': parameters_tuple,
118141
'images_file': images_file_tuple,
119-
'parameters': parameters_tuple
142+
'url': url_tuple,
143+
'threshold': threshold_tuple,
144+
'owners': owners_tuple,
145+
'classifier_ids': classifier_ids_tuple
120146
},
121147
accept_json=True)
122148
return response
123149

124150
#########################
125-
# face
151+
# Face
126152
#########################
127153

128154
def detect_faces(self,
129155
images_file=None,
130156
parameters=None,
131157
images_file_content_type=None,
132-
images_filename=None):
158+
images_filename=None,
159+
url=None):
133160
"""
134161
Detect faces in images.
135162
@@ -139,9 +166,10 @@ def detect_faces(self,
139166
does not support general biometric facial recognition.
140167
141168
:param file images_file: An image file (.jpg, .png) or .zip file with images. Include no more than 15 images. You can also include images with the `url` property in the **parameters** object. All faces are detected, but if there are more than 10 faces in an image, age and gender confidence scores might return scores of 0.
142-
:param str parameters: A JSON object that specifies a single image (.jpg, .png) to analyze by URL. The parameter can be sent as a string or a file. Example: `{\"url\":\"http://www.example.com/images/myimage.jpg\"}`.
169+
:param str parameters: (Deprecated) A JSON object that specifies a single image (.jpg, .png) to analyze by URL. The parameter can be sent as a string or a file. Example: `{\"url\":\"http://www.example.com/images/myimage.jpg\"}`.
143170
:param str images_file_content_type: The content type of images_file.
144171
:param str images_filename: The filename for images_file.
172+
:param str url: A string with the image URL to analyze.
145173
:return: A `dict` containing the `DetectedFaces` response.
146174
:rtype: dict
147175
"""
@@ -153,22 +181,24 @@ def detect_faces(self,
153181
mime_type = images_file_content_type or 'application/octet-stream'
154182
images_file_tuple = (images_filename, images_file, mime_type)
155183
parameters_tuple = None
156-
if parameters:
184+
if parameters is not None:
157185
parameters_tuple = (None, parameters, 'text/plain')
186+
url_tuple = None
187+
if url is not None:
188+
url_tuple = (None, url, 'text/plain')
158189
url = '/v3/detect_faces'
159190
response = self.request(
160191
method='POST',
161192
url=url,
162193
params=params,
163-
files={
164-
'images_file': images_file_tuple,
165-
'parameters': parameters_tuple
166-
},
194+
files={'images_file': images_file_tuple,
195+
'parameters': parameters_tuple,
196+
'url': url_tuple},
167197
accept_json=True)
168198
return response
169199

170200
#########################
171-
# custom
201+
# Custom
172202
#########################
173203

174204
def create_classifier(self,
@@ -290,6 +320,8 @@ def __init__(self, class_name):
290320
def _from_dict(cls, _dict):
291321
"""Initialize a Class object from a json dictionary."""
292322
args = {}
323+
if 'class_name' in _dict:
324+
args['class_name'] = _dict['class_name']
293325
if 'class' in _dict:
294326
args['class_name'] = _dict['class']
295327
else:
@@ -344,6 +376,8 @@ def __init__(self, class_name, score=None, type_hierarchy=None):
344376
def _from_dict(cls, _dict):
345377
"""Initialize a ClassResult object from a json dictionary."""
346378
args = {}
379+
if 'class_name' in _dict:
380+
args['class_name'] = _dict['class_name']
347381
if 'class' in _dict:
348382
args['class_name'] = _dict['class']
349383
else:

0 commit comments

Comments
 (0)