如何在Google App Engine灵活环境中运行TensorFlow?

2023-12-30

之前我问为什么GAE在这里找不到TensorFlow libhttps://stackoverflow.com/questions/40241846/why-googleappengine-gives-me-importerror-no-module-named-tensorflow https://stackoverflow.com/questions/40241846/why-googleappengine-gives-me-importerror-no-module-named-tensorflow

And 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"

部署成功,但在访问我的应用程序时出现服务器内部错误appspot控制台仍然向我显示ImportError: No module named tensorflow.

我需要做什么才能使基于 TensorFlow 的应用程序运行flexible enviroment?


为了帮助其他人,我发布了用于谷歌应用程序引擎灵活环境的 hello world 张量流代码,使用Python 3(我知道原来的问题是针对 python 2.7 提出的)。另请注意,webapp2 尚未与 python 3 兼容,因此我使用 Flask。

完整代码是

要求.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 https://github.com/armujahid/appengine-tensorflow-python3

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在Google App Engine灵活环境中运行TensorFlow? 的相关文章

随机推荐

  • 如何在 Aptana Studio 中自动缩进 JavaScript 代码?

    之前我使用Eclipse进行PHP和Java开发 我喜欢这个命令Ctrl i自动缩进代码 现在我使用基于Eclipse的Aptana Studio进行JavaScript开发 我想自动缩进我的 JavaScript 代码 但是Ctrl i删
  • 如何将外部CSS应用到flutter webview中的html渲染

    我想将外部 css 应用到在 flutter webview 中渲染的 html 在 android 中 它是使用以下语法完成的 您可以通过调用以下命令将任何 JavaScript 提交到您的 Web 视图 flutterWebViewPl
  • “System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常

    我正在 MVC 4 aspnet 网站中使用 EF5 在本地 一切正常 但是当我将其发布到 IIS 并尝试进入时 出现错误 System Data Entity Internal AppConfig 的类型初始值设定项 抛出异常 详细异常情
  • 填充div的空间

    我想要一个元素来填充父 div 的剩余空间 我已经成功做到了这一点 您可以在此处看到 链接已删除 但填充 div 右侧 位于左侧 div 下方 我基本上希望右侧的 div 从左侧的 div 结束的地方开始 希望这是有道理的
  • 从 TangoService_connectOnFrameAvailable 保存帧

    如何通过 TangoService connectOnFrameAvailable 保存帧并在我的计算机上正确显示它 作为此参考页 https developers google com project tango apis c struc
  • Angular bootstrap typeahead 不适用于 Angular 1.3.0

    我创建了一个小插件来表明这是行不通的 任何人都可以帮助我如何使用 typeahead 与 1 3 0 angularJS 提供替代解决方案 我们将其与 angular bootstrap 0 11 0 和最新版本的 bootstrap 一起
  • 角度测试在反应式表单上提交事件

    Context 我有一个具有基本形式 反应形式 的组件 我尝试测试此表单上的提交事件 看看它是否正确调用了必要的方法 我的问题 无法触发表单的提交事件 Files 组件 html
  • 如何使用新的 jstree v3.0.0 按需加载子项

    我正在寻找一些帮助在 jstree 中按需 扩展 填充子节点 我可以填充父节点 但无法填充子节点 设想 我正在使用 jstree 来填充树中的节点 我的数据源是json 但是 我从不同的服务获取父节点 从不同的服务获取子节点 我正在使用新的
  • 使用 GPU 加速 MATLAB 代码?

    AccelerEyes 于 2012 年 12 月宣布与 Mathworks 合作开发 GPU 代码 并已停止生产 Jacket for MATLAB http blog accelereyes com blog 2012 12 12 ex
  • 构建maven项目时编译错误

    我们正在尝试从 Jenkins 构建并部署一个 Maven 工件到我们的 Nexus 存储库管理器中 但我们在构建过程中遇到了编译错误 这是我们收到的错误 错误 未能执行目标 org apache maven plugins maven c
  • 如何在 Chrome 上调试 JavaScript

    我有一个奇怪的问题 jquery load 有时在 chrome 上失败 我不会用细节来打扰你们 我只是在寻找如何调试这样的问题的指导者 我想也许 firebug 可以提供帮助 但问题只发生在 chrome 上 甚至适用于 IE 我做类似的
  • 使用 XMLHttpRequest 上传文件

    我正在尝试使用拖放插件 http pascalprecht github com DnD js 在javascript中使用ajax上传文件
  • 从 HTML 表单到 PDF

    有没有一种简单的方法可以在网页上创建 HTML 表单 当用户提交时 将数据放入 PDF 文件并将其发送给接收者 该网页在 net 上运行 Thanks Umbraco http our umbraco org projects websit
  • 如何使用 C# 或 XAML 创建自动动画轮播循环图像?

    我已经在 Web 开发中完成了轮播 但通过 XAML 或 C 在 WPF 中为它们设置动画对我来说是新鲜事 网上有一些例子 但它们要么已经过时 要么不是我想要的 即使当我玩弄其他项目的源代码时 这也不是我所希望的 我想让图像自动从左到右 水
  • Android webview中的无限滚动

    我有一些本地 html 文件 我想用无限滚动方法显示它们 NOTE 我无法更改 html 内容 所以请不要建议向其中添加 javascript 我必须在运行时执行此操作 所以 我发现我可以执行javascript在运行时通过loadUrl
  • 生成的 pdf 中的文本是反向的

    我正在使用 pdfbox 向 pdf 文件添加一行 但我添加的文字是相反的 File file new File filePath PDDocument document PDDocument load file PDPage page d
  • 如何从 Magento-1 价格中删除小数点?

    我在搜索中找到的只是一个编程解决方案 我知道我们可以修改 lib Zend Locale Data en xml 以用于英语商店 en xml中有这部分
  • 我们可以在每个 上方的 table 内添加 div 吗?

    您好 我正在尝试在每个上面添加一个 div tr 但是当我查看 html 控制台时 div 显示在表格之外 下面是html代码 table div tr td td tr div div tr td td tr div table 这是不允
  • 计算方法的执行时间

    可能的重复 如何测量函数运行的时间 https stackoverflow com questions 10107140 how to measure how long is a function running 我有一个 I O 计时方法
  • 如何在Google App Engine灵活环境中运行TensorFlow?

    之前我问为什么GAE在这里找不到TensorFlow libhttps stackoverflow com questions 40241846 why googleappengine gives me importerror no mod