TensorFlow 2.0 rc のインストールメモ

pip install tesorflow で、TensorFlow 2.0 rc をインストールして、import してみると、次のエラーが発生。原因は、CPUが AVX(Advanced Vector Extensions)をサポートしていないためのようだ。Core i7なので、割と新しいと思っていたけど。orz

PS > pip install tensorflow==2.0.0-beta0
Collecting tensorflow==2.0.0-beta0
Downloading https://files.pythonhosted.org/packages/44/43/f2c843ffc4f914c31aee2f20c635cccd6fb2269d9491c12f9e0c30691554
/tensorflow-2.0.0b0-cp37-cp37m-win_amd64.whl (55.1MB)
|████████████████████████████████| 55.1MB 2.2MB/s
Requirement already satisfied: numpy<2.0,>=1.14.5 in d:\program files\python37\lib\site-packages (from tensorflow==2.0.0
-beta0) (1.17.0)
Collecting wheel>=0.26 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9
/wheel-0.33.6-py2.py3-none-any.whl
Collecting wrapt>=1.11.1 (from tensorflow==2.0.0-beta0)
Using cached https://files.pythonhosted.org/packages/23/84/323c2415280bc4fc880ac5050dddfb3c8062c2552b34c2e512eb4aa68f7
9/wrapt-1.11.2.tar.gz
Collecting keras-applications>=1.0.6 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/71/e3/19762fdfc62877ae9102edf6342d71b28fbfd9dea3d2f96a882ce099b03f
/Keras_Applications-1.0.8-py3-none-any.whl (50kB)
|████████████████████████████████| 51kB 3.2MB/s
Collecting tf-estimator-nightly<1.14.0.dev2019060502,>=1.14.0.dev2019060501 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/32/dd/99c47dd007dcf10d63fd895611b063732646f23059c618a373e85019eb0e
/tf_estimator_nightly-1.14.0.dev2019060501-py2.py3-none-any.whl (496kB)
|████████████████████████████████| 501kB 6.4MB/s
Collecting grpcio>=1.8.6 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/32/e7/478737fd426798caad32a2abb7cc63ddb4c12908d9e03471dd3c41992b05
/grpcio-1.23.0-cp37-cp37m-win_amd64.whl (1.6MB)
|████████████████████████████████| 1.6MB …
Collecting gast>=0.2.0 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/4e/35/11749bf99b2d4e3cceb4d55ca22590b0d7c2c62b9de38ac4a4a7f4687421
/gast-0.2.2.tar.gz
Collecting protobuf>=3.6.1 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/46/8b/5e77963dac4a944a0c6b198c004fac4c85d7adc54221c288fc6ca9078072
/protobuf-3.9.1-cp37-cp37m-win_amd64.whl (1.0MB)
|████████████████████████████████| 1.0MB …
Collecting absl-py>=0.7.0 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/3c/0d/7cbf64cac3f93617a2b6b079c0182e4a83a3e7a8964d3b0cc3d9758ba002
/absl-py-0.8.0.tar.gz (102kB)
|████████████████████████████████| 112kB 6.4MB/s
Collecting google-pasta>=0.1.6 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/d0/33/376510eb8d6246f3c30545f416b2263eee461e40940c2a4413c711bdf62d
/google_pasta-0.1.7-py3-none-any.whl (52kB)
|████████████████████████████████| 61kB 2.0MB/s
Collecting keras-preprocessing>=1.0.5 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/28/6a/8c1f62c37212d9fc441a7e26736df51ce6f0e38455816445471f10da4f0a
/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl (41kB)
|████████████████████████████████| 51kB 252kB/s
Collecting termcolor>=1.1.0 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981
/termcolor-1.1.0.tar.gz
Requirement already satisfied: six>=1.10.0 in d:\program files\python37\lib\site-packages (from tensorflow==2.0.0-beta0)
(1.12.0)
Collecting astor>=0.6.0 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/d1/4f/950dfae467b384fc96bc6469de25d832534f6b4441033c39f914efd13418
/astor-0.8.0-py2.py3-none-any.whl
Collecting tb-nightly<1.14.0a20190604,>=1.14.0a20190603 (from tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/a4/96/571b875cd81dda9d5dfa1422a4f9d749e67c0a8d4f4f0b33a4e5f5f35e27
/tb_nightly-1.14.0a20190603-py3-none-any.whl (3.1MB)
|████████████████████████████████| 3.1MB 6.8MB/s
Collecting h5py (from keras-applications>=1.0.6->tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/4f/1e/89aa610afce8df6fd1f12647600a05e902238587ae6375442a3164b59d51
/h5py-2.9.0-cp37-cp37m-win_amd64.whl (2.4MB)
|████████████████████████████████| 2.4MB 6.4MB/s
Requirement already satisfied: setuptools in d:\program files\python37\lib\site-packages (from protobuf>=3.6.1->tensorfl
ow==2.0.0-beta0) (40.8.0)
Collecting markdown>=2.6.8 (from tb-nightly<1.14.0a20190604,>=1.14.0a20190603->tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/c0/4e/fd492e91abdc2d2fcb70ef453064d980688762079397f779758e055f6575
/Markdown-3.1.1-py2.py3-none-any.whl (87kB)
|████████████████████████████████| 92kB 5.8MB/s
Collecting werkzeug>=0.11.15 (from tb-nightly<1.14.0a20190604,>=1.14.0a20190603->tensorflow==2.0.0-beta0)
Downloading https://files.pythonhosted.org/packages/d1/ab/d3bed6b92042622d24decc7aadc8877badf18aeca1571045840ad4956d3f
/Werkzeug-0.15.5-py2.py3-none-any.whl (328kB)
|████████████████████████████████| 337kB …

ERROR: tb-nightly 1.14.0a20190603 has requirement setuptools>=41.0.0, but you’ll have setuptools 40.8.0 which is incompatible.


Installing collected packages: wheel, wrapt, h5py, keras-applications, tf-estimator-nightly, grpcio, gast, protobuf, abs
l-py, google-pasta, keras-preprocessing, termcolor, astor, markdown, werkzeug, tb-nightly, tensorflow
Running setup.py install for wrapt … done
Running setup.py install for gast … done
Running setup.py install for absl-py … done
Running setup.py install for termcolor … done
Successfully installed absl-py-0.8.0 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.23.0 h5py-2.9.0 keras-applicatio
ns-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 protobuf-3.9.1 tb-nightly-1.14.0a20190603 tensorflow-2.0.0b0 termcolor
-1.1.0 tf-estimator-nightly-1.14.0.dev2019060501 werkzeug-0.15.5 wheel-0.33.6 wrapt-1.11.2
PS>

Tensorflowインストール不具合解決方法 を参考に、sseをインストールしてみる。

PS > pip install .\tensorflow-1.14.0-cp37-cp37m-win_amd64.whl により、sse をインストールしてみる。

import numpy as np
import matplotlib.pyplot as plt

print(tf.version)
1.14.0

その結果、TensorFlow のバージョンが 2.0 RC から、1.14.0 にダウンしている。ローカルでTF 2.0を試したかったのだけど、Google Colab で試すしかなさそう。

C#からすると違和感のあるPython 文法

概要文例
for の後の if 文 len([num for num in nums if num < 0])
暗黙の型変換bool(1), bool(0)
def という名前
関数の複数の戻り値
def least_difference(a, b, c):
diff1 = abs(a – b)
diff2 = abs(b – c)
diff3 = abs(a – c)
return min(diff1, diff2, diff3)
switch 文がない
else if ではなく、elif
def inspect(x):
if x == 0:
print(x, “is zero”)
elif x > 0:
print(x, “is positive”)
elif x < 0:
print(x, “is negative”)
else:
print(x, “is unlike anything I’ve ever seen…”)
標準ではconst がないPI = 3.14
トリプルクオート triplequoted_hello = “””hello
world”””
in planets = [‘Mercury’, ‘Venus’, ‘Earth’, ‘Mars’]
‘Saturn’ in planets
from import from math import *
print(pi, log(32, 2))
————-
from math import *
from numpy import *
print(pi, log(32, 2))
これは、path, numpy ともにlog が定義されているため、 TypeError: return arrays must be of ArrayType エラーとなる
dir print(dir(list))

[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1

OpenCVで、突然次のエラーが出るようになった。
[ WARN:1] videoio(MSMF): can’t grab frame. Error

原因は、VideoCapture を2つのプロセスで起動していたため、あとから起動したプロセスがフレームを取得することができなかったため。

OpenCV: FFMPEG: tag 0x5634504d/’MP4V’ is not supported with codec id 12 and form
at ‘mp4 / MP4 (MPEG-4 Part 14)’
OpenCV: FFMPEG: fallback to use tag 0x7634706d/’mp4v’
[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772

[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1
072875772
[ WARN:1] videoio(MSMF): can’t grab frame. Error: -1072875772
[ WARN:1] videoio(MSMF): can’t grab frame. Error: -2147483638
[ WARN:1] videoio(MSMF): can’t grab frame. Error: -2147483638
[ WARN:1] videoio(MSMF): can’t grab frame. Error: -2147483638
[ WARN:1] videoio(MSMF): can’t grab frame. Error: -2147483638

Module ‘cv2’ has no ‘VideoCapture’ memberpylint(no-member)

Visual Studio Code (Windows) で、CV2 で次の lint エラーが出る場合の解消法

Module ‘cv2’ has no ‘VideoCapture’ memberpylint(no-member)

[メニュー] →[ファイル] →[基本設定] →[設定]

設定タブが開くので、設定の検索に “lint” を入力

Python › Linting: Pylint Args
に、
–extension-pkg-whitelist=cv2
を追加して、セーブする。
似たような設定項目が多いので注意。