ã¯ããã«
Herokuã§OpenCVãæ±ãããå ´åãå¾æ¥ã¯Dockerfileãç¨æãã¦ãããã¤ããå¿ è¦ãããã¾ããããheroku.ymlã®ç»å ´ã«ãããããæ軽ã«ãããã¤ã§ããããã«ãªãã¾ããã®ã§ç´¹ä»ãã¾ãã
ç°å¢
OpenCVã使ããªãå ´åã®Python Flask ã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤
Herokuã¯ãGitHubã®ããã«ãHerokuä¸ã®ãªãã¸ããªã«ã½ã¼ã¹ã³ã¼ããPushããã¨èªåçã«ãã«ããã¦Webã¢ããªã±ã¼ã·ã§ã³ãå ¬éãã¦ããã¾ãã
ä»åã¯Pythonã®Flaskã¨ããWebãã¬ã¼ã ã¯ã¼ã¯ãå©ç¨ãã¦Webãµã¼ãã¹ãå ¬éãããã¨æã£ã¦ãã¾ããã¾ãã¯OpenCVã使ããªãå ´åãèãã¾ããFlaskã®ã¢ããªã±ã¼ã·ã§ã³ããããã¤ããå ´åããªãã¸ããªã®rootã«ä»¥ä¸ã®3ã¤ã®ãã¡ã¤ã«ãå¿ è¦ã§ãã
- runtime.txt
- requirements.txt
- Procfile
ã¾ã以ä¸ã®3ã¤ã®ãã¡ã¤ã«ä»¥å¤ã«å½ç¶ã¢ããªã±ã¼ã·ã§ã³ã®ã³ã¼ããå¿ è¦ã§ããé ã«ç°¡åã«èª¬æãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ã
ã¾ãã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãï¼Flaskï¼ã®æ¬ä½ã¨ã㦠main.py
ãç¨æãã¾ããä»åã¯åãã·ã³ãã«ãªãã®ãç¨æãã¾ããã
# -*- coding: utf-8 -*- import os from flask import Flask @app.route("/") def index(): return "Hello Flask" if __name__ == "__main__": port = int(os.environ.get("PORT", 5000)) app.run(port=port, debug=True)
Herokuã§ã¢ããªã±ã¼ã·ã§ã³ãåããå ´åã¯ãã·ã§ã«ã®ç°å¢å¤æ°ã§æå®ããããã¼ãã§åããå¿ è¦ãããã¾ãã®ã§ããªãããã®æ¹æ³ã§ãã¼ãçªå·ãPythonã«æ¸¡ãã¦ããå¿ è¦ãããã¾ããä»åã¯Pythonã®ã³ã¼ãä¸ã§ã·ã§ã«ã®ç°å¢å¤æ°ãããã¼ãçªå·ãåã£ã¦ããããã«ãã¦ãã¾ãã
runtime.txt
runtime.txt ã®ä¸èº«ã¯ä»¥ä¸ã®éãã§ãã
python-2.7.14
ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã®å®è¡ç°å¢ãæ¸ãã ãã§ãã
requirements.txt
Pythonã®å ´åå¿ è¦ãªãã¤ã§ããpipã§ã¤ã³ã¹ãã¼ã«ãããã¤ãæ¸ãã¾ãã
Flask==0.10.1 gunicorn==19.7.0
ããããæãã§ã
Procfile
Webã¢ããªã±ã¼ã·ã§ã³ã®èµ·åæ¹æ³ãæ¸ãã¾ããä»åã¯ããããæãã«ãªãã¾ãã
web: gunicorn app:app --log-file=-
ãããã¤
ãããã®ãã¡ã¤ã«ãé ç½®ãã¾ãã
$ ls app.py Procfile runtime.txt requirements.txt
git remoteã«herokuã追å ããã¦ãããã¨ã確èªãã¦pushï¼herokuã®è¿½å æ¹æ³ã¯ããã§ã¯çç¥ï¼ã
$ git remote -v heroku https://git.heroku.com/xxxxx.git (fetch) heroku https://git.heroku.com/xxxxx.git (push) $ git push heroku master
ãã㧠xxxx.herokuapp.com ã«ã¢ã¯ã»ã¹ãã㨠Hellow Flask ãåãã¯ãã§ãã
ãã®ã¾ã¾ã ã¨OpenCVã使ããªã
ãã®ã¾ã¾ã ã¨opencvã¯ä½¿ãã¾ãããpython-opencvèªä½ã¯requirements.txt
ã«è¿½å ããã°å©ç¨ã§ããããã«ãªãã®ã§ãããopencvæ¬ä½ãherokuå´ã«ã¤ã³ã¹ãã¼ã«ããã¦ããªãã®ã§åããªãã®ã§ãã
Flask==0.10.1 gunicorn==19.7.0 numpy==1.13.1 opencv-python==3.3.0.10
ã§ã¯ã©ããããããã®ã§ããããã
å¾æ¥ã¯Dockerã使ã£ã¦ãããã¤ãã¦ãã¾ããã
å¾æ¥ã¯Dockerã使ã£ã¦ãããã¤ãã¦ãã¾ããã
ãããDockerã¯è§¦ãããã¨ããªã人ã«ã¯ãªããªãé£è§£ã§ãããã¨ãã«herokuã®Dockerãããã¤ã¯ããªãé£è§£ã§ãããåã¯çµå±Dockerã使ã£ã¦ã®ãããã¤æ¹æ³ãåãããæãã¾ããã
Dockerã®å¤ããã«heroku.yml ã使ãã
å®ã¯ãheroku.yml
ãæ¸ãã¨ãDockerãå©ç¨ããªãã¦ããopencvãã¤ã³ã¹ãã¼ã«ããã¦ããç°å¢ãç°¡åã«herokuä¸ã«ç¨æã§ãããã¨ããããã¾ããã
heroku.yml ã¨ã¯
å ¬å¼ã®è§£èª¬ã¯ãã¡ãã§ãã
å ¬å¼ã®ãµã³ãã«ã¯ãã®ããã«ãªã£ã¦ãã¾ãã
build: languages: - ruby packages: - imagemagick run: web: bundle exec puma -C config/puma.rb
heroku.ymlã§OpenCVãåãherokuç°å¢ãæ§ç¯ãã
å
¬å¼ã®è§£èª¬ãèªãã¨ãProcfile
ã®ãããã«heroku.yml
ãç¨æããã¨æ¸ãã¦ããã¾ãããããã§ãherokuã§Python2 + OpenCVãåããã«ã¯ãããã¾ãã
build: languages: - python packages: - libopencv-dev run: web: gunicorn app:app --log-file=-
packages
ã®ã¨ããã«linopencv-dev
ãæ¸ãã¨ããããã¤æã«apt-get install
ã§OpenCVãã¤ã³ã¹ãã¼ã«ããã¾ããããã§OpenCVã使ããããã«ãªãã¾ããDockerfileããããã£ã¨ç°¡åã§ãããã
Procfile
ã®ä¸èº«ã¯heroku.yml
ã®run
ã®æã«æ¸ãã¦ããã¾ãã®ã§ãããã§Procfile
ã¯å¿
è¦ãªããªãã¾ãããruntime.txt
ã¨requirements.txt
ã¯å¿
è¦ãªã®ã§æ³¨æãã¦ãã ãããã¾ããProcfile
ã¨heroku.yml
ã両æ¹åå¨ããå ´åãheroku.yml
ãåªå
ãããã®ã§ãä¸æ¦Procfile
ã¯æ¶ããã«æ¾ç½®ãã¦ããã¦ãæ§ãã¾ããã
ãããã¤æ¹æ³ã¯ãheroku.yml
ããªãã¸ããªã®ã«ã¼ããã£ã¬ã¯ããªã«ç½®ãã¦pushããã ãã§ããä»åã¯ã¨ããããProcfileã¯ãã®ã¾ã¾ãããã¤ãã¾ããã
$ ls app.py heroku.yml Procfile runtime.txt requirements.txt $ git add heroku.yml $ git commit $ git remote -v heroku https://git.heroku.com/xxxxx.git (fetch) heroku https://git.heroku.com/xxxxx.git (push) $ git push heroku master
pushããã¨ãruntime.txt
ãå
ã«python2ãã¤ã³ã¹ãã¼ã«ãããheroku.xml
ãå
ã«packages
ãã¤ã³ã¹ãã¼ã«ãããrequirements.txt
ã解決ãããããã§ã¢ããªã±ã¼ã·ã§ã³ãèµ·åãã¾ããããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ãªã©ãæã¾ãã®ã§ãããã¤æéã¯çµæ§é·ããªã£ã¦ãã¾ãã®ã§ãããDockerfileãããæç¶ãæ軽ã§ãã
OpenCV以å¤ãheroku.yml
ã§ã¤ã³ã¹ãã¼ã«ã§ããããã±ã¼ã¸ã¯å¤æ°ããã¨æãã®ã§æ¯éãããã¦ã¿ã¦ãã ããã
ã¾ã¨ã
ã¾ã developer previewçã§ãããheroku.yml
ã使ããDockerã使ããã¨ãªãherokuä¸ã«OpenCVç°å¢ãæ´ããæ¹æ³ãç´¹ä»ãã¾ãããããªããã£ããã§ãæ¬å½ã¯ã¡ããã¨ãªãã¸ããªã¨ãå
¬éã§ããã¨è¯ãã®ã§ãããåãã¾ã ã¡ãã£ã¨è©¦ããã°ãããªã®ã§å
¬éã§ãããããªãã®ãããã¾ããï¼ï¼ãããæ¼ããªã©ããã¾ããããææé ããã°ã¨æãã¾ããï¼å
¬å¼ã®ããã¥ã¡ã³ãã¿ãã¨ã¾ã Python対å¿ãã¦ãªãããã§ãããããããDockerã³ã³ããã®pushã¨ããå¿
è¦ï¼ï¼
Herokuã¯è¦æ¨¡å°ããªã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤ã§ããã°ç¡æã§ä½¿ãã¾ãã®ã§ããã²æ´»ç¨ãã¦ã¿ã¦ãã ããã
詳解 OpenCV âã³ã³ãã¥ã¼ã¿ãã¸ã§ã³ã©ã¤ãã©ãªã使ã£ãç»åå¦çã»èªè
- ä½è : Gary Bradski,Adrian Kaehler,æ¾ç°æä¸
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2009/08/24
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 17人 ã¯ãªãã¯: 272å
- ãã®ååãå«ãããã° (35件) ãè¦ã
- ä½è : ç¸æ¾¤æ©,arton,é³¥äºéª,ç¹ç°æ¬å
- åºç社/ã¡ã¼ã«ã¼: KADOKAWA/ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹
- çºå£²æ¥: 2014/09/19
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (3件) ãè¦ã