title: How to load the pre-trained model of the tensorflow by using the opencv dnn model
body: <p>The readNetFromTensorflow function fails to load the tensorflow pre-trained model (.pb). </p>
  
  <p>Step 1: training the model of the tensorflow.
  Tensorflow model of linear regression codes as following:</p>
  
  <pre><code>#!/usr/bin/python
  import tensorflow as tf
  import numpy as np
  x_ = tf.placeholder(np.float32, [None, 1], 'input')
  y_ = tf.placeholder(np.float32, [None, 1], 'label')
  #layer1
  w1 = tf.Variable(tf.random_normal([1,3]))
  b1 = tf.Variable(tf.random_normal([3]) )
  a1 = tf.add(b1,tf.matmul(x_,w1)) 
  #layer2
  w2 = tf.Variable(tf.random_normal([3,1]))
  b2 = tf.Variable(tf.random_normal([1]) )
  a2 = tf.add(b2,tf.matmul(a1,w2),name="output") 
  #global steps
  steps = 5000 
  x = []
  y = []
  for i in range(1,200,5):
      temp = (1.0 * i)/10
      x.append([temp])
      y.append([3. + 2. * temp])
  x = np.array(x)
  y = np.array(y)
  #loss function
  loss =  tf.reduce_mean(tf.reduce_sum(tf.square(a2-y_)))
  #optimizer
  optimizer = tf.train.GradientDescentOptimizer(0.00001).minimize(loss)
  with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      length = len(x)
      #training...
      for i in range(steps):
          sess.run(optimizer,feed_dict={x_:x,y_:y})
          result = sess.run(loss,feed_dict={x_:x,y_:y})
          if i % 50 == 0:
              print("loss: ",result,"\tstep: ",i)
      saver = tf.train.Saver()
      saver.save(sess,"./model/model.ckpt")
      tf.train.write_graph(sess.graph.as_graph_def(), "./model/", "graph.pbtxt")
      print("predict...")
      pre = sess.run(a2,feed_dict={x_:[[0]]})
      print("x = 2 pre: ",pre)
  </code></pre>
  
  <p>Step 2: Save the model as the .pb file of the tensorflow. How to do that?</p>
  
  <p>Step 3: Load the .pb file by using the function readNetFromTensorflow of the  opencv3.4.1 with C++. The codes like that:</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;opencv2/dnn.hpp&gt;
  #include &lt;opencv2/imgproc.hpp&gt;
  #include &lt;opencv2/highgui.hpp&gt;
  using namespace std;
  using namespace cv;
  using namespace dnn;
  
  std::vector&lt;std::string&gt; classes;
  
  int main(int argc,char**argv)
  {
      if(argc != 2)
      {
          cout&lt;&lt;"Usage: ./main [tensorflow modle path(.pb)]"&lt;&lt;endl;
          return -1;
      }
      String model = argv[1];
      Net net = cv::dnn::readNetFromTensorflow(model,argv[2]);
      cout&lt;&lt;"load Net OK!!"&lt;&lt;endl;
  
      float inp[1*1] = {2};
      Mat Matrix(1,1,CV_32FC1,inp);
      cout&lt;&lt;"Matrix:\n"&lt;&lt;Matrix&lt;&lt;endl;
      net.setInput(Matrix);
  
      Mat output = net.forward();
      cout&lt;&lt;"output: " &lt;&lt; output &lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>The result should be 7. 
  There are two questions. First is how to generate a complete .pb file of the trained model, and another is how to use the pre-trained model in opencv3.4.1 dnn with C++?</p>