Ejemplo n.º 1
0
def model(th):
  assert isinstance(th, m.Config)
  model = m.get_container(th, flatten=True)
  model.add(Dense(th.layer_width, th.spatial_activation))
  model.add(Highway(
    th.layer_width, th.num_layers, th.spatial_activation,
    t_bias_initializer=th.bias_initializer))
  # model.register_extractor(m.LinearHighway.extractor)
  return m.finalize(th, model)
Ejemplo n.º 2
0
def output_and_build(model, th):
    assert isinstance(model, Classifier)
    assert isinstance(th, Config)
    # Add dropout if necessary
    if th.output_dropout > 0: model.add(Dropout(1 - th.output_dropout))
    # Add output layer
    model.add(Dense(num_neurons=th.output_dim))
    model.add(Activation('softmax'))

    model.build(loss='cross_entropy', metric='bpc', batch_metric='bpc')
Ejemplo n.º 3
0
def output_and_build(model, th):
    assert isinstance(model, Classifier)
    assert isinstance(th, Config)
    # Add output layer
    model.add(Dense(num_neurons=th.output_dim))
    model.add(Activation('softmax'))

    model.build(metric='gen_acc',
                batch_metric='gen_acc',
                val_targets='val_targets')
Ejemplo n.º 4
0
def output_and_build(model, th):
    assert isinstance(model, Classifier) and isinstance(th, Config)
    # Add output dropout if necessary
    if th.output_dropout > 0: model.add(Dropout(1 - th.output_dropout))
    # Add output layer
    model.add(Dense(num_neurons=th.output_dim))
    model.add(Activation('softmax'))

    # Build model
    model.build(loss=th.loss_string, metric=['loss', 'f1'], batch_metric='f1')
Ejemplo n.º 5
0
 def _get_layers(self):
   layers = []
   # Add conv layers
   for n in self.conv_list: layers.append(Conv2D(
     n, self.kernel_size, strides=self.strides,
     padding=self.padding, activation=self.activation))
   # Add flatten layer
   layers.append(Flatten())
   # Add fully-connected layers
   for n in self.fc_list: layers.append(Dense(n ,activation=self.activation))
   return layers
Ejemplo n.º 6
0
def output_and_build(model, th):
    assert isinstance(model, Classifier)
    assert isinstance(th, Config)
    # Add dropout if necessary
    if th.output_dropout > 0: model.add(Dropout(1 - th.output_dropout))
    # Add output layer
    model.add(Dense(num_neurons=th.output_dim))
    model.add(Activation('softmax'))

    model.build(last_only=True,
                metric=['accuracy', 'loss'],
                batch_metric='accuracy',
                eval_metric='accuracy')
Ejemplo n.º 7
0
def model(th):
  assert isinstance(th, m.Config)
  model = m.get_container(th, flatten=True)
  model.add(Dense(th.layer_width, th.spatial_activation))
  model.add(SLHighway(
    config_string=th.group_string,
    num_layers=th.num_layers,
    head_size=th.head_size,
    activation=th.spatial_activation,
    gutter=th.gutter,
    gutter_bias=th.gutter_bias,
  ))
  model.register_extractor(SLHighway.extractor)
  return m.finalize(th, model)
Ejemplo n.º 8
0
def typical(th, cells):
    assert isinstance(th, Config)

    # Initiate a model
    model = Classifier(mark=th.mark, net_type=Recurrent)

    # Add layers
    model.add(Input(sample_shape=th.input_shape, dtype=tf.int32))
    model.add(Onehot(depth=th.num_classes))
    emb_init = tf.initializers.random_uniform(-1, 1)
    model.add(Dense(th.hidden_dim, use_bias=False,
                    weight_initializer=emb_init))

    if th.input_dropout > 0: model.add(Dropout(1 - th.input_dropout))
    # Add hidden layers
    if not isinstance(cells, (list, tuple)): cells = [cells]
    for cell in cells:
        model.add(cell)
    # Build model and return
    output_and_build(model, th)
    return model