Skip to content

Commit 663bff4

Browse files
committed
Revert back for create_classifier and update_classifier
1 parent 4caa81a commit 663bff4

3 files changed

Lines changed: 29 additions & 108 deletions

File tree

test/integration/test_integration_visual_recognition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_detect_faces(self):
2828
def test_custom_classifier(self):
2929
with open(os.path.join(os.path.dirname(__file__), '../../resources/cars.zip'), 'rb') as cars, \
3030
open(os.path.join(os.path.dirname(__file__), '../../resources/trucks.zip'), 'rb') as trucks:
31-
classifier = self.visual_recognition.create_classifier('Cars vs Trucks', classname_positive_examples=cars, negative_examples=trucks)
31+
classifier = self.visual_recognition.create_classifier('Cars vs Trucks', cars_positive_examples=cars, negative_examples=trucks)
3232

3333
assert classifier is not None
3434

test/unit/test_visual_recognition_v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_create_classifier(self):
9898

9999
with open(os.path.join(os.path.dirname(__file__), '../../resources/cars.zip'), 'rb') as cars, \
100100
open(os.path.join(os.path.dirname(__file__), '../../resources/trucks.zip'), 'rb') as trucks:
101-
vr_service.create_classifier('Cars vs Trucks', classname_positive_examples=cars, negative_examples=trucks)
101+
vr_service.create_classifier('Cars vs Trucks', cars_positive_examples=cars, negative_examples=trucks)
102102

103103
assert len(responses.calls) == 1
104104

watson_developer_cloud/visual_recognition_v3.py

Lines changed: 27 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -172,65 +172,29 @@ def detect_faces(self,
172172
#########################
173173

174174
def create_classifier(self,
175-
name,
176-
classname_positive_examples,
177-
negative_examples=None,
178-
classname_positive_examples_filename=None,
179-
negative_examples_filename=None):
180-
"""
181-
Create a classifier.
182-
183-
Train a new multi-faceted classifier on the uploaded image data. Create your
184-
custom classifier with positive or negative examples. Include at least two sets of
185-
examples, either two positive example files or one positive and one negative file.
186-
You can upload a maximum of 256 MB per call. Encode all names in UTF-8 if they
187-
contain non-ASCII characters (.zip and image file names, and classifier and class
188-
names). The service assumes UTF-8 encoding if it encounters non-ASCII characters.
189-
190-
:param str name: The name of the new classifier. Encode special characters in UTF-8.
191-
:param file classname_positive_examples: A .zip file of images that depict the visual subject of a class in the new classifier. You can include more than one positive example file in a call. Append `_positive_examples` to the form name. The prefix is used as the class name. For example, `goldenretriever_positive_examples` creates the class **goldenretriever**. Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8. The API explorer limits you to training only one class. To train more classes, use the API functionality.
192-
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
193-
:param str classname_positive_examples_filename: The filename for classname_positive_examples.
194-
:param str negative_examples_filename: The filename for negative_examples.
195-
:return: A `dict` containing the `Classifier` response.
196-
:rtype: dict
197-
"""
198-
if name is None:
199-
raise ValueError('name must be provided')
200-
if classname_positive_examples is None:
201-
raise ValueError('classname_positive_examples must be provided')
202-
params = {'version': self.version}
203-
name_tuple = (None, name, 'text/plain')
204-
if not classname_positive_examples_filename and hasattr(
205-
classname_positive_examples, 'name'):
206-
classname_positive_examples_filename = classname_positive_examples.name
207-
mime_type = 'application/octet-stream'
208-
classname_positive_examples_tuple = (
209-
classname_positive_examples_filename, classname_positive_examples,
210-
mime_type)
211-
negative_examples_tuple = None
212-
if negative_examples:
213-
if not negative_examples_filename and hasattr(
214-
negative_examples, 'name'):
215-
negative_examples_filename = negative_examples.name
216-
if not negative_examples_filename:
217-
raise ValueError('negative_examples_filename must be provided')
218-
mime_type = 'application/octet-stream'
219-
negative_examples_tuple = (negative_examples_filename,
220-
negative_examples, mime_type)
221-
url = '/v3/classifiers'
222-
response = self.request(
223-
method='POST',
224-
url=url,
225-
params=params,
226-
files={
227-
'name': name_tuple,
228-
'classname_positive_examples':
229-
classname_positive_examples_tuple,
230-
'negative_examples': negative_examples_tuple
231-
},
232-
accept_json=True)
233-
return response
175+
name,
176+
**kwargs):
177+
"""
178+
Create a classifier.
179+
:param str name: The name of the new classifier. Cannot contain special characters.
180+
:param file <NAME>_positive_examples: A compressed (.zip) file of images that depict the visual subject for a class within the new classifier. Must contain a minimum of 10 images. The swagger limits you to training only one class. To train more classes, use the API functionality.
181+
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images.
182+
:return: A `dict` containing the `Classifier` response.
183+
:rtype: dict
184+
"""
185+
if name is None:
186+
raise ValueError('name must be provided')
187+
params = {'version': self.version}
188+
data = {'name': name}
189+
url = '/v3/classifiers'
190+
response = self.request(
191+
method='POST',
192+
url=url,
193+
params=params,
194+
data=data,
195+
files=kwargs,
196+
accept_json=True)
197+
return response
234198

235199
def delete_classifier(self, classifier_id):
236200
"""
@@ -280,68 +244,25 @@ def list_classifiers(self, verbose=None):
280244

281245
def update_classifier(self,
282246
classifier_id,
283-
classname_positive_examples=None,
284-
negative_examples=None,
285-
classname_positive_examples_filename=None,
286-
negative_examples_filename=None):
247+
**kwargs):
287248
"""
288249
Update a classifier.
289-
290-
Update a custom classifier by adding new positive or negative classes (examples)
291-
or by adding new images to existing classes. You must supply at least one set of
292-
positive or negative examples. For details, see [Updating custom
293-
classifiers](https://console.bluemix.net/docs/services/visual-recognition/customizing.html#updating-custom-classifiers).
294-
Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image
295-
file names, and classifier and class names). The service assumes UTF-8 encoding if
296-
it encounters non-ASCII characters. **Important:** You can't update a custom
297-
classifier with an API key for a Lite plan. To update a custom classifer on a Lite
298-
plan, create another service instance on a Standard plan and re-create your custom
299-
classifier. **Tip:** Don't make retraining calls on a classifier until the status
300-
is ready. When you submit retraining requests in parallel, the last request
301-
overwrites the previous requests. The retrained property shows the last time the
302-
classifier retraining finished.
303-
304250
:param str classifier_id: The ID of the classifier.
305-
:param file classname_positive_examples: A .zip file of images that depict the visual subject of a class in the classifier. The positive examples create or update classes in the classifier. You can include more than one positive example file in a call. Append `_positive_examples` to the form name. The prefix is used to name the class. For example, `goldenretriever_positive_examples` creates the class `goldenretriever`. Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8.
306-
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
307-
:param str classname_positive_examples_filename: The filename for classname_positive_examples.
308-
:param str negative_examples_filename: The filename for negative_examples.
251+
:param file <NAME>_positive_examples: A compressed (.zip) file of images that depict the visual subject for a class within the classifier. Must contain a minimum of 10 images.
252+
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images.
309253
:return: A `dict` containing the `Classifier` response.
310254
:rtype: dict
311255
"""
312256
if classifier_id is None:
313257
raise ValueError('classifier_id must be provided')
314258
params = {'version': self.version}
315-
classname_positive_examples_tuple = None
316-
if classname_positive_examples:
317-
if not classname_positive_examples_filename and hasattr(
318-
classname_positive_examples, 'name'):
319-
classname_positive_examples_filename = classname_positive_examples.name
320-
mime_type = 'application/octet-stream'
321-
classname_positive_examples_tuple = (
322-
classname_positive_examples_filename,
323-
classname_positive_examples, mime_type)
324-
negative_examples_tuple = None
325-
if negative_examples:
326-
if not negative_examples_filename and hasattr(
327-
negative_examples, 'name'):
328-
negative_examples_filename = negative_examples.name
329-
if not negative_examples_filename:
330-
raise ValueError('negative_examples_filename must be provided')
331-
mime_type = 'application/octet-stream'
332-
negative_examples_tuple = (negative_examples_filename,
333-
negative_examples, mime_type)
334259
url = '/v3/classifiers/{0}'.format(
335260
*self._encode_path_vars(classifier_id))
336261
response = self.request(
337262
method='POST',
338263
url=url,
339264
params=params,
340-
files={
341-
'classname_positive_examples':
342-
classname_positive_examples_tuple,
343-
'negative_examples': negative_examples_tuple
344-
},
265+
files=kwargs,
345266
accept_json=True)
346267
return response
347268

0 commit comments

Comments
 (0)