title: How to prune weights in Tensorflow CNN model (Without migrating model to Keras)
body: <p>I have a TF CNN model and now I want to use the weight pruning API of tensor flow with this but all the examples I checked online, it works only with Keras model </p>
  
  <p>I want to prune wights of my existing model</p>
  
  <pre><code>def mnist_cnn(inputs):
      input_layer = tf.reshape(inputs, [-1, 28, 28, 3])
  
      # Convolutional Layer #1
      conv1 = tf.layers.conv2d(
            inputs=input_layer,
            filters=32,
            kernel_size=[5, 5],
            padding="same",
            activation=tf.nn.relu)
  
      # Pooling Layer #1
      pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)
  
      # Convolutional Layer #2 and Pooling Layer #2
      conv2 = tf.layers.conv2d(
            inputs=pool1,
            filters=64,
            kernel_size=[5, 5],
            padding="same",
            activation=tf.nn.relu)
      pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2)
  
      # Dense Layer
      pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64])
      dense = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu)
      dropout = tf.layers.dropout(inputs=dense, rate=0.4)
  
      # Logits Layer
      outputs = tf.layers.dense(inputs=dropout, units=10)
  
      return outputs
  </code></pre>
  
  <p>This tutorial defines weight pruning
  <a href="https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_keras" rel="nofollow noreferrer">https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_keras</a></p>
  
  <p>but I can't figure out how to use Pruning APIs with my exiting model ( without upgrading it to keras sequential model )</p>