{"id":112,"date":"2019-06-29T10:59:07","date_gmt":"2019-06-29T02:59:07","guid":{"rendered":"http:\/\/www.mustenaka.cn\/?p=112"},"modified":"2019-06-30T23:50:28","modified_gmt":"2019-06-30T15:50:28","slug":"pythonoldapireplace","status":"publish","type":"post","link":"https:\/\/www.mustenaka.cn\/index.php\/2019\/06\/29\/pythonoldapireplace\/","title":{"rendered":"PYTHON\u65e7\u7684misc.imsave\u66ff\u6362"},"content":{"rendered":"<p>\u6e90\u81ea\u4e8e\u4e00\u4e2a\u9879\u76eegithub\u5bf9\u6297\u5e72\u6270\u7684\u9879\u76ee<\/p>\n<p>\u9879\u76ee\u672c\u8eab\u662f2014\u5e74\u7684\u9879\u76ee\uff0c\u65f6\u95f4\u8fc7\u4e8e\u4e45\u8fdc\u4f7f\u7528\u4e86\u5f88\u65e7\u7684API\uff0c\u56e0\u6b64\u76f4\u63a5\u8fd0\u884c\u8d77\u6765\u4f1a\u6709\u4e00\u4e9b\u95ee\u9898\uff0c\u9879\u76ee\u94fe\u63a5\u4e3a<a href=\"https:\/\/github.com\/jason71995\/Keras_adversarial_attack\">https:\/\/github.com\/jason71995\/Keras_adversarial_attack<\/a><\/p>\n<p>\u9879\u76ee\u4f7f\u7528\u6846\u67b6\u4e3atensorflow\u548ckeras\uff0c\u56fe\u7247\u5728\u8fdb\u884c\u653b\u51fb\u4e4b\u540e\u8fdb\u884c\u4e86\u4e00\u4e2a\u5b58\u50a8\uff0c\u4f46\u662f\u5728\u5b58\u50a8\u7684\u65f6\u5019\u4f1a\u53d1\u73b0API\u8fc7\u65f6\uff0c\u901a\u8fc7\u7b80\u5355\u7684\u4fee\u6539\u53ef\u4ee5\u8ba9\u5176\u6b63\u5e38\u8fd0\u884c<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" python=\"\">print (\"============================== Saving Images ==============================\")\r\nimages = (x_test[:100]*255).astype(\"uint8\")\r\nimages = np.reshape(images,(10,10,28,28))\r\nimages = np.transpose(images,(0,2,1,3))\r\nimages = np.reshape(images,(280,280))\r\nmisc.imsave(\"normal_images.png\",images)\r\n\r\nattack_images, = attack_func([x_test[:100], y_test[:100], eps, 0])\r\nimages = (attack_images*255).astype(\"uint8\")\r\nimages = np.reshape(images,(10,10,28,28))\r\nimages = np.transpose(images,(0,2,1,3))\r\nimages = np.reshape(images,(280,280))\r\nmisc.imsave(\"attack_images.png\",images)<\/code><\/pre>\n<p>\u8fd9\u4e2a\u662f\u6587\u4ef6\u7684\u540e\u534a\u6bb5\u5185\u5bb9\u4ee3\u7801\uff0c\u62a5\u9519\u63d0\u793amisc.imsave\u5df2\u7ecf\u88ab\u5f03\u7528\u4e86\uff0c\u4f7f\u7528\u65b0\u7684API\u63a5\u53e3imageio\u89e3\u51b3\u3002<\/p>\n<p>\u5148\u901a\u8fc7pip\u6216\u8005conda\u4e0b\u8f7d\u65b0\u7684API<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" python=\"\">pip install imageio<\/code><\/pre>\n<p>\u7136\u540e\u76f4\u63a5\u5728\u6e90\u4ee3\u7801\u7684\u57fa\u7840\u4e4b\u4e0a\u4fee\u6539\u4e3a\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" python=\"\">import imageio   #\u6dfb\u52a0\u65b0\u7684\u5185\u5bb9\r\n\r\n#\u2026\u2026\u2026\u2026\u7701\u7565\u4e2d\u95f4\u5185\u5bb9\u2026\u2026\u2026\u2026#\r\n\r\nprint (\"============================== Saving Images ==============================\")\r\nimages = (x_test[:100]*255).astype(\"uint8\")\r\nimages = np.reshape(images,(10,10,28,28))\r\nimages = np.transpose(images,(0,2,1,3))\r\nimages = np.reshape(images,(280,280))\r\n#misc.imsave(\"normal_images.png\",images)\r\nimageio.imwrite(\"normal_images.png\",images)\r\n\r\nattack_images, = attack_func([x_test[:100], y_test[:100], eps, 0])\r\nimages = (attack_images*255).astype(\"uint8\")\r\nimages = np.reshape(images,(10,10,28,28))\r\nimages = np.transpose(images,(0,2,1,3))\r\nimages = np.reshape(images,(280,280))\r\n#misc.imsave(\"attack_images.png\",images)\r\nimageio.imwrite(\"attack_images.png\",images)<\/code><\/pre>\n<p>\u5c31\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u4e86\uff0c\u5176\u6587\u4ef6\u4f1a\u76f4\u63a5\u4fdd\u5b58\u5728\u9879\u76ee\u5f53\u524d\u8def\u5f84\u4e2d\u3002<\/p>\n<p>imageio.imwrite(&#8220;\u8def\u5f84\u5730\u5740&#8221;,\u56fe\u7247\u4fe1\u606f)<\/p>\n<p>\u8def\u5f84\u5730\u5740\u5206\u4e3a \u76f8\u5bf9\u5730\u5740 \u548c \u7edd\u5bf9\u5730\u5740 \u4e24\u7c7b\uff0c\u76f8\u5bf9\u5730\u5740\u4f1a\u4ee5\u5f53\u524d\u4ee3\u7801\u5b58\u50a8\u7684\u8def\u5f84\u4e3a\u57fa\u7840\uff0c\u56fe\u7247\u4fe1\u606f\u5c31\u662f\u6211\u4eec\u5904\u7406\u548c\u5bf9\u6297\u7684\u5185\u5bb9\u4e86\u3002<\/p>\n<p>\u7b2c\u4e00\u6b21\u5728linux\u4e0a\u9762\u6c34\u535a\u5ba2\u6587\u7ae0QWQ<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6e90\u81ea\u4e8e\u4e00\u4e2a\u9879\u76eegithub\u5bf9\u6297\u5e72\u6270\u7684\u9879\u76ee \u9879\u76ee\u672c\u8eab\u662f2014\u5e74\u7684\u9879\u76ee\uff0c\u65f6\u95f4\u8fc7\u4e8e\u4e45\u8fdc\u4f7f\u7528\u4e86\u5f88\u65e7\u7684API [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,30],"tags":[12,31],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-ai","category-python","tag-ai","tag-python"],"views":3674,"_links":{"self":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":4,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":149,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions\/149"}],"wp:attachment":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}