私はTheanoでガウスカーネルを実装しました。しかし、それをニューラルネットワークの一部としてテストした場合、時間がかかりすぎます。カーネル減算はパラレル化されていないようです。ネットワーク全体のトレーニングは、単一の処理コアを使用します。では、Theanoにカーネル操作を分割させるように正しく誘導する方法はありますか?theanoでの効率的なカーネル実装
import theano.tensor as T
import numpy
import theano
batch_s=5
dims=10
hidd_s=3
out_s=2
missing_param = None #"ignore"
rng = numpy.random.RandomState(1234)
input = T.matrix("input")
X = numpy.asarray(rng.uniform(low=-2.1, high=5.0, size=(batch_s, dims)))
def layer(x):
W=theano.shared(
value=numpy.asarray(
rng.uniform(low=0.001, high=1.0, size=(dims, hidd_s)),
dtype=theano.config.floatX),
name='W', borrow=True)
S=theano.shared(
value=numpy.asarray(
rng.uniform(low=10.0, high=100.0, size=(hidd_s,)),
dtype=theano.config.floatX),
name='S', borrow=True)
dot_H = theano.shared(
value=numpy.zeros((batch_s, hidd_s),
dtype=theano.config.floatX),
name='dot_H', borrow=True)
# This is the kernel operation. I have tested with single scan as well
# as with two nested scans, but operations arenot splitted as in the
# case of the usual dot product T.dot().
for i in range(batch_s):
for j in range(hidd_s):
dot_H = T.set_subtensor(dot_H[i,j],
T.exp(-(W.T[j] - x[i]).norm(2) ** 2)/2 * S[j] ** 2)
return dot_H
layer_out = theano.function(
inputs=[input],
outputs=layer(input),
on_unused_input=missing_param
)
print layer_out(X)
タクあなたは大変です。
ニューラルネットワークを構築している場合は、[Intel Theano](https://github.com/intel/Theano)を試してみてください。これは、最適化された畳み込み、reluおよび他のプリミティブでCPUが非常に高速になります。 – Patric