0
$\begingroup$

I have two sets of networks:

network1:

    def network(self, input, dropout_rate):

        conv1 = tf.layers.conv2d(
            inputs = input,
            filters = 64,
            kernel_size = [3, 3],
            padding = 'same',
            activation = tf.nn.relu,
            name = 'conv1')

        conv2 = tf.layers.conv2d(
            inputs = conv1,
            filters = 64,
            kernel_size = [3, 3],
            padding = 'same',
            activation = tf.nn.relu,
            name = 'conv2')

        pool1 = tf.layers.max_pooling2d(
            inputs = conv2,
            pool_size = [2, 2],
            strides = [2, 2],
            name = 'pool1')

        pool1_dropout = tf.layers.dropout(
            inputs = pool1,
            rate = dropout_rate,
            training=True,
            name = 'pool1_dropout')

        conv3 = tf.layers.conv2d(
            inputs = pool1_dropout,
            filters = 128,
            kernel_size = [3, 3],
            padding = 'same',
            activation = tf.nn.relu,
            name = 'conv3')

        conv4 = tf.layers.conv2d(
            inputs = conv3,
            filters = 128,
            kernel_size = [3, 3],
            padding = 'same',
            activation = tf.nn.relu,
            name = 'conv4')

        pool2 = tf.layers.max_pooling2d(
            inputs = conv4,
            pool_size = [2, 2],
            strides = [2, 2],
            name = 'pool2')

        pool2_dropout = tf.layers.dropout(
            inputs = pool2,
            rate = dropout_rate,
            training=True,
            name = 'pool2_dropout')

        conv5 = tf.layers.conv2d(
            inputs = pool2_dropout,
            filters = 256,
            kernel_size = [3, 3],
            padding = 'same',
            activation = tf.nn.relu,
            name = 'conv5')

        pool3 = tf.layers.max_pooling2d(
            inputs = conv5,
            pool_size = [2, 2],
            strides = [2, 2],
            name = 'pool3')

        pool3_dropout = tf.layers.dropout(
            inputs = pool3,
            rate = dropout_rate,
            training=True,
            name = 'pool3_dropout')

        flat = tf.layers.flatten(
            inputs = pool3_dropout, 
            name = 'flat')

        fc1 = tf.layers.dense(
            inputs = flat,
            units = 256,
            activation = tf.nn.relu,
            name = 'fc1')

        fc1_dropout = tf.layers.dropout(
            inputs = fc1,
            rate = dropout_rate,
            training=True,
            name = 'fc1_dropout')

        fc2 = tf.layers.dense(
            inputs = fc1_dropout,
            units = self.num_classes,
            activation = None,
            name = 'fc2')

        # Give output node a 
        output = tf.identity(fc2, name='output')

        return output

network2:

    def network(self, input):

      conv1 = tf.layers.conv2d(
          inputs = input,
          filters = 64,
          kernel_size = [9, 66],
        #   padding = [[0, 0], [1, 1], [1, 1], [0,0]],
          padding = "valid",
          activation = tf.nn.relu,
          name = 'conv1')

      pool1 = tf.layers.max_pooling2d(
          inputs = conv1,
          pool_size = [3, 1],
          strides = [3, 1],
          name = 'pool1')

    #   pool1_dropout = tf.layers.dropout(
    #       inputs = pool1,
    #       rate = 0.4,
    #       training=True,
    #       name = 'pool1_dropout')

      conv2 = tf.layers.conv2d(
          inputs = pool1,
          filters = 64,
          kernel_size = [4, 33],
        #   padding = [[0, 0], [1, 1], [1, 1], [0,0]],
          padding = "valid",
          activation = tf.nn.relu,
          name = 'conv2')

      conv2_dropout = tf.layers.dropout(
          inputs = conv2,
          rate = 0.4,
          training=True,
          name = 'conv2_dropout')

      fc1 = tf.layers.dense(
          inputs = self.flatten(conv2_dropout),
          units = 256,
          activation = tf.nn.relu,
          name = 'fc1')

    #   fc1_dropout = tf.layers.dropout(
    #       inputs = fc1,
    #       rate = 0.2,
    #       training=True,
    #       name = 'fc1_dropout')

      fc2 = tf.layers.dense(
          inputs = fc1,
          units = self.num_classes,
          activation = tf.nn.softmax,
          name = 'fc2')

      # Give output node a 
      output = tf.identity(fc2, name='output')

      return output

When I train model using network1 on mnist data, trained model has following operation counts:

9 Const, 9 Identity, 4 BiasAdd, 3 Relu, 2 MatMul, 2 MaxPool, 2 Conv2D, 1 Placeholder, 1 Reshape, 1 Softmax

When I train model using network2 on some proprietary data, trained model has following operation counts:

14 Const, 9 Identity, 4 BiasAdd, 3 Mul, 3 Relu, 2 Sub, 2 Conv2D, 2 MatMul, 1 MaxPool, 1 GreaterEqual, 1 Placeholder, 1 RandomUniform, 1 RealDiv, 1 Cast, 1 Reshape, 1 Shape, 1 Sigmoid, 1 Add

My question is how tensorflow uses underlying operations while creating a network? And is there any way to control these operations?

I want to put network on edge device and library supports only few operations. Model trained with network1 has all supported operations but model trained with network2 have some unsupported operations. So How can I train model such that my final model doesn't have unsupported operation such as RandomUniform ?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.