def load_dbn(path='models/avletters_ae.mat'):
"""
load a pretrained dbn from path
:param path: path to the .mat dbn
:return: pretrained deep belief network
"""
# create the network using weights from pretrain_nn.mat
nn = sio.loadmat(path)
w1 = nn['w1'].astype('float32')
w2 = nn['w2'].astype('float32')
w3 = nn['w3'].astype('float32')
w4 = nn['w4'].astype('float32')
w5 = nn['w5'].astype('float32')
w6 = nn['w6'].astype('float32')
w7 = nn['w7'].astype('float32')
w8 = nn['w8'].astype('float32')
b1 = nn['b1'][0].astype('float32')
b2 = nn['b2'][0].astype('float32')
b3 = nn['b3'][0].astype('float32')
b4 = nn['b4'][0].astype('float32')
b5 = nn['b5'][0].astype('float32')
b6 = nn['b6'][0].astype('float32')
b7 = nn['b7'][0].astype('float32')
b8 = nn['b8'][0].astype('float32')
layers = [
(InputLayer, {'name': 'input', 'shape': (None, 1200)}),
(DenseLayer, {'name': 'l1', 'num_units': 2000, 'nonlinearity': sigmoid, 'W': w1, 'b': b1}),
(DenseLayer, {'name': 'l2', 'num_units': 1000, 'nonlinearity': sigmoid, 'W': w2, 'b': b2}),
(DenseLayer, {'name': 'l3', 'num_units': 500, 'nonlinearity': sigmoid, 'W': w3, 'b': b3}),
(DenseLayer, {'name': 'l4', 'num_units': 50, 'nonlinearity': linear, 'W': w4, 'b': b4}),
(DenseLayer, {'name': 'l5', 'num_units': 500, 'nonlinearity': sigmoid, 'W': w5, 'b': b5}),
(DenseLayer, {'name': 'l6', 'num_units': 1000, 'nonlinearity': sigmoid, 'W': w6, 'b': b6}),
(DenseLayer, {'name': 'l7', 'num_units': 2000, 'nonlinearity': sigmoid, 'W': w7, 'b': b7}),
(DenseLayer, {'name': 'output', 'num_units': 1200, 'nonlinearity': linear, 'W': w8, 'b': b8}),
]
dbn = NeuralNet(
layers=layers,
max_epochs=10,
objective_loss_function=squared_error,
update=adadelta,
regression=True,
verbose=1,
update_learning_rate=0.01,
# update_learning_rate=0.001,
# update_momentum=0.05,
objective_l2=0.005,
)
return dbn
评论列表
文章目录