chainerでloss出力のエラー
ただいま、chinerを学習中なんですが以下を実行すると次のエラーが出ます
chainer.utils.type_check.InvalidType: Invalid operation is performed
in: SoftmaxCrossEntropy (Forward)Expect: in_types[1].dtype.kind == i Actual: f != i
何が悪いのでしょうか?下にコードを貼ります
class MLP(chainer.Chain):
def __init__(self, n_units, n_outs):
super(MLP, self).__init__()
with self.init_scope():
self.l1 = L.Linear(None, n_units)
self.l2 = L.Linear(None, n_units)
self.l3 = L.Linear(None, n_outs)
def __call__(self, x, *args, **kwargs):
h1 = F.relu(self.l1(x))
h2 = F.relu(self.l2(h1))
y = F.relu(self.l3(h2))
return y
X = np.array([[1.,5.,0.,1.,3.],
[2.,3.,1.,3.,9.],
[0.,4.,4.,2.,1.],
[2.,3.,0.,4.,7.],
[0.,9.,0.,6.,4.],
[3.,4.,3.,1.,0.],
[1.,4.,0.,3.,1.],
[8.,1.,3.,3.,1.]], dtype=np.float32)
Y = np.array([0.5, 0.3, 0.4, 0.3, 0.9, 0.4, 0.4, 0.1], dtype=np.float32)
X = Variable(X)
model = MLP(5, 8)
h = model(X)
t = Y
loss = F.softmax_cross_entropy(h, t)
print loss
# opt = optimizers.Adam()
# opt.setup(model)