事のきっかけ
人工知能が最近のブームになりつつある今日この頃。
ひょんな事で始めたはいいが右も左も分からない状態で、あれこれと手を出していると学習ベクトル量子化という奴を行う際に、ググっても出てこなくて色々やってだいぶ時間を食ったので、ここにメモ兼周知する目的で書こうと思った。(余計なお世話)
pip3 パッケージ一覧
Package | Version |
---|---|
absl-py | 0.8.0 |
astor | 0.8.0 |
cycler | 0.10.0 |
gast | 0.3.2 |
google-pasta | 0.1.7 |
grpcio | 1.23.0 |
h5py | 2.10.0 |
Keras-Applications | 1.0.8 |
Keras-Preprocessing | 1.1.0 |
kiwisolver | 1.1.0 |
Markdown | 3.1.1 |
matplotlib | 3.1.1 |
neurolab | 0.3.5 |
numpy | 1.16.5 |
pip | 19.2.3 |
protobuf | 3.9.1 |
pyparsing | 2.4.2 |
python-dateutil | 2.8.0 |
setuptools | 41.2.0 |
six | 1.12.0 |
tensorboard | 1.14.0 |
tensorflow | 1.14.0 |
tensorflow-estimator | 1.14.0 |
termcolor | 1.1.0 |
Werkzeug | 0.15.6 |
wheel | 0.33.6 |
wrapt | 1.11.2 |
ソースコード(一部抜粋)
text = np.loadtxt('outPut.csv', delimiter=',')
FEATURE = text[:, :2]
LABEL = text[:, 2:]
input_neurons = 10
output_neurons = 4
weights = [1 / output_neurons] * output_neurons
NN = nl.net.newlvq(nl.tool.minmax(FEATURE), input_neurons, weights)
NN.train(FEATURE, LABEL, epochs=500, goal=-1)
エラーログ
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/Jetbrains/apps/PyCharm-P/ch-0/192.6603.34/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/Jetbrains/apps/PyCharm-P/ch-0/192.6603.34/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/azuma.t/git/tensorflow-hevc/20190917.py", line 61, in <module>
NN = nl.net.newlvq(nl.tool.minmax(FEATURE), input_neurons, weights)
File "/Users/azuma.t/py3.7/lib/python3.7/site-packages/neurolab/net.py", line 179, in newlvq
layer_out.np['w'][n][st:i].fill(1.0)
TypeError: slice indices must be integers or None or have an __index__ method
やり方
>>>import neurolab
>>>print(neurolab.__file__)
C:\Users\........\nurolab\__init__.py
neurolabの場所を出力させる。場所は、nurolabまでのディレクトリ。
その中の、net.pyの176行目にある
inx = np.floor(cn0 * pc.cumsum())
を
inx = np.floor(cn0 * pc.cumsum()).astype(int)
に変える事で回避できる。