Пример #1
0
    # deal with dropout
    do_dropout = False
    dropout_factor = [0.0]
    input_dropout_factor = 0.0
    if arguments.has_key('dropout_factor'):
        do_dropout = True
        if arguments.has_key('input_dropout_factor'):
            input_dropout_factor = float(arguments['input_dropout_factor'])
        dropout_factor = []
        factors = arguments['dropout_factor'].split(',')
        for n in xrange(len(factors)):
            dropout_factor.append(float(factors[n]))

    train_dataset, train_dataset_args = read_data_args(train_data_spec)
    valid_dataset, valid_dataset_args = read_data_args(valid_data_spec)
    train_sets, train_xy, train_x, train_y = read_dataset(train_dataset, train_dataset_args)
    valid_sets, valid_xy, valid_x, valid_y = read_dataset(valid_dataset, valid_dataset_args)

    numpy_rng = numpy.random.RandomState(89677)
    theano_rng = RandomStreams(numpy_rng.randint(2 ** 30))
    log('> ... building the model')
    if do_dropout:
        dnn = DNN_Dropout(numpy_rng=numpy_rng, theano_rng = theano_rng, n_ins=n_ins,
              hidden_layers_sizes=hidden_layers_sizes, n_outs=n_outs,
              activation = activation, dropout_factor = dropout_factor, input_dropout_factor = input_dropout_factor,
              do_maxout = do_maxout, pool_size = pool_size,
              max_col_norm = max_col_norm, l1_reg = l1_reg, l2_reg = l2_reg)
    else:
        dnn = DNN(numpy_rng=numpy_rng, theano_rng = theano_rng, n_ins=n_ins,
              hidden_layers_sizes=hidden_layers_sizes, n_outs=n_outs,
              activation = activation, do_maxout = do_maxout, pool_size = pool_size,
Пример #2
0
    n_outs = int(nnet_layers[-1])

    ptr_layer_number = len(hidden_layers_sizes)
    if arguments.has_key('ptr_layer_number'):
        ptr_layer_number = int(arguments['ptr_layer_number'])

    first_layer_gb = True
    if arguments.has_key('first_layer_type'):
        if arguments['first_layer_type'] == 'bb':
            first_layer_gb = False

    # if initialized with current
    keep_layer_num=0
    current_nnet = wdir + 'nnet.ptr.current'
  
    train_sets, train_xy, train_x, train_y = read_dataset(dataset, dataset_args)

    # numpy random generator
    numpy_rng = numpy.random.RandomState(89677)
    theano_rng = RandomStreams(numpy_rng.randint(2 ** 30))
    log('> ... building the model')
    # construct the stacked denoising autoencoder class
    srbm = SRBM(numpy_rng=numpy_rng, theano_rng = theano_rng, n_ins=n_ins,
              hidden_layers_sizes=hidden_layers_sizes,
              n_outs=n_outs, first_layer_gb = first_layer_gb)

    if keep_layer_num > 0:
        log('> ... initializing model from ' + current_nnet)
        _file2nnet(srbm.sigmoid_layers, set_layer_num = keep_layer_num, filename = current_nnet, withfinal=False)

    # PRETRAINING THE MODEL #