【目次】
手順の要点: Python 3.6, TensorFlow 1.15, Python の隔離された環境(Windows では C:\venv\tf115py36)
ソフトウエア等の利用条件等は,利用者で確認すること.
【サイト内の関連ページ】:
謝辞:ソフトウエアの作者に感謝します
TensorFlow 1.15 を使う.
「Visual Studio Community 2019 vesion 16.2, マイクロソフト C++ ビルドツールのインストール(Windows 上)」で説明している.
すでに TensorFlow 2 を使っている,あるいは使う予定ということがありえる. 単純には,TensorFlow 2 と TensorFlow 1.15 を共存させて Python で使うということはできないが, 少しの手間で,共存できるようになる. そこで,TensorFlow 2 とTensorFlow 1.15 の共存を前提として, TensorFlow 1.15 のインストールを行う.
【Python 開発環境のインストール】
Python を使うときは,Python開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter など)の利用も便利である
Windows, Ubuntu での Python 開発環境,Python コンソール(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, spyder)のインストール: 別ページで,インストール手順を説明している.
Windows でのPython3.6,TensorFlow 1.15 のインストール:別ページで説明している.
すでにPython 3.9 あるいは Python 3.8 をインストールしている,あるいは,インストール予定という場合を想定し, あとのトラブルが起きにくい,そして,簡単に運用できるように 「Python 3.6 をインストールし,その上に,TensorFlow 1.15.5 をインストールする」という手順を案内している.
Ubuntu でのPython,TensorFlow 1.15 のインストール:別ページで案内している.
Ubuntu のシステム Python に影響を与えないように,隔離された Python 3.6 仮想環境の新規作成し,その上にTensorFlow 1.15.5 をインストールするという手順(venv を使用)(Ubuntu 上)を案内している.
Git の URL: https://git-scm.com/
sudo apt -y update sudo apt -y install git
Git の URL: https://git-scm.com/
cmake のダウンロード URL: https://cmake.org/download/
sudo apt -y update sudo apt -y install git cmake cmake-curses-gui
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
cd c:\pytools rmdir /s /q deepgaze
git clone https://github.com/mpatacchiola/deepgaze cd deepgaze python setup.py build python setup.py install
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
Python プログラムを動かす.
import numpy as np
import cv2
from deepgaze.saliency_map import FasaSaliencyMapping
# Using OpenCV the resolution of the webcam is set to these values.
# You must check which resolution your webcam support and adjust the values in accordance.
RESOLUTION_WIDTH = 320
RESOLUTION_HEIGHT = 180
# Open the video stream and set the webcam resolution.
# It may give problem if your webcam does not support the particular resolution used.
video_capture = cv2.VideoCapture(0)
# Create the main window and move it
cv2.namedWindow('Video')
# Obtaining the CAM dimension
cam_w = int(video_capture.get(3))
cam_h = int(video_capture.get(4))
# Defining the FASA object using the camera resolution
my_map = FasaSaliencyMapping(cam_h, cam_w)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
image_salient = my_map.returnMask(frame, tot_bins=8, format='BGR2LAB')
cv2.imshow('Video', image_salient)
# Press Q to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break