0

I am a beginner in using Watson Visual Recognition and am trying to create a custom classifier to classify dog images. However, when trying to create my classifier as shown in the code snippet below, I get an error.

with open ('beagle.zip','rb') as beagles,open ('golden-retriever.zip','rb') as golden_retrievers,open `('husky.zip','rb') as huskies:`
       classifier = visrec.create_classifier(name = 'dog_classifier',positive_examples =     `{'beagles':beagles,'golden_retrievers':golden_retrievers,'huskies': 'huskies'})`

Here is the error:

    classifier = visrec.create_classifier(name = 'dog_classifier',positive_examples = {'beagles':beagles,'golden_retrievers':golden_retrievers,'huskies': 'huskies'})
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_watson/visual_recognition_v3.py", line 282, in create_classifier
    response = self.send(request)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_cloud_sdk_core/base_service.py", line 302, in send
    raise ApiException(response.status_code, http_response=response)
ibm_cloud_sdk_core.api_exception.ApiException: Error: <HTML><HEAD>
<TITLE>Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error - Write</H1>
The server encountered an internal error or misconfiguration and was unable to
complete your request.<P>
Reference&#32;&#35;4&#46;9436d517&#46;1617113574&#46;3744472
</BODY></HTML>
, Code: 503

How can I fix this?

Madel
  • 3
  • 3

1 Answers1

0

503 indicates that the service is unavailable. If could have been down when you were trying to hit it.

Current status shows it is up - https://cloud.ibm.com/status

Are you still getting the same error?

Sample code from the API documentation (https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v3?code=python#createclassifier) is

import json
from ibm_watson import VisualRecognitionV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
visual_recognition = VisualRecognitionV3(
    version='2018-03-19',
    authenticator=authenticator
)

visual_recognition.set_service_url('{url}')

with open('./beagle.zip', 'rb') as beagle, open(
        './golden-retriever.zip', 'rb') as goldenretriever, open(
            './husky.zip', 'rb') as husky, open(
                './cats.zip', 'rb') as cats:
    model = visual_recognition.create_classifier(
        'dogs',
        positive_examples={'beagle': beagle, 'goldenretriever': goldenretriever, 'husky': husky},
        negative_examples=cats).get_result()
print(json.dumps(model, indent=2))

Make sure that you have the set the service url correctly. The endpoint should match the region in which you have created your visual recognition service. You can verify what the url should be, as it will be available in the same place you get your API key from.

Thinking about this as I wrote the previous paragraph, I realise that as you are new to Watson Visual Recognition, you may not have created an instance of the service or generated an API key. As the service has been deprecated, you may not be able to do so. If this is the case, then I am afraid you won't be able to make use of the service.

chughts
  • 4,210
  • 2
  • 14
  • 27
  • Yes, I tried again after a couple of hours and once again now but it still doesn't work. Does the error then have nothing to do with my code? – Madel Mar 31 '21 at 10:44
  • If you are still getting a 503 then it is more likely an error in your code. As you are not getting an authentication error, it is likely that the endpoint you are using is wrong. Check that you are passing in the correct endpoint url. Full working code from the API documentation is in my answer. – chughts Mar 31 '21 at 11:01
  • No, I do have an API key and the url, its just that my code was missing the set_service_url line. Problem solved, thank you! – Madel Mar 31 '21 at 11:15