示例#1
0
Linear = Linear(in_size=144, out_size=10)

#calling model for creating features
model_test = RBM(n_visible=28 * 28, n_hidden=144)

#Loading Weight
rbm_weight_file = open("model/rbm_weight.npy", 'rb')
model_test.weight = pickle.load(rbm_weight_file)

#Loading visible layer bias
rbm_v_bias_file = open("model/rbm_v_bias.npy", 'rb')
model_test.v_bias = pickle.load(rbm_v_bias_file)

#Loading hidden layer bias
rbm_h_bias_file = open("model/rbm_h_bias.npy", 'rb')
model_test.h_bias = pickle.load(rbm_h_bias_file)

img_num = 60000


def train(x_train, y_train, alpha=0.001, weight_decay=0.0, epochs=40):
    for i in range(epochs):
        train_loss = 0
        count = 0
        for j in range(img_num):
            input = x_train[j].copy().reshape(1, 784) / 255.0
            target = y_train[j].copy()

            #Extracting hidden features using RBM
            input, _ = model_test.sample_h_given_v(input)