Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.6k stars 2.81k forks source link

Cognitive Services CustomVision: Missing enum type for "batch_read_*" with "mixed" mode #5889

Closed lawrencegripper closed 5 years ago

lawrencegripper commented 5 years ago

The current SDK for Cognitive Services CustomVision service is missing the "Mixed" mode option from the "batchread*" calls.

API Definition

Use this interface to get the result of a Batch Read File operation, employing the state-of-the-art Optical Character Recognition (OCR) algorithms optimized for text-heavy documents. It can handle hand-written, printed or mixed documents.

API definition showing use of "Mixed" mode

Current SDK Enum

The current Enum is missing the option for "Mixed" mode.

https://github.com/Azure/azure-sdk-for-python/blob/815deb24a5051e792c80edfe3d8e1904840135dd/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/azure/cognitiveservices/vision/computervision/models/computer_vision_client_enums.py#L85-L89

Attempted workaround

One way I attempted to workaround this issue was to create a new instance of the Enum with the string value "Mixed", however, this causes a validation error.

    with open(os.path.join(folder, input_image), "rb") as image_stream:
            job = client.batch_read_file_in_stream(
                image=image_stream,
                mode=TextRecognitionMode("Mixed"),
                raw=True
            )

Failure messages

> 2-get-ocr-result.py 
Traceback (most recent call last):
  File "/data/home/lawrence.gripper/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/ptvsd_launcher.py", line 45, in <module>
    main(ptvsdArgs)
  File "/data/home/lawrence.gripper/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/__main__.py", line 391, in main
    run()
  File "/data/home/lawrence.gripper/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/__main__.py", line 272, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/data/anaconda/envs/py35/lib/python3.5/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/data/anaconda/envs/py35/lib/python3.5/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/data/anaconda/envs/py35/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/data/home/lawrence.gripper/source/testharness/dataset-building/2-get-ocr-result.py", line 25, in <module>
    mode=TextRecognitionMode("Mixed"),
  File "/data/anaconda/envs/py35/lib/python3.5/enum.py", line 241, in __call__
    return cls.__new__(cls, value)
  File "/data/anaconda/envs/py35/lib/python3.5/enum.py", line 476, in __new__
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'Mixed' is not a valid TextRecognitionMode
toothache commented 5 years ago

Hi, @lawrencegripper . The mixed enum value is only valid in the preview version of batch_read_* API. Now this API enters public release version and mode parameter is also removed.

To fix the error, you should simply remove mode parameter in your function call.

lawrencegripper commented 5 years ago

So removing the mode= section of my call will result in me getting the Mixed result which is matching against both handwritten and printed text?

Specifically the result I want is the preview mixed mode result.

toothache commented 5 years ago

Yes. You'll get the Mixed result which matches both handwritten and printed text. We've added a component in the public release version which auto detects the text recognition mode.

lmazuel commented 5 years ago

@areddish ?

areddish commented 5 years ago

@lmazuel - Looks like @toothache has provided a solution, I think this can be closed.

lawrencegripper commented 5 years ago

Happy to close this one off, can we confirm that the field will be removed from the SDK? Great to have a workaround but maybe misleading for others too.

toothache commented 5 years ago

@lawrencegripper , yes. we removed the mode parameter with this PR.

https://github.com/Azure/azure-rest-api-specs/pull/5931

lawrencegripper commented 5 years ago

Cool! Thanks.