我正在使用Lasagne为MNIST数据集创建CNN.我正密切关注这个例子:卷积神经网络和Python特征提取.
我目前拥有的CNN架构(不包括任何丢失层)是:
NeuralNet(
layers=[('input', layers.InputLayer), # Input Layer
('conv2d1', layers.Conv2DLayer), # Convolutional Layer
('maxpool1', layers.MaxPool2DLayer), # 2D Max Pooling Layer
('conv2d2', layers.Conv2DLayer), # Convolutional Layer
('maxpool2', layers.MaxPool2DLayer), # 2D Max Pooling Layer
('dense', layers.DenseLayer), # Fully connected layer
('output', layers.DenseLayer), # Output Layer
],
# input layer
input_shape=(None, 1, 28, 28),
# layer conv2d1
conv2d1_num_filters=32,
conv2d1_filter_size=(5, 5),
conv2d1_nonlinearity=lasagne.nonlinearities.rectify,
# layer maxpool1
maxpool1_pool_size=(2, 2),
# layer conv2d2
conv2d2_num_filters=32,
conv2d2_filter_size=(3, 3),
conv2d2_nonlinearity=lasagne.nonlinearities.rectify,
# layer maxpool2
maxpool2_pool_size=(2, 2),
# Fully Connected …
Run Code Online (Sandbox Code Playgroud) neural-network deep-learning conv-neural-network lasagne nolearn
简而言之,为了运行卷积神经网络模型,我需要一个特殊版本nolearn
,其中包含https://github.com/dnouri/nolearn/tree/1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn形式的网址.但是,Download as Zip
页面上没有按钮,我也无法下载
git clone https://github.com/dnouri/nolearn -branch 1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn
Run Code Online (Sandbox Code Playgroud)
只是,
git clone https://github.com/dnouri/nolearn/tree/1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn
Run Code Online (Sandbox Code Playgroud)
也行不通.
甚至,我不知道我应该在谷歌搜索什么!
注意:这是为类提供支持的最后一个版本Objective
,即from lasagne.objectives import Objective
不再支持该命令!
我用lasagne/nolearn训练了一个自动编码器.假设网络层是[500,100,100,500].我像这样训练了神经网络:
net.fit(X, X)
Run Code Online (Sandbox Code Playgroud)
我想做类似以下的事情:
net.predict(X, layer=2)
Run Code Online (Sandbox Code Playgroud)
所以我会得到我的数据的抑制表示.因此,如果我的初始数据的形状为[10000,500],则结果数据将为[10000,100].
我搜索但无法找到如何做到这一点.是不是可以用千层面/ nolearn?
我正在nolearn做一个神经网络,这是一个使用烤宽面条的Theano图书馆.
我不明白如何定义自己的成本函数.
输出层只有3个神经元[0, 1, 2]
,我希望它在给出1或2时大部分都是肯定的,否则 - 如果它不能确定1,2,则简单地返回0.
所以,我提出了一个成本函数(需要调整),其成本是1和2的两倍而不是0,但我无法理解如何告诉网络.
# optimization method:
from lasagne.updates import sgd
update=sgd,
update_learning_rate=0.0001
Run Code Online (Sandbox Code Playgroud)
这是更新的代码,但是如何告诉SGD使用我的成本函数而不是它自己的?
编辑: 完整的网络代码是:
def nn_loss(data, x_period, columns, num_epochs, batchsize, l_rate=0.02):
net1 = NeuralNet(
layers=[('input', layers.InputLayer),
('hidden1', layers.DenseLayer),
('output', layers.DenseLayer),
],
# layer parameters:
batch_iterator_train=BatchIterator(batchsize),
batch_iterator_test=BatchIterator(batchsize),
input_shape=(None, int(x_period*columns)),
hidden1_nonlinearity=lasagne.nonlinearities.rectify,
hidden1_num_units=100, # number of units in 'hidden' layer
output_nonlinearity=lasagne.nonlinearities.sigmoid,
output_num_units=3,
# optimization method:
update=nesterov_momentum,
update_learning_rate=5*10**(-3),
update_momentum=0.9,
on_epoch_finished=[
EarlyStopping(patience=20),
],
max_epochs=num_epochs,
verbose=1,
# Here are the important parameters for multi labels
regression=True,
# objective_loss_function=multilabel_objective, …
Run Code Online (Sandbox Code Playgroud) 我正在使用Theano 0.7
,nolearn 0.6adev
并lasagne 0.2.dev1
在GPU(在IPython 3.2.1
笔记本电脑中)训练神经网络.但是,由于第一层('reduc'
),以下网络没有开始训练,等待几个小时后:
import theano
from lasagne import layers
from lasagne.updates import nesterov_momentum
from nolearn.lasagne import NeuralNet
from nolearn.lasagne import BatchIterator
from lasagne import nonlinearities
from lasagne import init
import numpy as np
testNet = NeuralNet(
layers=[(layers.InputLayer, {"name": 'input', 'shape': (None, 12, 1000, )}),
(layers.Conv1DLayer, {"name": 'reduc', 'filter_size': 1, 'num_filters': 4,
"nonlinearity":nonlinearities.linear,}),
(layers.Conv1DLayer, {"name": 'conv1', 'filter_size': 25, 'num_filters': 100,
'pad': 'same', }),
(layers.MaxPool1DLayer, {'name': 'pool1', 'pool_size': 5, 'stride': …
Run Code Online (Sandbox Code Playgroud) 我是Nolearn和Theano的新手.当我在Nolearn教程中尝试代码时,我的错误率非常高,为0.9!
为什么我在教程误差为0.005时会出现如此高的错误?还有其他人能够重现这个问题吗?
在OS X Yosemite上使用Theano 0.7.0,Lasagne v0.1,nolearn v0.5.
产量
[DBN] fitting X.shape=(46900, 784)
[DBN] layers [784, 300, 10]
[DBN] Fine-tune...
100%
Epoch 1:
100%
loss 2.30829815265
err 0.901340505464
(0:00:30)
Epoch 2:
100%
loss 2.30304712187
err 0.902813353825
(0:00:34)
Epoch 3:
100%
loss 2.30303548692
err 0.90072148224
(0:00:34)
Epoch 4:
100%
loss 2.30297605197
err 0.902322404372
(0:00:28)
Epoch 5:
100%
loss 2.30295462556
err 0.901191086066
(0:00:26)
Epoch 6:
100%
loss 2.30293222366
err 0.898352117486
(0:00:33)
Epoch 7:
100%
loss 2.30283567033
err 0.901425887978
(0:00:34)
Epoch …
Run Code Online (Sandbox Code Playgroud) 我尝试使用从nolearn包导入的DBN函数,这是我的代码:
from nolearn.dbn import DBN
import numpy as np
from sklearn import cross_validation
fileName = 'data.csv'
fileName_1 = 'label.csv'
data = np.genfromtxt(fileName, dtype=float, delimiter = ',')
label = np.genfromtxt(fileName_1, dtype=int, delimiter = ',')
clf = DBN(
[data, 300, 10],
learn_rates=0.3,
learn_rate_decays=0.9,
epochs=10,
verbose=1,
)
clf.fit(data,label)
score = cross_validation.cross_val_score(clf, data, label,scoring='f1', cv=10)
print score
Run Code Online (Sandbox Code Playgroud)
由于我的数据具有形状(1231,229)和带有形状(1231,13)的标签,因此标签集看起来像([0 0 1 0 1 0 1 0 0 0 1 1 0] ...,[.. ..]),当我运行我的代码时,我得到了这个错误信息:输入形状不好(1231,13).我想知道这里可能发生两个问题:
当我使用nolearn实现多标签分类时,我收到此错误:
'在索引1(基于0)的名称为"/Users/lm/Documents/anaconda/lib/python2.7/site-packages/nolearn/lasagne/base.p y:391"的theano函数输入参数错误,'TensorType(float32,matrix)无法存储dtype int64的值而不会有丢失精度的风险.如果你不介意这种损失,你可以:1)显式地将你的数据转换为float32,或者2)在调用"function"时设置"allow_input_downcast = True".',array([[0,0,0,... ,0,0,1],
nolearn ×8
lasagne ×5
python ×5
theano ×4
python-2.7 ×2
autoencoder ×1
dbn ×1
git ×1
github ×1