def __init__(self,
              channel_1_num,
              channel_2_num,
              conv_size,
              hidden_size,
              pool_size,
              learning_rate,
              x_dim=784,
              y_dim=10):
     self.channel_1_num = channel_1_num
     self.channel_2_num = channel_2_num
     self.conv_size = nni.choice(2, 3, 5, 7, name='self.conv_size')
     self.hidden_size = nni.choice(124, 512, 1024, name='self.hidden_size')
     self.pool_size = pool_size
     self.learning_rate = nni.uniform(0.0001,
                                      0.1,
                                      name='self.learning_rate')
     self.x_dim = x_dim
     self.y_dim = y_dim
     self.images = tf.placeholder(tf.float32, [None, self.x_dim],
                                  name='input_x')
     self.labels = tf.placeholder(tf.float32, [None, self.y_dim],
                                  name='input_y')
     self.keep_prob = tf.placeholder(tf.float32, name='keep_prob')
     self.train_step = None
     self.accuracy = None
Esempio n. 2
0
 def __init__(self,
              channel_1_num=32,
              channel_2_num=64,
              conv_size=5,
              hidden_size=1024,
              pool_size=2,
              learning_rate=0.0001,
              x_dim=784,
              y_dim=10):
     self.channel_1_num = channel_1_num
     self.channel_2_num = channel_2_num
     self.conv_size = nni.choice({
         2: 2,
         3: 3,
         5: 5,
         7: 7
     },
                                 name='self.conv_size')
     self.hidden_size = nni.choice({
         124: 124,
         512: 512,
         1024: 1024
     },
                                   name='self.hidden_size')
     self.pool_size = pool_size
     self.learning_rate = nni.randint(2, 3, 5, name='self.learning_rate')
     self.x_dim = x_dim
     self.y_dim = y_dim
Esempio n. 3
0
def main():
    data_dir = '/tmp/tensorflow/mnist/input_data'
    mnist = input_data.read_data_sets(data_dir, one_hot=True)
    logger.debug('Mnist download data down.')
    mnist_network = MnistNetwork()
    mnist_network.build_network()
    logger.debug('Mnist build network done.')
    graph_location = tempfile.mkdtemp()
    logger.debug('Saving graph to: %s' % graph_location)
    train_writer = tf.summary.FileWriter(graph_location)
    train_writer.add_graph(tf.get_default_graph())
    test_acc = 0.0
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        batch_num = 200
        for i in range(batch_num):
            batch_size = nni.choice(50, 250, 500, name='batch_size')
            batch = mnist.train.next_batch(batch_size)
            dropout_rate = nni.choice(1, 5, name='dropout_rate')
            mnist_network.train_step.run(feed_dict={mnist_network.x: batch[
                0], mnist_network.y: batch[1], mnist_network.keep_prob:
                dropout_rate})
            if i % 100 == 0:
                test_acc = mnist_network.accuracy.eval(feed_dict={
                    mnist_network.x: mnist.test.images, mnist_network.y:
                    mnist.test.labels, mnist_network.keep_prob: 1.0})
                nni.report_intermediate_result(test_acc)
        test_acc = mnist_network.accuracy.eval(feed_dict={mnist_network.x:
            mnist.test.images, mnist_network.y: mnist.test.labels,
            mnist_network.keep_prob: 1.0})
        nni.report_final_result(test_acc)
Esempio n. 4
0
def main(params):
    '''
    Main function, build mnist network, run and send result to NNI.
    '''
    # Import data
    mnist = download_mnist_retry(params['data_dir'])
    print('Mnist download data done.')
    logger.debug('Mnist download data done.')

    # Create the model
    # Build the graph for the deep net
    mnist_network = MnistNetwork(channel_1_num=params['channel_1_num'],
                                 channel_2_num=params['channel_2_num'],
                                 pool_size=params['pool_size'])
    mnist_network.build_network()
    logger.debug('Mnist build network done.')

    # Write log
    graph_location = tempfile.mkdtemp()
    logger.debug('Saving graph to: %s', graph_location)
    train_writer = tf.summary.FileWriter(graph_location)
    train_writer.add_graph(tf.get_default_graph())

    test_acc = 0.0
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        batch_num = nni.choice(50, 250, 500, name='batch_num')
        for i in range(batch_num):
            batch = mnist.train.next_batch(batch_num)
            dropout_rate = nni.choice(1, 5, name='dropout_rate')
            mnist_network.train_step.run(
                feed_dict={
                    mnist_network.images: batch[0],
                    mnist_network.labels: batch[1],
                    mnist_network.keep_prob: dropout_rate
                })

            if i % 100 == 0:
                test_acc = mnist_network.accuracy.eval(
                    feed_dict={
                        mnist_network.images: mnist.test.images,
                        mnist_network.labels: mnist.test.labels,
                        mnist_network.keep_prob: 1.0
                    })

                nni.report_intermediate_result(test_acc)
                logger.debug('test accuracy %g', test_acc)
                logger.debug('Pipe send intermediate result done.')

        test_acc = mnist_network.accuracy.eval(
            feed_dict={
                mnist_network.images: mnist.test.images,
                mnist_network.labels: mnist.test.labels,
                mnist_network.keep_prob: 1.0
            })

        nni.report_final_result(test_acc)
        logger.debug('Final result is %g', test_acc)
        logger.debug('Send final result done.')
Esempio n. 5
0
 def test_specified_name(self):
     val = nni.choice({'a': 'a', '3*2+1': 3*2+1, '[1, 2]': [1, 2], '{"a", 2}': {"a", 2}}, name = 'choice1', key='test_smartparam/choice1/choice')
     self.assertEqual(val, 'a')
     val = nni.choice({'a': 'a', '3*2+1': 3*2+1, '[1, 2]': [1, 2], '{"a", 2}': {"a", 2}}, name = 'choice2', key='test_smartparam/choice2/choice')
     self.assertEqual(val, 7)
     val = nni.choice({'a': 'a', '3*2+1': 3*2+1, '[1, 2]': [1, 2], '{"a", 2}': {"a", 2}}, name = 'choice3', key='test_smartparam/choice3/choice')
     self.assertEqual(val, [1, 2])
     val = nni.choice({'a': 'a', '3*2+1': 3*2+1, '[1, 2]': [1, 2], '{"a", 2}': {"a", 2}}, name = 'choice4', key='test_smartparam/choice4/choice')
     self.assertEqual(val, {"a", 2})
Esempio n. 6
0
 def test_specified_name(self):
     val = nni.choice(
         {
             'a': 'a',
             '3*2+1': 3 * 2 + 1,
             '[1, 2]': [1, 2],
             '{"a", 2}': {"a", 2}
         },
         name='choice1')
     self.assertEqual(val, 'a')
     val = nni.choice(
         {
             'a': 'a',
             '3*2+1': 3 * 2 + 1,
             '[1, 2]': [1, 2],
             '{"a", 2}': {"a", 2}
         },
         name='choice2')
     self.assertEqual(val, 7)
     val = nni.choice(
         {
             'a': 'a',
             '3*2+1': 3 * 2 + 1,
             '[1, 2]': [1, 2],
             '{"a", 2}': {"a", 2}
         },
         name='choice3')
     self.assertEqual(val, [1, 2])
     val = nni.choice(
         {
             'a': 'a',
             '3*2+1': 3 * 2 + 1,
             '[1, 2]': [1, 2],
             '{"a", 2}': {"a", 2}
         },
         name='choice4')
     self.assertEqual(val, {"a", 2})
Esempio n. 7
0
 def test_specified_name(self):
     val = nni.choice('a', 'b', 'c', name='choice1')
     self.assertEqual(val, 'c')
Esempio n. 8
0
import nni


def max_pool(k):
    pass


h_conv1 = 1
conv_size = nni.choice(2, 3, 5, 7, name='conv_size')
h_pool1 = nni.function_choice(lambda: max_pool(h_conv1),
                              lambda: avg_pool(h_conv2, h_conv3),
                              name='max_pool')
test_acc = 1
nni.report_intermediate_result(test_acc)
test_acc = 2
nni.report_final_result(test_acc)
Esempio n. 9
0
import nni


def max_pool(k):
    pass


h_conv1 = 1
nni.choice({'foo': foo, 'bar': bar})(1)
conv_size = nni.choice({2: 2, 3: 3, 5: 5, 7: 7}, name='conv_size')
abc = nni.choice({'2': '2', 3: 3, '(5 * 6)': 5 * 6, 7: 7}, name='abc')
h_pool1 = nni.function_choice({
    'max_pool': lambda: max_pool(h_conv1),
    'h_conv1': lambda: h_conv1,
    'avg_pool': lambda: avg_pool(h_conv2, h_conv3)
})
h_pool1 = nni.function_choice(
    {
        'max_pool(h_conv1)': lambda: max_pool(h_conv1),
        'avg_pool(h_conv2, h_conv3)': lambda: avg_pool(h_conv2, h_conv3)
    },
    name='max_pool')
h_pool2 = nni.function_choice(
    {
        'max_poo(h_conv1)': lambda: max_poo(h_conv1),
        '(2 * 3 + 4)': lambda: 2 * 3 + 4,
        '(lambda x: 1 + x)': lambda: lambda x: 1 + x
    },
    name='max_poo')
tmp = nni.qlognormal(1.2, 3, 4.5)
test_acc = 1
Esempio n. 10
0
import nni


def max_pool(k):
    pass


h_conv1 = 1
conv_size = nni.choice({2: 2, 3: 3, 5: 5, 7: 7}, name='conv_size')
abc = nni.choice(
    {
        '2': '2',
        3: 3,
        '(5 * 6)': 5 * 6,
        "{(1): 2, '3': 4}": {
            (1): 2,
            '3': 4
        },
        '[1, 2, 3]': [1, 2, 3]
    },
    name='abc')
h_pool1 = nni.function_choice(
    {
        'max_pool(h_conv1)': lambda: max_pool(h_conv1),
        'avg_pool(h_conv2, h_conv3)': lambda: avg_pool(h_conv2, h_conv3)
    },
    name='max_pool')
h_pool2 = nni.function_choice(
    {
        'max_poo(h_conv1)': lambda: max_poo(h_conv1),
        '(2 * 3 + 4)': lambda: 2 * 3 + 4,