2016-11-25 77 views
0

我在本地創建了一些自定義分類器,然後嘗試在bluemix上部署基於我創建的分類器對圖像進行分類的應用程序。部署Watson視覺識別應用程序失敗

當我嘗試部署它時,它無法啓動。

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)) 

即使我嘗試部署一個簡單的打印,它failes部署,但啓動應用程序,我從bluemix得到,或瓶教程(https://www.ibm.com/blogs/bluemix/2015/03/simple-hello-world-python-app-using-flask/)我在網上找到的部署就好了。

我對網絡編程和使用雲服務非常陌生,所以我完全迷失了。

謝謝。

+0

你需要排除你的代碼。嘗試在本地運行代碼,看看它是否可行。否則,它更像是一個Bluemix應用程序問題,在這種情況下,您可能需要發佈與錯誤相關的日誌。 –

+0

@ SimonO'Doherty我的代碼在本地運行得很好。當我嘗試部署時,我無法從帖子日誌中獲得任何有用的信息,只是該應用已崩潰。順便說一句,我從平臺內的選項獲取日誌原因cf日誌appname --recent給我一個錯誤。 –

回答

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

+0

我已經嘗試使用--no-route運行,但沒有成功,但是我要按照鏈接中的說明再試一次。謝謝。 –

+0

請注意,「VCAP_APP_PORT」環境變量的使用已被棄用,並且在未來版本的Cloud Foundry中將不起作用,您應該使用「PORT」。 –

+0

謝謝,我將編輯我的示例以反映這一點 –

0

的主要問題的輸出是沃森 - 開發雲模塊,給了我,它找不到一個錯誤。

我降級到python 2.7.12版,爲所有用戶安裝。 修改後的runtime.exe和requirments.txt(requirments.txt可能不需要) 與迭戈一起上演,使用無路線和設置健康檢查APP_NAME無命令。

那些固定的問題,但我仍然得到一個退出狀態0

0

當你部署bluemix的應用程序,你應該有一個requirements.txt,其中包括服務,您需要在應用中使用。 所以,你應該檢出你requirements.txt,也許你失去了

watson_developer_cloud 

,然後,將requirements.txt喜歡這樣的:

Flask==0.10.1 
watson_developer_cloud 
相關問題