{"id":103,"date":"2019-11-27T15:05:57","date_gmt":"2019-11-27T07:05:57","guid":{"rendered":"http:\/\/8.154.33.202\/?p=103"},"modified":"2019-11-27T15:08:00","modified_gmt":"2019-11-27T07:08:00","slug":"tensorflow-%e5%88%9d%e5%a7%8b%e5%8c%96%e6%96%b0%e5%a2%9e%e5%8f%98%e9%87%8f%ef%bc%8c%e4%bf%9d%e6%8c%81%e8%bd%bd%e5%85%a5%e7%9a%84%e9%a2%84%e8%ae%ad%e7%bb%83%e6%a8%a1%e5%9e%8b%e6%9d%83%e9%87%8d%e4%b8%8d","status":"publish","type":"post","link":"http:\/\/8.154.33.202\/?p=103","title":{"rendered":"tensorflow \u521d\u59cb\u5316\u65b0\u589e\u53d8\u91cf\uff0c\u4fdd\u6301\u8f7d\u5165\u7684\u9884\u8bad\u7ec3\u6a21\u578b\u6743\u91cd\u4e0d\u53d8"},"content":{"rendered":"\n<p>       \u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u8fd9\u6837\u4e00\u4e9b\u95ee\u9898\uff0c\u60f3\u8981\u4f7f\u7528\u4e00\u4e9b\u9884\u8bad\u7ec3\u597d\u7684\u6a21\u578b\uff0c\u7136\u540e\u5728\u5176\u57fa\u7840\u4e0a\u8fdb\u884c\u4e00\u4e9b\u589e\u51cf\uff0c\u4ee5\u9002\u5e94\u65b0\u7684\u4efb\u52a1\u3002\u5728\u5f00\u59cb\u8bad\u7ec3\u4e4b\u524d\uff0c\u8981\u5bf9\u6240\u6709\u7684\u65b0\u589e\u53d8\u91cf\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u4f46\u662f\u8981\u4fdd\u6301\u9884\u8bad\u7ec3\u6a21\u578b\u4e2d\u5df2\u6709\u7684\u6743\u91cd\u4e0d\u53d8\uff0c\u5373\u53ea\u521d\u59cb\u5316\u65b0\u589e\u53d8\u91cf\u3002\u800c\u5982\u679c\u4f7f\u7528tensorflow\u4e2d\u63d0\u4f9b\u7684saver.restore(sess, ckpt_path)\uff0c\u4f1a\u62a5\u627e\u4e0d\u5230\u65b0\u589e\u8282\u70b9\u7684\u9519\u8bef\uff01\u8bb0\u5f55\u4e00\u4e0b\u8fd9\u79cd\u60c5\u51b5\u8981\u5982\u4f55\u5904\u7406\u3002<\/p>\n\n\n\n<p>       \u9996\u5148\uff0c\u5728\u5bf9\u9884\u8bad\u7ec3\u6a21\u578b\u8fdb\u884c\u589e\u51cf\u4e4b\u524d\uff0c\u5148\u8fdb\u884csaver.restore(sess, ckpt_path)\u8f7d\u5165\u9884\u8bad\u7ec3\u6743\u91cd\uff0c\u7136\u540e\u518d\u8fdb\u884c\u5bf9\u7f51\u7edc\u7ed3\u6784\u7684\u589e\u51cf\uff08\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528tf.get_default_graph().get_tensor_by_name(tensor_name)\u83b7\u53d6\u5230\u539f\u7f51\u7edc\u4e2d\u7684tensor\uff0c\u6765\u8fdb\u884c\u65b0\u589e\u8282\u70b9\uff09<\/p>\n\n\n\n<p>       \u5728\u589e\u52a0\u5b8c\u65b0\u589e\u8282\u70b9\u4e4b\u540e\uff0c\u8981\u521d\u59cb\u5316\u8fd9\u4e9b\u65b0\u589e\u8282\u70b9\u6743\u91cd\u53d8\u91cf\u3002\u63a5\u4e0b\u6765\u5c31\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65\uff0c\u83b7\u53d6\u7f51\u7edc\u4e2d\u6240\u6709\u672a\u521d\u59cb\u5316\u7684\u6743\u91cd\u53d8\u91cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>def <\/strong>get_uninitialized_variables(sess):<br>    global_vars = tf.global_variables()<br>    is_not_initialized = sess.run([tf.is_variable_initialized(var) <strong>for <\/strong>var <strong>in <\/strong>global_vars])<br>    not_initialized_vars = [v <strong>for <\/strong>(v, f) <strong>in <\/strong>zip(global_vars, is_not_initialized) <strong>if not <\/strong>f]<br>    print([str(i.name) <strong>for <\/strong>i <strong>in <\/strong>not_initialized_vars])<br>    <strong>return <\/strong>not_initialized_vars<\/pre>\n\n\n\n<p>        \u7136\u540e\u5728\u4f1a\u8bdd\u4e2d\uff0c\u521d\u59cb\u5316\u8fd9\u4e9b\u53d8\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sess.run(tf.variables_initializer(get_uninitialized_variables(sess)))<\/pre>\n\n\n\n<p>       \u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u6109\u5feb\u5730\u8fdb\u884c\u8bad\u7ec3\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u8fd9\u6837\u4e00\u4e9b\u95ee\u9898\uff0c\u60f3\u8981\u4f7f\u7528\u4e00\u4e9b\u9884\u8bad\u7ec3\u597d\u7684\u6a21\u578b\uff0c\u7136\u540e\u5728\u5176\u57fa\u7840\u4e0a\u8fdb\u884c\u4e00\u4e9b\u589e\u51cf\uff0c\u4ee5\u9002\u5e94\u65b0\u7684\u4efb\u52a1\u3002\u5728\u5f00\u59cb\u8bad\u7ec3 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/8.154.33.202\/?p=103\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201ctensorflow \u521d\u59cb\u5316\u65b0\u589e\u53d8\u91cf\uff0c\u4fdd\u6301\u8f7d\u5165\u7684\u9884\u8bad\u7ec3\u6a21\u578b\u6743\u91cd\u4e0d\u53d8\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-tensorflow","category-4"],"_links":{"self":[{"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/posts\/103"}],"collection":[{"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/8.154.33.202\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":2,"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":106,"href":"http:\/\/8.154.33.202\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/106"}],"wp:attachment":[{"href":"http:\/\/8.154.33.202\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/8.154.33.202\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/8.154.33.202\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}