class_docstr: MnistNetwork is for initializing and building basic network for mnist.
class_docstr_tok: ["MnistNetwork","is","for","initializing","and","building","basic","network","for","mnist","."]
docstr: Building network for mnist
docstr_tok: ["Building","network","for","mnist"]
code: def build_network(self):
      """
      Building network for mnist
      """
  
      # Reshape to use within a convolutional neural net.
      # Last dimension is for "features" - there is only one here, since images are
      # grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
      with tf.name_scope("reshape"):
          try:
              input_dim = int(math.sqrt(self.x_dim))
          except:
              print(
                  "input dim cannot be sqrt and reshape. input dim: "
                  + str(self.x_dim)
              )
              logger.debug(
                  "input dim cannot be sqrt and reshape. input dim: %s",
                  str(self.x_dim),
              )
              raise
          x_image = tf.reshape(
              self.images, [-1, input_dim, input_dim, 1]
          )
  
      # First convolutional layer - maps one grayscale image to 32 feature maps.
      with tf.name_scope("conv1"):
          w_conv1 = weight_variable(
              [self.conv_size, self.conv_size, 1, self.channel_1_num]
          )
          b_conv1 = bias_variable([self.channel_1_num])
          h_conv1 = tf.nn.relu(conv2d(x_image, w_conv1) + b_conv1)
  
      # Pooling layer - downsamples by 2X.
      with tf.name_scope("pool1"):
          h_pool1 = max_pool(h_conv1, self.pool_size)
  
      # Second convolutional layer -- maps 32 feature maps to 64.
      with tf.name_scope("conv2"):
          w_conv2 = weight_variable(
              [
                  self.conv_size,
                  self.conv_size,
                  self.channel_1_num,
                  self.channel_2_num,
              ]
          )
          b_conv2 = bias_variable([self.channel_2_num])
          h_conv2 = tf.nn.relu(conv2d(h_pool1, w_conv2) + b_conv2)
  
      # Second pooling layer.
      with tf.name_scope("pool2"):
          h_pool2 = max_pool(h_conv2, self.pool_size)
  
      # Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
      # is down to 7x7x64 feature maps -- maps this to 1024 features.
      last_dim = int(input_dim / (self.pool_size * self.pool_size))
      with tf.name_scope("fc1"):
          w_fc1 = weight_variable(
              [
                  last_dim * last_dim * self.channel_2_num,
                  self.hidden_size,
              ]
          )
          b_fc1 = bias_variable([self.hidden_size])
  
      h_pool2_flat = tf.reshape(
          h_pool2, [-1, last_dim * last_dim * self.channel_2_num]
      )
      h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, w_fc1) + b_fc1)
  
      # Dropout - controls the complexity of the model, prevents co-adaptation of features.
      with tf.name_scope("dropout"):
          h_fc1_drop = tf.nn.dropout(h_fc1, self.keep_prob)
  
      # Map the 1024 features to 10 classes, one for each digit
      with tf.name_scope("fc2"):
          w_fc2 = weight_variable([self.hidden_size, self.y_dim])
          b_fc2 = bias_variable([self.y_dim])
          y_conv = tf.matmul(h_fc1_drop, w_fc2) + b_fc2
  
      with tf.name_scope("loss"):
          cross_entropy = tf.reduce_mean(
              tf.nn.softmax_cross_entropy_with_logits(
                  labels=self.labels, logits=y_conv
              )
          )
      with tf.name_scope("adam_optimizer"):
          self.train_step = tf.train.AdamOptimizer(
              self.learning_rate
          ).minimize(cross_entropy)
  
      with tf.name_scope("accuracy"):
          correct_prediction = tf.equal(
              tf.argmax(y_conv, 1), tf.argmax(self.labels, 1)
          )
          self.accuracy = tf.reduce_mean(
              tf.cast(correct_prediction, tf.float32)
          )
  
file_path: nni/examples/trials/mnist-tfv1/mnist_before.py
imports: import argparse
  import logging
  import math
  import tempfile
  import time
  import tensorflow
  from tensorflow.examples.tutorials.mnist import input_data
label_desc: Use image node_id 2 for calling the MnistNetwork obj's underlying member method code with example usage: obj.build_network() without return types