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

<ul dir="auto">
<li>OpenCV =&gt; 4.1.2（Ubuntu18.04），4.2（Win10 64bit)</li>
<li>Operating System / Platform =&gt; Linux, Win</li>
<li>Compiler =&gt; gcc7.5(linux), Visual Studio 2019(Win10)</li>
<li>Tensorflow =&gt; 2.1</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I want to convert keras model to <code class="notranslate">.pb</code> file and load it using <code class="notranslate">dnn.readNetFromTensorflow()</code> , and I got an error like the title shows ( same error in Ubuntu18.04 with opencv 4.1.2):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: OpenCV(4.2.0) E:\ScientificComputing\opencv-4.2.0\modules\dnn\src\tensorflow\tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: my_model/saved_model.pb in function 'ReadTFNetParamsFromBinaryFileOrDie'"><pre class="notranslate"><code class="notranslate">error: OpenCV(4.2.0) E:\ScientificComputing\opencv-4.2.0\modules\dnn\src\tensorflow\tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: my_model/saved_model.pb in function 'ReadTFNetParamsFromBinaryFileOrDie'
</code></pre></div>
<p dir="auto">Can someone tell me the best way to load a keras model (tf version is 2.1)? I tried the solution in issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="404879408" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/13728" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/13728/hovercard" href="https://github.com/opencv/opencv/issues/13728">#13728</a> , but didn't work for me.</p>
<h5 dir="auto">Steps to reproduce</h5>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf
import cv2
from cv2 import dnn
import numpy as np 
import matplotlib.pyplot as plt
import os
print(tf.__version__)
print(cv2.__version__)
model = tf.keras.applications.mobilenet.MobileNet(weights=None)
model.save('my_model', save_format='tf')

net = dnn.readNetFromTensorflow('my_model/saved_model.pb')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>
<span class="pl-k">import</span> <span class="pl-s1">cv2</span>
<span class="pl-k">from</span> <span class="pl-s1">cv2</span> <span class="pl-k">import</span> <span class="pl-s1">dnn</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span> 
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">os</span>
<span class="pl-en">print</span>(<span class="pl-s1">tf</span>.<span class="pl-s1">__version__</span>)
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">__version__</span>)
<span class="pl-s1">model</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-s1">keras</span>.<span class="pl-s1">applications</span>.<span class="pl-s1">mobilenet</span>.<span class="pl-v">MobileNet</span>(<span class="pl-s1">weights</span><span class="pl-c1">=</span><span class="pl-c1">None</span>)
<span class="pl-s1">model</span>.<span class="pl-en">save</span>(<span class="pl-s">'my_model'</span>, <span class="pl-s1">save_format</span><span class="pl-c1">=</span><span class="pl-s">'tf'</span>)

<span class="pl-s1">net</span> <span class="pl-c1">=</span> <span class="pl-s1">dnn</span>.<span class="pl-en">readNetFromTensorflow</span>(<span class="pl-s">'my_model/saved_model.pb'</span>)</pre></div>
<p dir="auto">In tf2.1, the <code class="notranslate">save</code> method using argument <code class="notranslate">save_format='tf'</code> will generate files like below:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15122811/74510623-232e6b00-4f3f-11ea-8af4-838decbc5173.png"><img src="https://user-images.githubusercontent.com/15122811/74510623-232e6b00-4f3f-11ea-8af4-838decbc5173.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">I encountered a discrepancy between the documentation (found <a href="http://docs.opencv.org/3.1.0/d2/de8/group__core__array.html#ga937ecdce4679a77168730830a955bea7" rel="nofollow">here</a>) and the actual behavior of the cv::log function. Though the documentation says that log(0) will evaluate it to roughly -700, printing it indicates that it is -inf. Is this the intended behavior?</p>
<h3 dir="auto">Please state the information for your system</h3>
<ul dir="auto">
<li>OpenCV version: 3.1.0</li>
<li>Host OS: Mac OS X 10.10.5</li>
</ul>
<p dir="auto">Duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="97441532" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/4982" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/4982/hovercard" href="https://github.com/opencv/opencv/issues/4982">#4982</a></p>