如何获取层上神经元的值? Python-不学习
How to get values of neurons on layer? Python-nolearn
我使用 nolearn 库创建了神经网络。
net = NeuralNet(
layers=[
('input', layers.InputLayer),
('conv1', layers.Conv2DLayer),
('pool1', layers.MaxPool2DLayer),
('dropout1', layers.DropoutLayer),
('conv2', layers.Conv2DLayer),
('pool2', layers.MaxPool2DLayer),
('dropout2', layers.DropoutLayer),
('conv3', layers.Conv2DLayer),
('pool3', layers.MaxPool2DLayer),
('dropout3', layers.DropoutLayer),
('hidden4', layers.DenseLayer),
('output', layers.DenseLayer),
],
input_shape=(None, 1, imgSize, imgSize),
conv1_num_filters=32, conv1_filter_size=(param1, param1), pool1_pool_size=(2, 2),
dropout1_p=0.4,
conv2_num_filters=64, conv2_filter_size=(param2, param2), pool2_pool_size=(2, 2),
dropout2_p=0.4,
conv3_num_filters=128, conv3_filter_size=(param3, param3), pool3_pool_size=(2, 2),
dropout3_p=0.4,
hidden4_num_units=1000,
output_num_units=classNum, output_nonlinearity=lasagne.nonlinearities.softmax,
update_learning_rate=0.01,
update_momentum=0.9,
regression=False,
max_epochs=100,
verbose=1,
)
net.fit(trainD, trainL)
如何获取某些 x 上隐藏层神经元的值?我不会获取这些值并将它们用于其他算法以获得更好的结果。
所以,我找到了解决方案。
hidden_layer = layers.get_output(net.layers_['hidden4'], deterministic=True)
input_var = net.layers_['input'].input_var
f_hidden = theano.function([input_var], hidden_layer)
instance = TestD[i][None, :, :, :]
pred = f_hidden(instance)
我使用 nolearn 库创建了神经网络。
net = NeuralNet(
layers=[
('input', layers.InputLayer),
('conv1', layers.Conv2DLayer),
('pool1', layers.MaxPool2DLayer),
('dropout1', layers.DropoutLayer),
('conv2', layers.Conv2DLayer),
('pool2', layers.MaxPool2DLayer),
('dropout2', layers.DropoutLayer),
('conv3', layers.Conv2DLayer),
('pool3', layers.MaxPool2DLayer),
('dropout3', layers.DropoutLayer),
('hidden4', layers.DenseLayer),
('output', layers.DenseLayer),
],
input_shape=(None, 1, imgSize, imgSize),
conv1_num_filters=32, conv1_filter_size=(param1, param1), pool1_pool_size=(2, 2),
dropout1_p=0.4,
conv2_num_filters=64, conv2_filter_size=(param2, param2), pool2_pool_size=(2, 2),
dropout2_p=0.4,
conv3_num_filters=128, conv3_filter_size=(param3, param3), pool3_pool_size=(2, 2),
dropout3_p=0.4,
hidden4_num_units=1000,
output_num_units=classNum, output_nonlinearity=lasagne.nonlinearities.softmax,
update_learning_rate=0.01,
update_momentum=0.9,
regression=False,
max_epochs=100,
verbose=1,
)
net.fit(trainD, trainL)
如何获取某些 x 上隐藏层神经元的值?我不会获取这些值并将它们用于其他算法以获得更好的结果。
所以,我找到了解决方案。
hidden_layer = layers.get_output(net.layers_['hidden4'], deterministic=True)
input_var = net.layers_['input'].input_var
f_hidden = theano.function([input_var], hidden_layer)
instance = TestD[i][None, :, :, :]
pred = f_hidden(instance)