ラザニアとテアノを使用して、VGG から回帰タスクの 20 個の数値を予測しています。私が書いたスクリプトの例では、画像の数は 100 です。
ネットで調べてみると、nolearnを使っている人は を指定することで直りますregression=True
が、私はラザニアばかり使っています
そう:
('X.shape', (100, 3, 224, 224))
('y.shape', (100, 20))
これが正確なエラーメッセージです
Traceback (most recent call last):
File "script_1.py", line 167, in <module>
loss = train_batch()
File "script_1.py", line 90, in train_batch
return train_fn(X_tr[ix], y_tr[ix])
File "/usr/local/lib/python2.7/dist-packages/Theano-0.8.0rc1-py2.7.egg/theano/compile/function_module.py", line 786, in __call__
allow_downcast=s.allow_downcast)
File "/usr/local/lib/python2.7/dist-packages/Theano-0.8.0rc1-py2.7.egg/theano/tensor/type.py", line 177, in filter
data.shape))
TypeError: ('Bad input argument to theano function with name "script_1.py:159" at index 1(0-based)', 'Wrong number of dimensions: expected 1, got 2 with shape (16, 20).')
モデルはこちら
def build_model():
net = {}
net['input'] = InputLayer((None, 3, 224, 224))
net['conv1'] = ConvLayer(net['input'], num_filters=96, filter_size=7, stride=2, flip_filters=False)
...............
net['drop7'] = DropoutLayer(net['fc7'], p=0.5)
net['fc8'] = DenseLayer(net['drop7'], num_units=20, nonlinearity=None)
return net
ジェネレーター:
def batches(iterable, N):
chunk = []
for item in iterable:
chunk.append(item)
if len(chunk) == N:
yield chunk
chunk = []
if chunk:
yield chunk
def train_batch():
ix = range(len(y_tr))
np.random.shuffle(ix)
ix = ix[:BATCH_SIZE]
return train_fn(X_tr[ix], y_tr[ix])
関連するトレーニング スニペット
X_sym = T.tensor4()
y_sym = T.ivector()
output_layer = net['fc8']
prediction = lasagne.layers.get_output(output_layer, X_sym)
loss = lasagne.objectives.squared_error(prediction, y_sym)
loss = loss.mean()
acc = T.mean(T.eq(T.argmax(prediction, axis=1), y_sym), dtype=theano.config.floatX)
params = lasagne.layers.get_all_params(output_layer, trainable=True)
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate=0.0001, momentum=0.9)
train_fn = theano.function([X_sym, y_sym], loss, updates=updates)
val_fn = theano.function([X_sym, y_sym], [loss, acc])
pred_fn = theano.function([X_sym], prediction)
for epoch in range(5):
for batch in range(25):
loss = train_batch()
.....