0
votes

I'm trying to create a new class with the API like it's shown in the API Documentation https://cloud.ibm.com/apidocs/visual-recognition?code=python#update-a-classifier

The part that Watson uses as the name of the class is the prefix of "_positive_examples". I need to use the content of a variable as the prefix, but it's a keyword and I can't add any variable there (variableNotWorking in the code).

I have tried to format as a string and also to create a dictionary in Python and introduce it there but I always obtain an error either from Python or Watson.

    positive = nuevaClase + '_positive_examples'
    visual_recognition = credencials()
    with open(aprDirFitxer1, 'rb') as nuevaClase:
            updated_model = visual_recognition.update_classifier(
                classifier_id=classifId,
                positive_examples={positive : nuevaClase}).get_result()

The error from Watson that I always obtain is:

watson_developer_cloud.watson_service.WatsonApiException: Error: Cannot execute learning task.  Did not find any files to process in the POST request body. , Code: 400 
1
Which version of the Watson Python SDK are you using? A new version was released recently that uses a different format to specify the classifiers so it's important to know which version you are using. - Mike Kistler
The version is VisualRecognitionV3 - David
I updated it to the new format but I always obtain the same response: watson_developer_cloud.watson_service.WatsonApiException: Error: Cannot execute learning task. Did not find any files to process in the POST request body. , Code: 400 - David

1 Answers

0
votes

I think your problem may be that you are using an old version of the SDK because the package name changed in Version 3 to "ibm-watson". You need to install the new SDK package with

pip install --upgrade ibm-watson

and then in your Python code, import from this new package:

from ibm_watson import VisualRecognitionV3