@@ -60,7 +60,7 @@ def __init__(
6060 ready for a later version.
6161
6262 :param str url: The base url to use when contacting the service (e.g.
63- "https://gateway.watsonplatform.net/visual-recognition/api").
63+ "https://gateway.watsonplatform.net/visual-recognition/api/visual-recognition/api ").
6464 The base url may differ between Bluemix regions.
6565
6666 :param str iam_apikey: An API key that can be used to request IAM tokens. If
@@ -93,13 +93,13 @@ def __init__(
9393
9494 def classify (self ,
9595 images_file = None ,
96- accept_language = None ,
96+ images_filename = None ,
9797 url = None ,
9898 threshold = None ,
9999 owners = None ,
100100 classifier_ids = None ,
101+ accept_language = None ,
101102 images_file_content_type = None ,
102- images_filename = None ,
103103 ** kwargs ):
104104 """
105105 Classify images.
@@ -112,8 +112,7 @@ def classify(self,
112112 non-ASCII characters. The service assumes UTF-8 encoding if it encounters
113113 non-ASCII characters.
114114 You can also include an image with the **url** parameter.
115- :param str accept_language: The desired language of parts of the response. See the
116- response for details.
115+ :param str images_filename: The filename for images_file.
117116 :param str url: The URL of an image (.gif, .jpg, .png, .tif) to analyze. The
118117 minimum recommended pixel density is 32X32 pixels, but the service tends to
119118 perform better with images that are at least 224 x 224 pixels. The maximum image
@@ -138,8 +137,9 @@ def classify(self,
138137 - `default`: Returns classes from thousands of general tags.
139138 - `food`: Enhances specificity and accuracy for images of food items.
140139 - `explicit`: Evaluates whether the image might be pornographic.
140+ :param str accept_language: The desired language of parts of the response. See the
141+ response for details.
141142 :param str images_file_content_type: The content type of images_file.
142- :param str images_filename: The filename for images_file.
143143 :param dict headers: A `dict` containing the request headers
144144 :return: A `DetailedResponse` containing the result, headers and HTTP status code.
145145 :rtype: DetailedResponse
@@ -188,10 +188,10 @@ def classify(self,
188188
189189 def detect_faces (self ,
190190 images_file = None ,
191- url = None ,
192- images_file_content_type = None ,
193191 images_filename = None ,
192+ url = None ,
194193 accept_language = None ,
194+ images_file_content_type = None ,
195195 ** kwargs ):
196196 """
197197 Detect faces in images.
@@ -215,16 +215,16 @@ def detect_faces(self,
215215 characters. The service assumes UTF-8 encoding if it encounters non-ASCII
216216 characters.
217217 You can also include an image with the **url** parameter.
218+ :param str images_filename: The filename for images_file.
218219 :param str url: The URL of an image to analyze. Must be in .gif, .jpg, .png, or
219220 .tif format. The minimum recommended pixel density is 32X32 pixels, but the
220221 service tends to perform better with images that are at least 224 x 224 pixels.
221222 The maximum image size is 10 MB. Redirects are followed, so you can use a
222223 shortened URL.
223224 You can also include images with the **images_file** parameter.
224- :param str images_file_content_type: The content type of images_file.
225- :param str images_filename: The filename for images_file.
226225 :param str accept_language: The desired language of parts of the response. See the
227226 response for details.
227+ :param str images_file_content_type: The content type of images_file.
228228 :param dict headers: A `dict` containing the request headers
229229 :return: A `DetailedResponse` containing the result, headers and HTTP status code.
230230 :rtype: DetailedResponse
@@ -264,6 +264,8 @@ def detect_faces(self,
264264
265265 def create_classifier (self ,
266266 name ,
267+ positive_examples ,
268+ positive_examples_filename = {},
267269 negative_examples = None ,
268270 negative_examples_filename = None ,
269271 ** kwargs ):
@@ -280,36 +282,33 @@ def create_classifier(self,
280282
281283 :param str name: The name of the new classifier. Encode special characters in
282284 UTF-8.
283- :param file negative_examples: A .zip file of images that do not depict the visual
284- subject of any of the classes of the new classifier. Must contain a minimum of 10
285- images.
286- Encode special characters in the file name in UTF-8.
287- :param str negative_examples_filename: The filename for negative_examples.
288- :param file positive_examples: A .zip file of images that depict the visual
289- subject of a class in the new classifier. You can include more than one positive
290- example file in a call.
285+ :param dict positive_examples: A dictionary that contains the value for each
286+ classname. The value is a .zip file of images that depict the visual subject of a
287+ class in the new classifier. You can include more than one positive example file
288+ in a call.
291289 Specify the parameter name by appending `_positive_examples` to the class name.
292290 For example, `goldenretriever_positive_examples` creates the class
293291 **goldenretriever**.
294292 Include at least 10 images in .jpg or .png format. The minimum recommended image
295293 resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100
296294 MB per .zip file.
297295 Encode special characters in the file name in UTF-8.
298- :param str positive_examples_filename: The filename for positive_examples.
296+ :param dict positive_examples_filename: A dictionary that contains the value for
297+ each classname. The value is the filename for positive_examples.
298+ :param file negative_examples: A .zip file of images that do not depict the visual
299+ subject of any of the classes of the new classifier. Must contain a minimum of 10
300+ images.
301+ Encode special characters in the file name in UTF-8.
302+ :param str negative_examples_filename: The filename for negative_examples.
299303 :param dict headers: A `dict` containing the request headers
300304 :return: A `DetailedResponse` containing the result, headers and HTTP status code.
301305 :rtype: DetailedResponse
302306 """
303307
304308 if name is None :
305309 raise ValueError ('name must be provided' )
306- positive_examples_keys = [
307- key for key in kwargs if re .match ('^.+_positive_examples$' , key )
308- ]
309- if not positive_examples_keys :
310- raise ValueError (
311- 'At least one <classname>_positive_examples parameter must be provided'
312- )
310+ if positive_examples is None :
311+ raise ValueError ('positive_examples must be provided' )
313312
314313 headers = {}
315314 if 'headers' in kwargs :
@@ -321,6 +320,14 @@ def create_classifier(self,
321320
322321 form_data = {}
323322 form_data ['name' ] = (None , name , 'text/plain' )
323+ for key in positive_examples .keys ():
324+ part_name = '%s_positive_examples' % (key )
325+ value = positive_examples [key ]
326+ if positive_examples_filename :
327+ filename = positive_examples_filename .get (key )
328+ if not filename and hasattr (value , 'name' ):
329+ filename = basename (value .name )
330+ form_data [part_name ] = (filename , value , 'application/octet-stream' )
324331 if negative_examples :
325332 if not negative_examples_filename and hasattr (
326333 negative_examples , 'name' ):
@@ -330,12 +337,6 @@ def create_classifier(self,
330337 form_data ['negative_examples' ] = (negative_examples_filename ,
331338 negative_examples ,
332339 'application/octet-stream' )
333- for key in positive_examples_keys :
334- value = kwargs [key ]
335- filename = kwargs .get (key + '_filename' )
336- if not filename and hasattr (value , 'name' ):
337- filename = basename (value .name )
338- form_data [key ] = (filename , value , 'application/octet-stream' )
339340
340341 url = '/v3/classifiers'
341342 response = self .request (
@@ -441,6 +442,8 @@ def list_classifiers(self, verbose=None, **kwargs):
441442
442443 def update_classifier (self ,
443444 classifier_id ,
445+ positive_examples = {},
446+ positive_examples_filename = {},
444447 negative_examples = None ,
445448 negative_examples_filename = None ,
446449 ** kwargs ):
@@ -460,33 +463,31 @@ def update_classifier(self,
460463 retraining finished.
461464
462465 :param str classifier_id: The ID of the classifier.
463- :param file negative_examples: A .zip file of images that do not depict the visual
464- subject of any of the classes of the new classifier. Must contain a minimum of 10
465- images.
466- Encode special characters in the file name in UTF-8.
467- :param str negative_examples_filename: The filename for negative_examples.
468- :param file positive_examples: A .zip file of images that depict the visual
469- subject of a class in the classifier. The positive examples create or update
470- classes in the classifier. You can include more than one positive example file in
471- a call.
466+ :param dict positive_examples: A dictionary that contains the value for each
467+ classname. The value is a .zip file of images that depict the visual subject of a
468+ class in the classifier. The positive examples create or update classes in the
469+ classifier. You can include more than one positive example file in a call.
472470 Specify the parameter name by appending `_positive_examples` to the class name.
473471 For example, `goldenretriever_positive_examples` creates the class
474472 `goldenretriever`.
475473 Include at least 10 images in .jpg or .png format. The minimum recommended image
476474 resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100
477475 MB per .zip file.
478476 Encode special characters in the file name in UTF-8.
479- :param str positive_examples_filename: The filename for positive_examples.
477+ :param dict positive_examples_filename: A dictionary that contains the value for
478+ each classname. The value is the filename for positive_examples.
479+ :param file negative_examples: A .zip file of images that do not depict the visual
480+ subject of any of the classes of the new classifier. Must contain a minimum of 10
481+ images.
482+ Encode special characters in the file name in UTF-8.
483+ :param str negative_examples_filename: The filename for negative_examples.
480484 :param dict headers: A `dict` containing the request headers
481485 :return: A `DetailedResponse` containing the result, headers and HTTP status code.
482486 :rtype: DetailedResponse
483487 """
484488
485489 if classifier_id is None :
486490 raise ValueError ('classifier_id must be provided' )
487- positive_examples_keys = [
488- key for key in kwargs if re .match ('^.+_positive_examples$' , key )
489- ]
490491
491492 headers = {}
492493 if 'headers' in kwargs :
@@ -497,6 +498,14 @@ def update_classifier(self,
497498 params = {'version' : self .version }
498499
499500 form_data = {}
501+ for key in positive_examples .keys ():
502+ part_name = '%s_positive_examples' % (key )
503+ value = positive_examples [key ]
504+ if positive_examples_filename :
505+ filename = positive_examples_filename .get (key )
506+ if not filename and hasattr (value , 'name' ):
507+ filename = basename (value .name )
508+ form_data [part_name ] = (filename , value , 'application/octet-stream' )
500509 if negative_examples :
501510 if not negative_examples_filename and hasattr (
502511 negative_examples , 'name' ):
@@ -506,12 +515,6 @@ def update_classifier(self,
506515 form_data ['negative_examples' ] = (negative_examples_filename ,
507516 negative_examples ,
508517 'application/octet-stream' )
509- for key in positive_examples_keys :
510- value = kwargs [key ]
511- filename = kwargs .get (key + '_filename' )
512- if not filename and hasattr (value , 'name' ):
513- filename = basename (value .name )
514- form_data [key ] = (filename , value , 'application/octet-stream' )
515518
516519 url = '/v3/classifiers/{0}' .format (
517520 * self ._encode_path_vars (classifier_id ))
0 commit comments