2016-10-28 5 views
2

Прежде чем я спросил, почему GAE не может найти TensorFlow LIB здесь https://stackoverflow.com/questions/40241846/why-googleappengine-gives-me-importerror-no-module-named-tensorflowКак запустить TensorFlow в гибком окружении Google App Engine?

И Dmytro Sadovnychyi сказал мне, что GAE не может работать TensorFlow, но GAE гибкой может.

Так что я создал свой проект в США зоне и пытается развернуть мой простой проект:

import webapp2 
import tensorflow as tf 

class MainHandler(webapp2.RequestHandler): 
    def get(self): 
     hello = tf.constant('Hello, TensorFlow!') 
     sess = tf.Session() 
     self.response.write(sess.run(hello)) 
     a = tf.constant(10) 
     b = tf.constant(32) 
     self.response.write(sess.run(a + b)) 
     #self.response.write('asd'); 


app = webapp2.WSGIApplication([ 
    ('/', MainHandler) 
], debug=True) 

WITN vm: true в YAML.

Это YAML:

application: tstmchnlrn 
version: 1 
runtime: python27 
vm: true 
api_version: 1 
threadsafe: yes 

handlers: 
- url: /favicon\.ico 
    static_files: favicon.ico 
    upload: favicon\.ico 

- url: .* 
    script: main.app 

libraries: 
- name: webapp2 
    version: "2.5.2" 

Deploy успехи, но я получаю сервера Внутренняя ошибка при посещении моего приложения на appspot и консоли все еще показывает мне ImportError: No module named tensorflow.

Что мне нужно сделать, чтобы приложение на основе TensorFlow запускалось в flexible enviroment?

ответ

2

Это похоже на то, что зависимость не попала в экземпляр.

Создайте файл requirements.txt и list your dependencies, включая Tensor Flow.

+0

так, я создал requirements.txt файл и помещается вместе с моей '' yaml' и py' файлов. Содержимое - это просто ссылка: 'https: // storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl'. После развертывания этого проекта и повторного тестирования у меня все еще была такая же ошибка, что и модуль TensorFlow не найден. Нужно ли мне делать что-то еще особенное, чтобы заставить VM устанавливать TensorFlow? Я развертываю проект через PyCharm. – Kosmos

+0

Ссылка на хранилище - 404. Должно ли это быть общедоступным? – BrettJ

+0

Я не знаю ... но эта команда отлично работает с консолью: «Metafalica @ DESKTOP-MC1D431: ~ $ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11 .0rc1-cp27-none-linux_x86_64.whl Загрузка/распаковка https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl Загрузка tensorflow-0.11.0rc1 -cp27-none-linux_x86_64.whl (39.8MB): 97% 39.0MB' – Kosmos

1

Чтобы помочь кому-либо еще, я размещаю свой код потока тензоров мира приветствия для гибкой среды с движком Google, используя Python 3 (Я знаю, что исходный вопрос был задан для python 2.7). Также обратите внимание, что webapp2 еще не совместим с python 3, поэтому я использую Flask.

Полный код

requirements.txt

Flask==0.12.2 
gunicorn==19.7.1 
tensorflow==1.3.0 

app.yaml

runtime: python 
threadsafe: yes 
env: flex 
entrypoint: gunicorn -b :$PORT main:app 

runtime_config: 
    python_version: 3 

main.py

# Copyright 2015 Google Inc. All Rights Reserved. 
# 
# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 
# 
#  http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 

# [START app] 
import logging 
import platform 
import tensorflow as tf 

from flask import Flask 


app = Flask(__name__) 


@app.route('/') 
def hello(): 
    """Return a friendly HTTP greeting.""" 
    # Simple hello world using TensorFlow 

    # Create a Constant op 
    # The op is added as a node to the default graph. 
    # 
    # The value returned by the constructor represents the output 
    # of the Constant op. 
    hello = tf.constant('Hello, TensorFlow!') 

    # Start tf session 
    sess = tf.Session() 

    return sess.run(hello).decode()+' Python '+ platform.python_version() 


@app.errorhandler(500) 
def server_error(e): 
    logging.exception('An error occurred during a request.') 
    return """ 
    An internal error occurred: <pre>{}</pre> 
    See logs for full stacktrace. 
    """.format(e), 500 


if __name__ == '__main__': 
    # This is used when running locally. Gunicorn is used to run the 
    # application on Google App Engine. See entrypoint in app.yaml. 
    app.run(host='127.0.0.1', port=8080, debug=True) 
# [END app] 

Этот же код также размещается на GitHub here

Смежные вопросы