예제 #1
0
            plt.imshow(feature.reshape(k, shp[0], shp[1])[0], interpolation='None', cmap='binary')
        plt.show()

    def dump2file(cnn, filename):
        global datasets_for_abstract
        x = datasets_for_abstract[0][0]
        y = datasets_for_abstract[0][1].eval()

        features = cnn.get_feature(x)

        print features.shape
        print y.shape
        cPickle.dump((features, y), open(filename, 'wb'))
        

    cnn = CNN(dim_in = 1, size_in = (28, 28), nkerns = [(4, (2, 2), (1, 1)), (2, (3, 3), (2, 2))])
    #fit(self, lossf, datasets, batch_size = 500, n_epochs = 200, learning_rate = 0.01):

#    examinate(cnn)
#    dump2file(cnn, './features/1_random.feature')

    examinate(cnn)
    cnn.set_lossf(core.loss_functions.TEST_LOSS_F)
    cnn.fit(datasets, batch_size = 200, n_epochs = 100, learning_rate = 0.0001)
    examinate(cnn)

#    dump2file(cnn, './features/1_trained.feature')



예제 #2
0
        features = features0 - features1  

        cPickle.dump((features, y), open(filename, 'wb'))
        

    cnn1 = CNN(dim_in = 1, size_in = (32, 32), nkerns = [(8, (2, 2), (1, 1)), (6, (3, 3), (2, 2))])
    cnn2 = CNN(dim_in = 1, size_in = (32, 32), nkerns = [(8, (2, 2), (1, 1)), (6, (3, 3), (2, 2))])
    #fit(self, lossf, datasets, batch_size = 500, n_epochs = 200, learning_rate = 0.01):

#    examinate(cnn)

    examinate(cnn1, cnn2)
    dump2file(cnn1, cnn2, './features/1_random.feature')

    for i in range(4):
        print 'The %03dth updating' % i
        loss = core.loss_functions.lossf3(cnn1, cnn2.get_feature(datasets1[0][0]))
        cnn1.set_lossf(loss)
        cnn1.fit(datasets0, batch_size = 50, n_epochs = 5, learning_rate = 0.00001, test_model_on = 0)

        loss = core.loss_functions.lossf3(cnn2, cnn1.get_feature(datasets1[0][0]))
        cnn2.set_lossf(loss)
        cnn2.fit(datasets1, batch_size = 50, n_epochs = 5, learning_rate = 0.00001, test_model_on = 0)

    examinate(cnn1, cnn2)
    dump2file(cnn1, cnn2, './features/1_trained.feature')