title: I have a problem in freezing the graph for a CNN model for image classification
body: <p>I built a CNN model for image classification, I want to use it in an android application so I figured that I need to freeze the graph and save it in .pb format.
  I'm trying to use this function to achieve this :</p>
  
  <pre><code>MODEL_NAME = 'cnn_model'
  def export_model(saver, model, input_node_names, output_node_name):
      tf.train.write_graph(tf.keras.backend.get_session().graph_def, 'out', \
                          MODEL_NAME + '_graph.pbtxt')
  
      saver.save(tf.keras.backend.get_session(), 'out/' + MODEL_NAME  +'.chkp')
  
      freeze_graph.freeze_graph('out/' + MODEL_NAME + '_graph.pbtxt', None, \
                                False, 'out/' + MODEL_NAME + '.chkp', output_node_name, \
                                "save/restore_all", "save/Const:0", \
                                'out/frozen_' + MODEL_NAME + '.pb', True, "")
  
      input_graph_def = tf.GraphDef()
      with tf.gfile.Open('out/frozen_' + MODEL_NAME+ '.pb', "rb") as f:
          input_graph_def.ParseFromString(f.read())
  
      output_graph_def = optimize_for_inference_lib.optimize_for_inference(
              input_graph_def, input_node_names, [output_node_name],
              tf.float32.as_datatype_enum)
  
      with tf.gfile.FastGFile('out/opt_' + MODEL_NAME +'.pb', "wb")as f:
          f.write(output_graph_def.SerializeToString())
  
      print("graph saved!")
  
      return 
  </code></pre>
  
  <p>and this is how I called the method :</p>
  
  <pre><code>export_model(tf.train.Saver(), classifier , ["conv2d_6_input_2"], "dense_5_2/Softmax")      
  </code></pre>
  
  <p>after calling the method five files are produced:</p>
  
  <ul>
  <li>checkpoint</li>
  <li>cnn_model.chkp.data-00000-of-00001</li>
  <li>cnn_model.chkp.index</li>
  <li>cnn_model.chkp.meta</li>
  <li>cnn_model_graph.pbtxt</li>
  </ul>
  
  <p>but after that this error occurs</p>
  
  <pre><code>---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  &lt;ipython-input-98-39ddde1e67a7&gt; in &lt;module&gt;()
  ----&gt; 1 export_model(tf.train.Saver(), classifier , ["conv2d_6_input_2"], "dense_5_2/Softmax")
  
  10 frames
  /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in __getitem__(self, i)
     2152 
     2153     def __getitem__(self, i):
  -&gt; 2154       return self._inputs[i]
     2155 
     2156   @property
  
  IndexError: list index out of range
  </code></pre>
  
  <p>This is the CNN layers :</p>
  
  <pre><code># Initialing the CNN
  classifier = Sequential()
  
  # Step 1 - Convolutio Layer
  classifier.add(Convolution2D(32, 3,  3, input_shape = (64, 64, 3), activation = 'relu' ,padding='same'))
  
  #step 2 - Pooling
  classifier.add(MaxPooling2D((2,2), padding='same'))
  
  # Adding second convolution layer
  classifier.add(Convolution2D(32, 3,  3, activation = 'relu' ,padding='same'))
  classifier.add(MaxPooling2D((2,2), padding='same'))
  
  #Adding 3rd Concolution Layer
  classifier.add(Convolution2D(64, 3,  3, activation = 'relu' ,padding='same'))
  classifier.add(MaxPooling2D((2,2), padding='same'))
  
  
  #Step 3 - Flattening
  classifier.add(Flatten())
  
  #Step 4 - Full Connection
  classifier.add(Dense(256, activation = 'relu'))
  classifier.add(Dropout(0.5))
  classifier.add(Dense(26, activation = 'softmax'))
  </code></pre>
  
  <p>Any help would be so much appreciated as I'm new to machine learning and deep learning and this error has been persisting for days. </p>