Microsoft Cognitive Services Emotion API. Error: 'Image size is too small or too big.'

こ雲淡風輕ζ 提交于 2020-01-04 02:04:12

问题


I have noticed a rather strange error with the Emotion API from the Cognitive Services suite.

Everything works just fine as long as I send it URL's. When sending it image attachments. I receive this JSON error: { error: { code: 'InvalidImageSize', message: 'Image size is too small or too big.' } }

Sending it smaller or larger versions does not help. Send a URL of the same image, and suddenly it works fine again.

I stream the attachment to the API service in the exact same way I do for another Cognitive Services API, namely Computer Vision. And that works great with streamed attachments.

The code is on GitHub: https://github.com/sebsylvester/botbuilder-mcs

I know the APIs are still in preview, but this is still a weird issue.


回答1:


Unfortunately, the Emotion and Face APIs do not support chunked transfers, as noted here. The 'workaround' is to load the image bits synchronously prior to making the web request. The code snippet from that project is thus:

function _postImageSync(url, image, options) {
    return new _Promise(function (resolve, reject) {
        request.post({
            uri: host + rootPath + url,
            headers: {
                'Ocp-Apim-Subscription-Key': key,
                'Content-Type': 'application/octet-stream'
            },
            qs: options,
            body: fs.readFileSync(image)
        }, (error, response) => {
            response.body = JSON.parse(response.body);
            _return(error, response, resolve, reject);
        });
    });
}


来源:https://stackoverflow.com/questions/41806979/microsoft-cognitive-services-emotion-api-error-image-size-is-too-small-or-too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!