首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google Cloud Server在查询对象本地化时强制关闭

Google Cloud Server在查询对象本地化时强制关闭
EN

Stack Overflow用户
提问于 2020-03-31 13:02:37
回答 1查看 99关注 0票数 0

我有时会收到错误信息

代码语言:javascript
运行
复制
google.api_core.exceptions.ServiceUnavailable: 503 Getting metadata from plugin failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

在运行时

代码语言:javascript
运行
复制
# server/classifiers/gcloud/identifier.py


import io
import os
import json
from google.cloud import vision
from google.cloud.vision import types
from collections import Counter

client = vision.ImageAnnotatorClient()

with io.open("config/labels.json", "r") as f:
    LABELS = json.loads(f.read())


def identify_from_string(blob):
    image = types.Image(content=blob)
    response = client.object_localization(image=image)
    labels = response.localized_object_annotations
    objects = set(label.name for label in labels)

    c = Counter()
    for label, s in LABELS.items():
        for ob in objects:
            if ob in s:
                c[label] += s[ob]

    if not c: print("Sorry, the server is currently full.")
    return str(c)

并在response = client.object_localization(image=image)的行上抛出错误。在我的app.py上,我有

代码语言:javascript
运行
复制
# server/app.py

import os
import json
from server.classifiers.gcloud import identifier
from flask import Flask, Response, render_template, send_file, request

@app.route('/classify', methods=['POST'])
def classify():
    app.logger.info("Got image to /classify")
    file = request.files['image']
    blob = file.read()
    results = identifier.identify_from_string(blob)
    return Response(response=json.dumps(dict(response)), status=200)

其中server.classifiers.gcloud.identifier指向上面的文件。偶尔,这个问题会突然消失。有什么办法可以解决这个问题吗?

EN

Stack Overflow用户

发布于 2020-05-14 04:35:35

看起来你很有可能需要下载服务帐户凭据并导出环境变量和GOOGLE_CLOUD_PROJECT,例如在*nix上:

代码语言:javascript
运行
复制
export GOOGLE_CLOUD_PROJECT=blue-jet-123
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/path/to/service.json

我试图重现这个错误,但是我的flask服务器没有启动,你能指出"config/labels.json“的内容吗?你可以把你的文件夹树形结构,以确保我们有相同的目录结构

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60943745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档