本文整理汇总了Python中nolearn.lasagne.NeuralNet.save_weights_to方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNet.save_weights_to方法的具体用法?Python NeuralNet.save_weights_to怎么用?Python NeuralNet.save_weights_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nolearn.lasagne.NeuralNet
的用法示例。
在下文中一共展示了NeuralNet.save_weights_to方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlorotUniform
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
dropout_p=0.5,
output_num_units=num_classes, output_nonlinearity=lasagne.nonlinearities.softmax,
output_W = GlorotUniform(gain = 1.0),
# ----------------------- ConvNet Params -------------------------------------------
update = nesterov_momentum,
update_learning_rate = learning_rate,
update_momentum = momentum,
max_epochs = num_epochs,
verbose = 1,
)
tic = time.time()
for i in range(12):
convNet.fit(dataset['X_train'], dataset['Y_train'])
fl = './model1/saved_model_data' + str(i+1) + '.npz'
convNet.save_weights_to(fl)
print 'Model saved to file :- ', fl
toc = time.time()
fl = './model1/saved_model_data' + str(6) + '.npz'
convNet.load_weights_from(fl)
y_pred = convNet.predict(dataset['X_test'])
print classification_report(Y_test, y_pred)
print accuracy_score(Y_test, y_pred)
print 'Time taken to train the data :- ', toc-tic, 'seconds'
示例2: open
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
# output
output_nonlinearity=lasagne.nonlinearities.softmax,
output_num_units=2,
# optimization method params
update=nesterov_momentum,
update_learning_rate=0.007,
update_momentum=0.9,
max_epochs=16,
verbose=1,
)
"""Loading data and training Lasagne network using nolearn"""
trainImg = np.load('trainImg_stage1.npy')
trainVal2 = np.load('trainVal_stage1.npy')
trainImg2 = trainImg.astype(np.float32).swapaxes(1, 3)
trainVal2 = trainVal2.astype(np.uint8)
print "Training Classifier: 70/30 split"
nn.fit(trainImg2, trainVal2)
print "Saving Classifier"
pickle.dump(nn, open("nn_stage1.pkl", "wb"))
nn.save_weights_to('weights_stage1')
示例3:
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
output_nonlinearity=softmax,
update=nesterov_momentum,
update_learning_rate=0.01,
update_momentum=0.9,
eval_size=0.2,
verbose=1,
max_epochs=200)
print "fitting nn model.."
net0.fit(X_train, y_train)
print "predicting probabilities using nn model..."
proba = net0.predict_proba(X_test)
ll.append(calc_ll_from_proba(proba, y_test))
print metrics.confusion_matrix(
y_test.astype(int), np.argmax(proba, axis=1).astype(int))
print "logloss: ", ll[ncv]
print "saving nn model..."
net0.save_weights_to('weights/nn_%d.pkl' % ncv)
net0 = None
ncv += 1
ll = np.array(ll)
print "logloss: ", ll
# make_submission(net0, X_test, ids, encoder)
示例4: open
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
verbose=1,
)
ae.fit(X_train, X_out)
print
### expect training / val error of about 0.087 with these parameters
### if your GPU not fast enough, reduce the number of filters in the conv/deconv step
# <codecell>
import pickle
import sys
sys.setrecursionlimit(10000)
pickle.dump(ae, open('mnist/conv_ae.pkl','w'))
#ae = pickle.load(open('mnist/conv_ae.pkl','r'))
ae.save_weights_to('mnist/conv_ae.np')
# <codecell>
X_train_pred = ae.predict(X_train).reshape(-1, 28, 28) * sigma + mu
X_pred = np.rint(X_train_pred).astype(int)
X_pred = np.clip(X_pred, a_min = 0, a_max = 255)
X_pred = X_pred.astype('uint8')
print X_pred.shape , X.shape
# <codecell>
### show random inputs / outputs side by side
def get_picture_array(X, index):
array = X[index].reshape(28,28)
示例5: open
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
verbose=1,
)
ae.fit(X_train, X_out)
print
### expect training / val error of about 0.087 with these parameters
### if your GPU not fast enough, reduce the number of filters in the conv/deconv step
# <codecell>
import pickle
import sys
sys.setrecursionlimit(10000)
pickle.dump(ae, open('ish/conv_ae.pkl','w'))
#ae = pickle.load(open('mnist/conv_ae.pkl','r'))
ae.save_weights_to('ish/conv_ae.np')
# <codecell>
X_train_pred = ae.predict(X_train).reshape(-1, IMAGE_WIDTH, IMAGE_HEIGHT) * sigma + mu
X_pred = np.rint(X_train_pred).astype(int)
X_pred = np.clip(X_pred, a_min = 0, a_max = 255)
X_pred = X_pred.astype('uint8')
print X_pred.shape , X.shape
# <codecell>
### show random inputs / outputs side by side
def get_picture_array(X, index):
array = X[index].reshape(IMAGE_WIDTH,IMAGE_HEIGHT)
示例6: createCSAE
# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import save_weights_to [as 别名]
#.........这里部分代码省略.........
conv41_num_filters=layers_size[3], conv41_filter_size=filter_4, conv41_nonlinearity=activation,
# conv41_border_mode="same",
conv41_pad="same",
# conv42_num_filters=layers_size[3], conv42_filter_size=filter_4, conv42_nonlinearity=activation,
# # conv42_border_mode="same",
# conv42_pad="same",
unpool2_ds=(2, 2),
conv5_num_filters=layers_size[4], conv5_filter_size=filter_5, conv5_nonlinearity=activation,
# conv5_border_mode="same",
conv5_pad="same",
conv51_num_filters=layers_size[4], conv51_filter_size=filter_5, conv51_nonlinearity=activation,
# conv51_border_mode="same",
conv51_pad="same",
# conv52_num_filters=layers_size[4], conv52_filter_size=filter_5, conv52_nonlinearity=activation,
# # conv52_border_mode="same",
# conv52_pad="same",
conv6_num_filters=1, conv6_filter_size=filter_6, conv6_nonlinearity=last_layer_activation,
# conv6_border_mode="same",
conv6_pad="same",
output_layer_shape=(([0], -1)),
update_learning_rate=learning_rate,
update_momentum=update_momentum,
update=nesterov_momentum,
train_split=TrainSplit(eval_size=train_valid_split),
batch_iterator_train=FlipBatchIterator(batch_size=batch_size) if flip_batch else BatchIterator(batch_size=batch_size),
regression=True,
max_epochs=epochs,
verbose=1,
hiddenLayer_to_output=-9)
cnn.fit(X_train, X_out)
try:
pickle.dump(cnn, open(folder_path + 'conv_ae.pkl', 'w'))
# cnn = pickle.load(open(folder_path + 'conv_ae.pkl','r'))
cnn.save_weights_to(folder_path + 'conv_ae.np')
except:
print ("Could not pickle cnn")
X_pred = cnn.predict(X_train).reshape(-1, input_height, input_width) # * sigma + mu
# # X_pred = np.rint(X_pred).astype(int)
# # X_pred = np.clip(X_pred, a_min=0, a_max=255)
# # X_pred = X_pred.astype('uint8')
#
# try:
# trian_last_hiddenLayer = cnn.output_hiddenLayer(X_train)
# # test_last_hiddenLayer = cnn.output_hiddenLayer(test_x)
# pickle.dump(trian_last_hiddenLayer, open(folder_path + 'encode.pkl', 'w'))
# except:
# print "Could not save encoded images"
print ("Saving some images....")
for i in range(10):
index = np.random.randint(train_x.shape[0])
print (index)
def get_picture_array(X, index):
array = np.rint(X[index] * 256).astype(np.int).reshape(input_height, input_width)
array = np.clip(array, a_min=0, a_max=255)
return array.repeat(4, axis=0).repeat(4, axis=1).astype(np.uint8())
original_image = Image.fromarray(get_picture_array(X_out, index))
# original_image.save(folder_path + 'original' + str(index) + '.png', format="PNG")
#
# array = np.rint(trian_last_hiddenLayer[index] * 256).astype(np.int).reshape(input_height/2, input_width/2)
# array = np.clip(array, a_min=0, a_max=255)
# encode_image = Image.fromarray(array.repeat(4, axis=0).repeat(4, axis=1).astype(np.uint8()))
# encode_image.save(folder_path + 'encode' + str(index) + '.png', format="PNG")
new_size = (original_image.size[0] * 3, original_image.size[1])
new_im = Image.new('L', new_size)
new_im.paste(original_image, (0, 0))
pred_image = Image.fromarray(get_picture_array(X_pred, index))
# pred_image.save(folder_path + 'pred' + str(index) + '.png', format="PNG")
new_im.paste(pred_image, (original_image.size[0], 0))
noise_image = Image.fromarray(get_picture_array(X_train, index))
new_im.paste(noise_image, (original_image.size[0]*2, 0))
new_im.save(folder_path+'origin_prediction_noise-'+str(index)+'.png', format="PNG")
# diff = ImageChops.difference(original_image, pred_image)
# diff = diff.convert('L')
# diff.save(folder_path + 'diff' + str(index) + '.png', format="PNG")
# plt.imshow(new_im)
# new_size = (original_image.size[0] * 2, original_image.size[1])
# new_im = Image.new('L', new_size)
# new_im.paste(original_image, (0, 0))
# pred_image = Image.fromarray(get_picture_array(X_train, index))
# # pred_image.save(folder_path + 'noisyInput' + str(index) + '.png', format="PNG")
# new_im.paste(pred_image, (original_image.size[0], 0))
# new_im.save(folder_path+'origin_VS_noise-'+str(index)+'.png', format="PNG")
# plt.imshow(new_im)
return cnn