Beispiel #1
0
    def create_clf(cls, data=None):
        """Create neural network."""
        try:
            bits = data.shape[1]
        except AttributeError:
            bits = cls.default_bits
        net_params = {
            "layers": [("input", InputLayer), ("inputdrop", DropoutLayer),
                       ("hidden", DenseLayer), ("hiddendrop", DropoutLayer),
                       ("output", DenseLayer)],
            "input_shape": (None, bits),
            "inputdrop_p":
            cls.input_dropout_rate,
            "hidden_num_units":
            cls.hidden_num_units,
            "hidden_nonlinearity":
            cls.hidden_nonlinearity,
            "hiddendrop_p":
            cls.hidden_dropout_rate,
            "output_num_units":
            2,
            "output_nonlinearity":
            cls.output_nonlinearity,
            "update_learning_rate":
            cls.leakiness,
            "max_epochs":
            cls.max_epochs,
            "on_epoch_finished":
            EarlyStopping(patience=cls.patience)
        }
        clf = NeuralNet(**net_params)
        if data is not None:
            batch_size = min(
                cls.max_batch_size,
                int(cls.min_percent_data_in_batch * data.shape[0]))
            clf.batch_iterator_train = BalancedClassIterator(
                batch_size=batch_size)
            clf.batch_iterator_test = BalancedClassIterator(
                batch_size=batch_size)

        return clf
Beispiel #2
0
        print(('train_labels_file = %s' % (train_labels_file)))

    print(('trained_net_file = %s' % (trained_net_file)))

    if retrain:
        print('retraining net...')
        data, labels = load2d(train_data_file, train_labels_file)
        train_net(data, labels, net13, trained_net_file)
        plot_loss(net13, outfile=join(root, 'plots', 'net13_loss.png'))
    elif test:
        print('loading net from disk...')
        with open(trained_net_file, 'rb') as ifile:
            net13 = pickle.load(ifile)
        print('loading test data...')
        data, _ = load2d(test_data_file)
        names = np.load(test_names_file)
        print('generating kaggle submission...')

        generate_submission(data, names, net13, submission_file, header_file, N=50)
    elif finetune:
        print('loading pre-trained net from disk...')
        with open(trained_net_file, 'rb') as ifile:
            net13 = pickle.load(ifile)
        print('loading training data...')
        data, labels = load2d(train_data_file, train_labels_file)
        net13.batch_iterator_train = BatchIterator(batch_size=128)
        net13.update_learning_rate = 0.00001
        net13.max_epochs = 1
        #net13.on_training_finished = [early_stopping.load_best_weights]
        train_net(data, labels, net13, finetuned_net_file)
Beispiel #3
0
    input_shape=(None, 1, PIXELS, PIXELS),
    conv1_num_filters=32, conv1_filter_size=(3, 3), pool1_ds=(2, 2),
    conv2_num_filters=64, conv2_filter_size=(2, 2), pool2_ds=(2, 2),
    hidden4_num_units=500,
    output_num_units=2, output_nonlinearity=nonlinearities.softmax,

    update_learning_rate=0.01,
    update_momentum=0.9,

    regression=False,
    max_epochs=1000,
    verbose=1,
    )

class SimpleBatchIterator(BatchIterator):

    def transform(self, Xb, yb):
        Xb, yb = super(SimpleBatchIterator, self).transform(Xb, yb)
        # The 'incomming' and outcomming shape is (batchsize, 1, 28, 28)


        return Xb[:,:,::-1,:], yb #<--- Here we do the flipping

net1.batch_iterator_train = SimpleBatchIterator(batch_size=128)
net1.fit(X, y)