<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.0.0</li>
<li>Operating System / Platform =&gt; Ubuntu 18.4</li>
<li>Compiler =&gt; gcc 7.2</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">I'm having problems trying to load a model in pb or pb&amp;pbtxt using readNetFromTensorflow.<br>
The model is a pretrained resnext network trained and exported using tflearn with code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="net = tflearn.input_data(shape=[None, 49, 49, 3], img_prep, img_aug)
net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
...
net = tflearn.fully_connected(net, 11, activation='softmax')

model = tflearn.DNN(net)
model.load(&quot;checkpoints/meta-data/model_resnext-96000&quot;)

init_op = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init_op)

tf.train.write_graph(sess.graph_def, &quot;/tmp/my-model&quot;, 'graph.pbtxt', as_text=True)
tf.train.write_graph(sess.graph, &quot;/tmp/my-model&quot;, 'graph.pb', as_text=False)"><pre class="notranslate"><code class="notranslate">net = tflearn.input_data(shape=[None, 49, 49, 3], img_prep, img_aug)
net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
...
net = tflearn.fully_connected(net, 11, activation='softmax')

model = tflearn.DNN(net)
model.load("checkpoints/meta-data/model_resnext-96000")

init_op = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init_op)

tf.train.write_graph(sess.graph_def, "/tmp/my-model", 'graph.pbtxt', as_text=True)
tf.train.write_graph(sess.graph, "/tmp/my-model", 'graph.pb', as_text=False)
</code></pre></div>
<p dir="auto">The model works perfectly fine using tflearn api (model.predict()).<br>
After that I attempted to freeze the graph and optimize it for inference:</p>
<p dir="auto">1.Freezing the graph</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python -m tensorflow.python.tools.freeze_graph --input_binary --input_graph graph.pb --output_graph frozen_graph.pb --input_checkpoint ~/datasets/TrainedNetworksTfLearn/Expression/model-resnext-no-train-ops --output_node_names FullyConnected/Softmax"><pre class="notranslate"><code class="notranslate">python -m tensorflow.python.tools.freeze_graph --input_binary --input_graph graph.pb --output_graph frozen_graph.pb --input_checkpoint ~/datasets/TrainedNetworksTfLearn/Expression/model-resnext-no-train-ops --output_node_names FullyConnected/Softmax
</code></pre></div>
<p dir="auto">2 Optimizing the graph for inference with two different ways<br>
a).using tensorflow.python.tools.optimize_for_inference:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python -m tensorflow.python.tools.optimize_for_inference --input frozen_graph_with_freeze_graph_tool.pb --output frozen_interference_graph_opt.pb --frozen_graph True --input_names InputData/X --output_names FullyConnected/Softmax"><pre class="notranslate"><code class="notranslate">python -m tensorflow.python.tools.optimize_for_inference --input frozen_graph_with_freeze_graph_tool.pb --output frozen_interference_graph_opt.pb --frozen_graph True --input_names InputData/X --output_names FullyConnected/Softmax
</code></pre></div>
<p dir="auto">b). using snippet provided by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dkurt/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dkurt">@dkurt</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import tensorflow as tf
from tensorflow.tools.graph_transforms import TransformGraph
from tensorflow.python.tools import optimize_for_inference_lib

graph = 'graph.pb'
with tf.gfile.FastGFile(graph, &quot;rb&quot;) as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.summary.FileWriter('logs', graph_def)

    inp_node = 'InputData/X'
    out_node = 'FullyConnected/Softmax'
    graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, [inp_node], [out_node],
                                                                  tf.float32.as_datatype_enum)
    graph_def = TransformGraph(graph_def, [inp_node], [out_node], [&quot;sort_by_execution_order&quot;])

    tf.train.write_graph(graph_def, &quot;/tmp/my-model&quot;, 'graph_opt.pbtxt', as_text=True)
    tf.train.write_graph(graph_def, &quot;/tmp/my-model&quot;, 'graph_opt.pb', as_text=False)"><pre class="notranslate"><code class="notranslate">import tensorflow as tf
from tensorflow.tools.graph_transforms import TransformGraph
from tensorflow.python.tools import optimize_for_inference_lib

graph = 'graph.pb'
with tf.gfile.FastGFile(graph, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.summary.FileWriter('logs', graph_def)

    inp_node = 'InputData/X'
    out_node = 'FullyConnected/Softmax'
    graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, [inp_node], [out_node],
                                                                  tf.float32.as_datatype_enum)
    graph_def = TransformGraph(graph_def, [inp_node], [out_node], ["sort_by_execution_order"])

    tf.train.write_graph(graph_def, "/tmp/my-model", 'graph_opt.pbtxt', as_text=True)
    tf.train.write_graph(graph_def, "/tmp/my-model", 'graph_opt.pb', as_text=False)
</code></pre></div>
<p dir="auto">This completes successfully:</p>
<blockquote>
<p dir="auto">WARNING:tensorflow:From optimize_graph.py:6: FastGFile.<strong>init</strong> (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.<br>
Instructions for updating:<br>
Use tf.gfile.GFile.<br>
WARNING:tensorflow:Passing a <code class="notranslate">GraphDef</code> to the SummaryWriter is deprecated. Pass a <code class="notranslate">Graph</code> object instead, such as <code class="notranslate">sess.graph</code>.<br>
WARNING:tensorflow:From //.local/lib/python3.6/site-packages/tensorflow/python/tools/strip_unused_lib.py:86: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.<br>
Instructions for updating:<br>
Use tf.compat.v1.graph_util.extract_sub_graph<br>
WARNING:tensorflow:From //.local/lib/python3.6/site-packages/tensorflow/python/tools/optimize_for_inference_lib.py:113: remove_training_nodes (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.<br>
Instructions for updating:<br>
Use tf.compat.v1.graph_util.remove_training_nodes<br>
2019-03-15 17:32:23.963903: I tensorflow/tools/graph_transforms/transform_graph.cc:317] Applying sort_by_execution_order</p>
</blockquote>
<p dir="auto">After these steps i get the following errors:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="this-&gt;net = cv::dnn::readNetFromTensorflow(&quot;graph_opt.pb&quot;, &quot;graph_opt.pbtxt&quot;);"><pre class="notranslate"><code class="notranslate">this-&gt;net = cv::dnn::readNetFromTensorflow("graph_opt.pb", "graph_opt.pbtxt");
</code></pre></div>
<blockquote>
<p dir="auto">tf_importer.cpp:616: error: (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'addConstNodes'</p>
</blockquote>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="this-&gt;net = cv::dnn::readNetFromTensorflow(&quot;graph_opt.pb&quot;);"><pre class="notranslate"><code class="notranslate">this-&gt;net = cv::dnn::readNetFromTensorflow("graph_opt.pb");
</code></pre></div>
<blockquote>
<p dir="auto">tf_graph_simplifier.cpp:773: error: (-2:Unspecified error) Tensor's data type is not supported in function 'getTensorContent'</p>
</blockquote>
<h5 dir="auto">Steps to reproduce</h5>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 3.4</li>
<li>Operating System / Platform =&gt; Mac OS X ( Related to JS version of Open CV)</li>
<li>JS has been built using branch 3.4</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">Was trying to use orb.detect() function in JS but it throws errors:</p>
<p dir="auto"><code class="notranslate">Cannot call Feature2D.detect due to unbound types: NSt3__26vectorIN2cv8KeyPointENS_9allocatorIS2_EEEE↵ at UnboundTypeError</code></p>
<h5 dir="auto">Steps to reproduce</h5>

<p dir="auto">Use the steps as mentioned in the tutorial to include JS file in your code<br>
and then when opencv has been loaded into Browser memory run this code</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="console.log(cv);
let imgMat = cv.imread(imgElement);
let orb = new cv.ORB();
let kp = orb.detect(imgMat,&quot;&quot;);
console.log(&quot;kp&quot;,kp);
// let result = orb.compute(imgMat,kp);
// console.log(&quot;result&quot;,result);
mat.delete();"><pre class="notranslate"><span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">cv</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">imgMat</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span><span class="pl-kos">.</span><span class="pl-en">imread</span><span class="pl-kos">(</span><span class="pl-s1">imgElement</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">orb</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-s1">cv</span><span class="pl-kos">.</span><span class="pl-c1">ORB</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">kp</span> <span class="pl-c1">=</span> <span class="pl-s1">orb</span><span class="pl-kos">.</span><span class="pl-en">detect</span><span class="pl-kos">(</span><span class="pl-s1">imgMat</span><span class="pl-kos">,</span><span class="pl-s">""</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"kp"</span><span class="pl-kos">,</span><span class="pl-s1">kp</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// let result = orb.compute(imgMat,kp);</span>
<span class="pl-c">// console.log("result",result);</span>
<span class="pl-s1">mat</span><span class="pl-kos">.</span><span class="pl-en">delete</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>