예제 #1
0
def nn_mnist_model(graph):
    """Creates model for NN mnist.

  Returns:
    logits
  """
    with graph.as_default():
        is_train = tf.placeholder(tf.bool, shape=(), name='is_train')

    n_inputs = 28 * 28
    n_hidden1 = 300
    n_hidden2 = 100
    n_outputs = 10

    with graph.as_default():
        with tf.name_scope('Inputs'):
            with tf.name_scope('X'):
                X = tf.placeholder(DTYPE, shape=(None, n_inputs), name='X')  # pylint: disable=invalid-name
            with tf.name_scope('y'):
                y = tf.placeholder(tf.int64, shape=(None), name='y')  # pylint: disable=invalid-name

        hidden1 = nn_layer(X, n_hidden1, name='hidden1', activation=tf.nn.relu)  # pylint: disable=no-member

        hidden2 = nn_layer(hidden1,
                           n_hidden2,
                           name='hidden2',
                           activation=tf.nn.relu)  # pylint: disable=no-member

        logits = nn_layer(hidden2, n_outputs, name='logits')

    return X, y, is_train, logits
예제 #2
0
def nn_mnist_model_small_with_dropout(graph):
    with graph.as_default():
        is_train = tf.placeholder(tf.bool, shape=(), name='is_train')
    n_inputs = 28 * 28
    n_hidden1 = 5
    n_hidden2 = 5
    n_outputs = 10
    with graph.as_default():
        with tf.name_scope('Inputs'):
            with tf.name_scope('X'):
                X = tf.placeholder(DTYPE, shape=(None, n_inputs), name='X')  # pylint: disable=invalid-name
            with tf.name_scope('y'):
                y = tf.placeholder(tf.int64, shape=(None), name='y')  # pylint: disable=invalid-name

        keep_prob = tf.placeholder(DTYPE, name='keep_prob')

        hidden1 = nn_layer(X, n_hidden1, name='hidden1', activation=tf.nn.relu)  # pylint: disable=no-member

        hidden1_dropout = tf.nn.dropout(hidden1, keep_prob)

        hidden2 = nn_layer(hidden1_dropout,
                           n_hidden2,
                           name='hidden2',
                           activation=tf.nn.relu)  # pylint: disable=no-member

        hidden2_dropout = tf.nn.dropout(hidden2, keep_prob)

        logits = nn_layer(hidden2, n_outputs, name='logits')

    return X, y, is_train, keep_prob, logits
예제 #3
0
def nn_mnist_model_dropout(graph):  # pylint: disable=too-many-locals
    """Creates model for NN mnist.

  Returns:
    logits
  """
    n_inputs = 28 * 28
    n_hidden1 = 1024
    n_hidden2 = 1024
    n_hidden3 = 2048
    n_outputs = 10
    with graph.as_default():
        is_train = tf.placeholder(tf.bool, shape=(), name='is_train')
    with graph.as_default():
        with tf.name_scope('Inputs'):
            with tf.name_scope('X'):
                X = tf.placeholder(DTYPE, shape=(None, n_inputs), name='X')  # pylint: disable=invalid-name
            with tf.name_scope('y'):
                y = tf.placeholder(tf.int64, shape=(None), name='y')  # pylint: disable=invalid-name
        #with tf.name_scope('NN'):

        keep_prob = tf.placeholder(DTYPE, name='keep_prob')

        hidden1 = nn_layer(X, n_hidden1, name='hidden1', activation=tf.nn.relu)  # pylint: disable=no-member

        hidden1_dropout = tf.nn.dropout(hidden1, keep_prob)

        hidden2 = nn_layer(hidden1_dropout,
                           n_hidden2,
                           name='hidden2',
                           activation=tf.nn.relu)  # pylint: disable=no-member

        hidden2_dropout = tf.nn.dropout(hidden2, keep_prob)

        hidden3 = nn_layer(hidden2_dropout,
                           n_hidden3,
                           name='hidden3',
                           activation=tf.nn.relu)  # pylint: disable=no-member

        hidden3_dropout = tf.nn.dropout(hidden3, keep_prob)

        logits = nn_layer(hidden3_dropout, n_outputs, name='logits')
    return X, y, is_train, keep_prob, logits