コード例 #1
0
ファイル: test_on_mnist.py プロジェクト: umutekmekci/deepNN
      'incoming_layer_list': [0,],
      'incoming_weight_list': [],
      'bias': None,
      'loss': 'cross_entropy',
      'act_func_name': 'softmax',
      'value': None,
      'layer_type': 'output',
      'back_error': 0,
      'link2input': None,
      'link2target': y_train } }

network = NeuralNetwork(n_layers=2, layer_dict = Networklayer_dict)
network.fit(batch_size = 1000, learning_rate = step_iterator(0.1,0.01,-0.02), 
            weight_decay = step_iterator(0,0,0), momentum = step_iterator(0.1,0.9,0.1), n_iter = 100, switch_point = 10)

y_pred = network.transform(rbm2.transform(rbm1.transform(rbm0.transform(X_test))))[0]
correct = np.sum(y_pred.argmax(axis=1) == y_test.argmax(axis=1))
print('correct = %d in %d'%(correct,X_test.shape[0]))
network.transform(rbm2.transform(rbm1.transform(rbm0.transform(X_train_copy))))[0]
error = network.empirical_error(target = y_train)
print('initial error: %f'%error)

with open(r"C:\Users\daredavil\Documents\Python Scripts\RBMver2\rbms.pkl",'wb') as file_:
    pickle.dump((rbm0.hidden_layer.dimension, rbm0.weight_list[0], rbm0.hidden_layer.bias,
                 rbm1.hidden_layer.dimension, rbm1.weight_list[0], rbm1.hidden_layer.bias,
                 rbm2.hidden_layer.dimension, rbm2.weight_list[0], rbm2.hidden_layer.bias,
                 network.output_layer_list[0].incoming_weight_list[0], network.output_layer_list[0].bias), file_)


Networklayer_dict = { 0: { 
                                'n_neuron': X.shape[1],    
コード例 #2
0
ファイル: cifar_deep_auto.py プロジェクト: umutekmekci/deepNN
        "bias": rbm_list[0].input_layer_list[0].bias,
        "loss": "mse",
        "act_func_name": "linear",
        "value": None,
        "layer_type": "output",
        "random_state": random_state,
        "back_error": 0,
        "link2target": X_train,
    },
}
network = NeuralNetwork(n_layers=11, layer_dict=Networklayer_dict)
network.fit(
    batch_size=1000,
    learning_rate=step_iterator(0.1, 0.01, -0.02),
    weight_decay=step_iterator(0, 0, 0),
    momentum=step_iterator(0, 0, 0),
    n_iter=5,
    switch_point=None,
)
network.transform([X_train])[0]
hidd_rep_train = network.layer_list[5].value

network.transform([X_test])[0]
hidd_rep_test = network.layer_list[5].value

save_dict["hrtrain"] = hidd_rep_train
save_dict["hrtest"] = hidd_rep_test

with open("data.pkl", "wb") as f_:
    cPickle.dump(save_dict, f_)