部署Watson Visual识别应用程序失败

时间:2016-11-25 14:19:10

标签: python ibm-cloud watson visual-recognition

我在本地创建了一些自定义分类器,然后我尝试在bluemix上部署一个应用程序,该应用程序根据我制作的分类器对图像进行分类。

当我尝试部署它时,它很难开始。

import os
import json
from os.path import join, dirname
from os import environ
from watson_developer_cloud import VisualRecognitionV3 
import time
start_time = time.time()

visual_recognition = VisualRecognitionV3(VisualRecognitionV3.latest_version, api_key='*************')

with open(join(dirname(__file__), './test170.jpg'), 'rb') as image_file:
 print(json.dumps(visual_recognition.classify(images_file=image_file,threshold=0, classifier_ids=['Angle_971786581']), indent=2))

print("--- %s seconds ---" % (time.time() - start_time))

即使我尝试部署一个简单的打印,它也很容易部署,但是我从bluemix或Flask教程(https://www.ibm.com/blogs/bluemix/2015/03/simple-hello-world-python-app-using-flask/)获得的入门应用程序我发现在线部署就好了。

我对网络编程和使用云服务都很陌生,所以我完全迷失了。

谢谢。

3 个答案:

答案 0 :(得分:3)

Bluemix期待你的python应用程序在端口上提供服务。如果您的应用程序未在端口上提供某种响应,则会假定应用程序无法启动。

# On Bluemix, get the port number from the environment variable PORT
# When running this app on the local machine, default the port to 8080
port = int(os.getenv('PORT', 8080))


@app.route('/')
def hello_world():
    return 'Hello World! I am running on port ' + str(port)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=port)

看起来你正在编写代码只执行一次并停止。相反,当有人点击你的URL时,让它完成工作,如上面的hello_world()函数所示。

想想当有人去YOUR_APP_NAME.mybluemix.net时你想要发生什么

如果您不希望您的应用程序成为WEB应用程序,而是只执行一次(后台工作程序应用程序),则在cf push命令的末尾使用--no-route选项。然后,使用cf logs appname --recent查看日志以查看应用程序的输出

https://console.ng.bluemix.net/docs/manageapps/depapps.html#deployingapps

答案 1 :(得分:0)

主要问题是watson-developer-cloud模块,给我一个无法找到的错误。

我降级到python版本2.7.12,为所有用户安装它。 修改了runtime.exe和requirments.txt(可能不需要requirments.txt) 与Diego一起使用no-route和set-health-check APP_NAME none命令。

那些解决了问题,但我仍然得到退出状态0。

答案 2 :(得分:0)

在bluemix中部署应用时,您应该有一个requirements.txt,其中包含您在应用中使用的服务。 所以,你应该检查你的要求.txt,也许你输了

watson_developer_cloud

然后,requirements.txt喜欢这个:

Flask==0.10.1
watson_developer_cloud
相关问题