首页 > 解决方案 > Tensorflow 应用程序不再部署到 Heroku:Slug 尺寸太大

问题描述

我有许多 Heroku 应用程序,直到最近我才能够无缝地更新它们。它们使用 tensorflow 和 streamlit,并且在部署时都发出类似的消息:

-----> Compressing...
remote:  !     Compiled slug size: 560.2M is too large (max is 500M).
remote:  !     See: http://devcenter.heroku.com/articles/slug-size
remote:
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 5c0f686a86459f6e81627ce14770f7494f4bd244
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 5c0f686a86459f6e81627ce14770f7494f4bd244
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to dry-caverns-08193.
remote:
To https://git.heroku.com/dry-caverns-08193.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dry-caverns-08193.git'

我知道它说蛞蝓尺寸太大,但他们之前运行过相同的消息,所以我不确定这就是问题所在。

这是我的文件设置:

app.py
Procfile
requirements.txt
setup.sh
my_model/
  -- assets/
  -- variables/
       -- variables.index
       -- variables.data-00000-of-000001
  saved_model.pb

requirements.txt内容如下:

tensorflow==2.*
streamlit==0.67.0
requests==2.24.0
requests-oauthlib==1.3.0

setup.sh内容如下:

mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"myemail@gmail.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml

我的直接怀疑是 tensorflow 导致 slug 尺寸太大——但它以前也可以使用 tensorflow,所以我不确定为什么它现在不起作用。

还有什么可能吗?

编辑:

看完这个问题后: Heroku:如果您正在分支上开发并通过 git 进行部署,您必须运行: 我尝试过git push heroku master:main,但这不适用于日志中的以下显示:

Push rejected to dry-caverns-08193.
remote:
To https://git.heroku.com/dry-caverns-08193.git
 ! [remote rejected] master -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dry-caverns-08193.git'

标签: tensorflowherokustreamlit

解决方案


如果您使用的是免费测功机:

在 中进行更改requirements.txt

tensorflow-cpu

代替

tensorflow

这将大大减少你的蛞蝓大小

此外,您的问题也可能取决于模型重量大小

另一个提示:

如果您直接从 GitHub 拉取代码,请使用“.slugignore”文件,这样您就可以忽略 README 到 GitHub Actions 到笔记本等任何内容,以免被添加到您的 Dyno


推荐阅读