{"id":2280,"date":"2022-01-22T18:06:02","date_gmt":"2022-01-22T10:06:02","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2280"},"modified":"2022-01-22T18:06:03","modified_gmt":"2022-01-22T10:06:03","slug":"dataen","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/dataen\/","title":{"rendered":"\u4e00\u6587\u5f52\u7eb3 AI \u6570\u636e\u589e\u5f3a\u4e4b\u6cd5"},"content":{"rendered":"\n<p>\u4f5c\u8005 | \u7b97\u6cd5\u8fdb\u9636<br>\u6458\u81ea\uff1a \u7b97\u6cd5\u8fdb\u9636\u5fae\u4fe1\u516c\u4f17\u53f7<\/p>\n\n\n\n<p>\u6570\u636e\u3001\u7b97\u6cd5\u3001\u7b97\u529b\u662f\u4eba\u5de5\u667a\u80fd\u53d1\u5c55\u7684\u4e09\u8981\u7d20\u3002\u6570\u636e\u51b3\u5b9a\u4e86Ai\u6a21\u578b\u5b66\u4e60\u7684\u4e0a\u9650\uff0c\u6570\u636e\u89c4\u6a21\u8d8a\u5927\u3001\u8d28\u91cf\u8d8a\u9ad8\uff0c\u6a21\u578b\u5c31\u80fd\u591f\u62e5\u6709\u66f4\u597d\u7684\u6cdb\u5316\u80fd\u529b\u3002\u7136\u800c\u5728\u5b9e\u9645\u5de5\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u6709\u6570\u636e\u91cf\u592a\u5c11(\u76f8\u5bf9\u6a21\u578b\u800c\u8a00)\u3001\u6837\u672c\u4e0d\u5747\u8861\u3001\u5f88\u96be\u8986\u76d6\u5168\u90e8\u7684\u573a\u666f\u7b49\u95ee\u9898\uff0c\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u7684\u4e00\u4e2a\u6709\u6548\u9014\u5f84\u662f\u901a\u8fc7\u6570\u636e\u589e\u5f3a\uff08Data Augmentation\uff09\uff0c\u4f7f\u6a21\u578b\u5b66\u4e60\u83b7\u5f97\u8f83\u597d\u7684\u6cdb\u5316\u6027\u80fd\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icxmzrwj30u00at765.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h2>1 \u6570\u636e\u589e\u5f3a\u4ecb\u7ecd<\/h2>\n\n\n\n<p>\u6570\u636e\u589e\u5f3a\uff08Data Augmentation\uff09\u662f\u5728\u4e0d\u5b9e\u8d28\u6027\u7684\u589e\u52a0\u6570\u636e\u7684\u60c5\u51b5\u4e0b\uff0c\u4ece\u539f\u59cb\u6570\u636e\u52a0\u5de5\u51fa\u66f4\u591a\u7684\u8868\u793a\uff0c\u63d0\u9ad8\u539f\u6570\u636e\u7684\u6570\u91cf\u53ca\u8d28\u91cf\uff0c\u4ee5\u63a5\u8fd1\u4e8e\u66f4\u591a\u6570\u636e\u91cf\u4ea7\u751f\u7684\u4ef7\u503c\u3002\u5176\u539f\u7406\u662f\uff0c<strong>\u901a\u8fc7\u5bf9\u539f\u59cb\u6570\u636e\u878d\u5165\u5148\u9a8c\u77e5\u8bc6\uff0c\u52a0\u5de5\u51fa\u66f4\u591a\u6570\u636e\u7684\u8868\u793a\uff0c\u6709\u52a9\u4e8e\u6a21\u578b\u5224\u522b\u6570\u636e\u4e2d\u7edf\u8ba1\u566a\u58f0<\/strong>\uff0c\u52a0\u5f3a\u672c\u4f53\u7279\u5f81\u7684\u5b66\u4e60\uff0c\u51cf\u5c11\u6a21\u578b\u8fc7\u62df\u5408\uff0c\u63d0\u5347\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u5982\u7ecf\u5178\u7684\u673a\u5668\u5b66\u4e60\u4f8b\u5b50&#8211;\u54c8\u58eb\u5947\u8bef\u5206\u7c7b\u4e3a\u72fc\uff1a\u901a\u8fc7\u53ef\u89e3\u91ca\u6027\u65b9\u6cd5\uff0c\u53ef\u53d1\u73b0\u9519\u8bef\u5206\u7c7b\u662f\u7531\u4e8e\u56fe\u50cf\u4e0a\u7684\u96ea\u9020\u6210\u7684\u3002\u901a\u5e38\u72d7\u5bf9\u6bd4\u72fc\u7684\u56fe\u50cf\u91cc\u9762\u96ea\u5730\u80cc\u666f\u6bd4\u8f83\u5c11\uff0c\u5206\u7c7b\u5668\u5b66\u4f1a\u4f7f\u7528\u96ea\u4f5c\u4e3a\u4e00\u4e2a\u7279\u5f81\u6765\u5c06\u56fe\u50cf\u5206\u7c7b\u4e3a\u72fc\u8fd8\u662f\u72d7\uff0c\u800c\u5ffd\u7565\u4e86\u52a8\u7269\u672c\u4f53\u7684\u7279\u5f81\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6570\u636e\u589e\u5f3a\u7684\u65b9\u6cd5\uff0c\u589e\u52a0\u53d8\u6362\u540e\u7684\u6570\u636e(\u5982\u80cc\u666f\u6362\u8272\u3001\u52a0\u5165\u566a\u58f0\u7b49\u65b9\u5f0f)\u6765\u8bad\u7ec3\u6a21\u578b\uff0c\u5e2e\u52a9\u6a21\u578b\u5b66\u4e60\u5230\u672c\u4f53\u7684\u7279\u5f81\uff0c\u63d0\u9ad8\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icxtvmvj307805e752.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u9700\u8981\u5173\u6ce8\u7684\u662f\uff0c\u6570\u636e\u589e\u5f3a\u6837\u672c\u4e5f\u6709\u53ef\u80fd\u662f\u5f15\u5165\u7247\u9762\u566a\u58f0\uff0c\u5bfc\u81f4\u8fc7\u62df\u5408\u3002\u6b64\u65f6\u9700\u8981\u8003\u8651\u7684\u662f\u8c03\u6574\u6570\u636e\u589e\u5f3a\u65b9\u6cd5\uff0c\u6216\u8005\u901a\u8fc7\u7b97\u6cd5(\u53ef\u501f\u9274Pu-Learning\u601d\u8def)\u9009\u62e9\u589e\u5f3a\u6570\u636e\u7684\u6700\u4f73\u5b50\u96c6\uff0c\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u5e38\u7528\u6570\u636e\u589e\u5f3a\u65b9\u6cd5\u53ef\u5206\u4e3a\uff1a<strong>\u57fa\u4e8e\u6837\u672c\u53d8\u6362\u7684\u6570\u636e\u589e\u5f3a\u53ca\u57fa\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u6570\u636e\u589e\u5f3a\u3002<\/strong><\/p>\n\n\n\n<h2>2 \u57fa\u4e8e\u6837\u672c\u53d8\u6362\u7684\u6570\u636e\u589e\u5f3a<\/h2>\n\n\n\n<p>\u6837\u672c\u53d8\u6362\u6570\u636e\u589e\u5f3a\u5373\u91c7\u7528\u9884\u8bbe\u7684\u6570\u636e\u53d8\u6362\u89c4\u5219\u8fdb\u884c\u5df2\u6709\u6570\u636e\u7684\u6269\u589e\uff0c\u5305\u542b\u5355\u6837\u672c\u6570\u636e\u589e\u5f3a\u548c\u591a\u6837\u672c\u6570\u636e\u589e\u5f3a\u3002<\/p>\n\n\n\n<h3>2.1 \u5355\u6837\u672c\u589e\u5f3a<\/h3>\n\n\n\n<p>\u5355(\u56fe\u50cf)\u6837\u672c\u589e\u5f3a\u4e3b\u8981\u6709\u51e0\u4f55\u64cd\u4f5c\u3001\u989c\u8272\u53d8\u6362\u3001\u968f\u673a\u64e6\u9664\u3001\u6dfb\u52a0\u566a\u58f0\u7b49\u65b9\u6cd5\uff0c\u53ef\u53c2\u89c1imgaug\u5f00\u6e90\u5e93\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icy6simj30n208042z.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h3>2.2 \u591a\u6837\u672c\u6570\u636e\u589e\u5f3a\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u591a\u6837\u672c\u589e\u5f3a\u662f\u901a\u8fc7\u5148\u9a8c\u77e5\u8bc6\u7ec4\u5408\u53ca\u8f6c\u6362\u591a\u4e2a\u6837\u672c\uff0c\u4e3b\u8981\u6709Smote\u3001SamplePairing\u3001Mixup\u7b49\u65b9\u6cd5\u5728\u7279\u5f81\u7a7a\u95f4\u5185\u6784\u9020\u5df2\u77e5\u6837\u672c\u7684\u90bb\u57df\u503c\u3002<\/p>\n\n\n\n<ul><li>Smote<\/li><\/ul>\n\n\n\n<p>Smote(Synthetic Minority Over-sampling Technique)\u65b9\u6cd5\u8f83\u5e38\u7528\u4e8e\u6837\u672c\u5747\u8861\u5b66\u4e60\uff0c\u6838\u5fc3\u601d\u60f3\u662f\u4ece\u8bad\u7ec3\u96c6\u968f\u673a\u540c\u7c7b\u7684\u4e24\u8fd1\u90bb\u6837\u672c\u5408\u6210\u4e00\u4e2a\u65b0\u7684\u6837\u672c\uff0c\u5176\u65b9\u6cd5\u53ef\u4ee5\u5206\u4e3a\u4e09\u6b65\uff1a<\/p>\n\n\n\n<p>1\u3001 \u5bf9\u4e8e\u5404\u6837\u672cX_i\uff0c\u8ba1\u7b97\u4e0e\u540c\u7c7b\u6837\u672c\u7684\u6b27\u5f0f\u8ddd\u79bb\uff0c\u786e\u5b9a\u5176\u540c\u7c7b\u7684K\u4e2a(\u5982\u56fe3\u4e2a)\u8fd1\u90bb\u6837\u672c\uff1b<\/p>\n\n\n\n<p>2\u3001\u4ece\u8be5\u6837\u672ck\u8fd1\u90bb\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6837\u672c\u5982\u8fd1\u90bbX_ik\uff0c\u751f\u6210\u65b0\u7684\u6837\u672c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Xsmote_ik =  Xi  +  rand(0,1) \u2217 \u2223X_i \u2212 X_ik\u2223  <\/code><\/pre>\n\n\n\n<p>3\u3001\u91cd\u590d2\u6b65\u9aa4\u8fed\u4ee3N\u6b21\uff0c\u53ef\u4ee5\u5408\u6210N\u4e2a\u65b0\u7684\u6837\u672c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icyemicj30hl0b4myk.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># SMOTE\nfrom imblearn.over_sampling import SMOTE\n\nprint(\"Before OverSampling, counts of label\\n{}\".format(y_train.value_counts()))\nsmote = SMOTE()\nx_train_res, y_train_res = smote.fit_resample(x_train, y_train)\nprint(\"After OverSampling, counts of label\\n{}\".format(y_train_res.value_counts())) <\/code><\/pre>\n\n\n\n<ul><li>SamplePairing<\/li><\/ul>\n\n\n\n<p>SamplePairing\u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u662f\u4ece\u8bad\u7ec3\u96c6\u968f\u673a\u62bd\u53d6\u7684\u4e24\u5e45\u56fe\u50cf\u53e0\u52a0\u5408\u6210\u4e00\u4e2a\u65b0\u7684\u6837\u672c\uff08\u50cf\u7d20\u53d6\u5e73\u5747\u503c\uff09\uff0c\u4f7f\u7528\u7b2c\u4e00\u5e45\u56fe\u50cf\u7684label\u4f5c\u4e3a\u5408\u6210\u56fe\u50cf\u7684\u6b63\u786elabel\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icyhprkj30u00g744w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<ul><li>Mixup<\/li><\/ul>\n\n\n\n<p>Mixup\u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u662f\u6309\u4e00\u5b9a\u7684\u6bd4\u4f8b\u968f\u673a\u6df7\u5408\u4e24\u4e2a\u8bad\u7ec3\u6837\u672c\u53ca\u5176\u6807\u7b7e\uff0c\u8fd9\u79cd\u6df7\u5408\u65b9\u5f0f\u4e0d\u4ec5\u80fd\u591f\u589e\u52a0\u6837\u672c\u7684\u591a\u6837\u6027\uff0c\u4e14\u80fd\u591f\u4f7f\u51b3\u7b56\u8fb9\u754c\u66f4\u52a0\u5e73\u6ed1\uff0c\u589e\u5f3a\u4e86\u96be\u4f8b\u6837\u672c\u7684\u8bc6\u522b\uff0c\u6a21\u578b\u7684\u9c81\u68d2\u6027\u5f97\u5230\u63d0\u5347\u3002\u5176\u65b9\u6cd5\u53ef\u4ee5\u5206\u4e3a\u4e24\u6b65\uff1a<\/p>\n\n\n\n<p>1\u3001\u4ece\u539f\u59cb\u8bad\u7ec3\u6570\u636e\u4e2d\u968f\u673a\u9009\u53d6\u7684\u4e24\u4e2a\u6837\u672c(xi, yi) and (xj, yj)\u3002\u5176\u4e2dy(\u539f\u59cblabel)\u7528one-hot \u7f16\u7801\u3002<\/p>\n\n\n\n<p>2\u3001\u5bf9\u4e24\u4e2a\u6837\u672c\u6309\u6bd4\u4f8b\u7ec4\u5408\uff0c\u5f62\u6210\u65b0\u7684\u6837\u672c\u548c\u5e26\u6743\u91cd\u7684\u6807\u7b7e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x\u02dc = \u03bbxi + (1 \u2212 \u03bb)xj  \ny\u02dc = \u03bbyi + (1 \u2212 \u03bb)yj  <\/code><\/pre>\n\n\n\n<p>\u6700\u7ec8\u7684loss\u4e3a\u5404\u6807\u7b7e\u4e0a\u5206\u522b\u8ba1\u7b97cross-entropy loss\uff0c\u52a0\u6743\u6c42\u548c\u3002\u5176\u4e2d \u03bb \u2208 [0, 1]\uff0c \u03bb\u662fmixup\u7684\u8d85\u53c2\u6570\uff0c\u63a7\u5236\u4e24\u4e2a\u6837\u672c\u63d2\u503c\u7684\u5f3a\u5ea6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icz3aecj30u009rn11.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># Mixup\ndef mixup_batch(x, y, step, batch_size, alpha=0.2):\n    \"\"\"\n    get batch data\n    :param x: training data\n    :param y: one-hot label\n    :param step: step\n    :param batch_size: batch size\n    :param alpha: hyper-parameter \u03b1, default as 0.2\n    :return:  x y \n    \"\"\"\n    candidates_data, candidates_label = x, y\n    offset = (step * batch_size) % (candidates_data.shape&#91;0] - batch_size)\n\n    # get batch data\n    train_features_batch = candidates_data&#91;offset:(offset + batch_size)]\n    train_labels_batch = candidates_label&#91;offset:(offset + batch_size)]\n\n    if alpha == 0:\n        return train_features_batch, train_labels_batch\n\n    if alpha &gt; 0:\n        weight = np.random.beta(alpha, alpha, batch_size)\n        x_weight = weight.reshape(batch_size, 1)\n        y_weight = weight.reshape(batch_size, 1)\n        index = np.random.permutation(batch_size)\n        x1, x2 = train_features_batch, train_features_batch&#91;index]\n        x = x1 * x_weight + x2 * (1 - x_weight)\n        y1, y2 = train_labels_batch, train_labels_batch&#91;index]\n        y = y1 * y_weight + y2 * (1 - y_weight)\n        return x, y <\/code><\/pre>\n\n\n\n<h2>3 \u57fa\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u6570\u636e\u589e\u5f3a<\/h2>\n\n\n\n<h3>3.1 \u7279\u5f81\u7a7a\u95f4\u7684\u6570\u636e\u589e\u5f3a<\/h3>\n\n\n\n<p>\u4e0d\u540c\u4e8e\u4f20\u7edf\u5728\u8f93\u5165\u7a7a\u95f4\u53d8\u6362\u7684\u6570\u636e\u589e\u5f3a\u65b9\u6cd5\uff0c\u795e\u7ecf\u7f51\u7edc\u53ef\u5c06\u8f93\u5165\u6837\u672c\u6620\u5c04\u4e3a\u7f51\u7edc\u5c42\u7684\u4f4e\u7ef4\u5411\u91cf(\u8868\u5f81\u5b66\u4e60)\uff0c\u4ece\u800c\u76f4\u63a5\u5728\u5b66\u4e60\u7684\u7279\u5f81\u7a7a\u95f4\u8fdb\u884c\u7ec4\u5408\u53d8\u6362\u7b49\u8fdb\u884c\u6570\u636e\u589e\u5f3a\uff0c\u5982MoEx\u65b9\u6cd5\u7b49\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icyubt2j30u007v0w4.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h3>3.2 \u57fa\u4e8e\u751f\u6210\u6a21\u578b\u7684\u6570\u636e\u589e\u5f3a<\/h3>\n\n\n\n<p>\u751f\u6210\u6a21\u578b\u5982\u53d8\u5206\u81ea\u7f16\u7801\u7f51\u7edc(Variational Auto-Encoding network, VAE)\u548c\u751f\u6210\u5bf9\u6297\u7f51\u7edc(Generative Adversarial Network, GAN)\uff0c\u5176\u751f\u6210\u6837\u672c\u7684\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u589e\u5f3a\u3002\u8fd9\u79cd\u57fa\u4e8e\u7f51\u7edc\u5408\u6210\u7684\u65b9\u6cd5\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684\u6570\u636e\u589e\u5f3a\u6280\u672f\u867d\u7136\u8fc7\u7a0b\u66f4\u52a0\u590d\u6742, \u4f46\u662f\u751f\u6210\u7684\u6837\u672c\u66f4\u52a0\u591a\u6837\u3002<\/p>\n\n\n\n<ul><li>\u53d8\u5206\u81ea\u7f16\u7801\u5668VAE\u53d8\u5206\u81ea\u7f16\u7801\u5668\uff08Variational Autoencoder\uff0cVAE\uff09\u5176\u57fa\u672c\u601d\u8def\u662f\uff1a\u5c06\u771f\u5b9e\u6837\u672c\u901a\u8fc7\u7f16\u7801\u5668\u7f51\u7edc\u53d8\u6362\u6210\u4e00\u4e2a\u7406\u60f3\u7684\u6570\u636e\u5206\u5e03\uff0c\u7136\u540e\u628a\u6570\u636e\u5206\u5e03\u518d\u4f20\u9012\u7ed9\u89e3\u7801\u5668\u7f51\u7edc\uff0c\u6784\u9020\u51fa\u751f\u6210\u6837\u672c\uff0c\u6a21\u578b\u8bad\u7ec3\u5b66\u4e60\u7684\u8fc7\u7a0b\u662f\u4f7f\u751f\u6210\u6837\u672c\u4e0e\u771f\u5b9e\u6837\u672c\u8db3\u591f\u63a5\u8fd1\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icz5cvdj30hm06sjsw.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># VAE\u6a21\u578b\nclass VAE(keras.Model):\n    ...\n    def train_step(self, data):\n        with tf.GradientTape() as tape:\n            z_mean, z_log_var, z = self.encoder(data)\n            reconstruction = self.decoder(z)\n            reconstruction_loss = tf.reduce_mean(\n                tf.reduce_sum(\n                    keras.losses.binary_crossentropy(data, reconstruction), axis=(1, 2)\n                )\n            )\n            kl_loss = -0.5 * (1 + z_log_var - tf.square(z_mean) - tf.exp(z_log_var))\n            kl_loss = tf.reduce_mean(tf.reduce_sum(kl_loss, axis=1))\n            total_loss = reconstruction_loss + kl_loss\n        grads = tape.gradient(total_loss, self.trainable_weights)\n        self.optimizer.apply_gradients(zip(grads, self.trainable_weights))\n        self.total_loss_tracker.update_state(total_loss)\n        self.reconstruction_loss_tracker.update_state(reconstruction_loss)\n        self.kl_loss_tracker.update_state(kl_loss)\n        return {\n            \"loss\": self.total_loss_tracker.result(),\n            \"reconstruction_loss\": self.reconstruction_loss_tracker.result(),\n            \"kl_loss\": self.kl_loss_tracker.result(),\n        } <\/code><\/pre>\n\n\n\n<ul><li>\u751f\u6210\u5bf9\u6297\u7f51\u7edcGAN\u751f\u6210\u5bf9\u6297\u7f51\u7edc-GAN(Generative Adversarial Network) \u7531\u751f\u6210\u7f51\u7edc(Generator,&nbsp;<em>G<\/em>)\u548c\u5224\u522b\u7f51\u7edc(Discriminator,&nbsp;<em>D<\/em>)\u4e24\u90e8\u5206\u7ec4\u6210\uff0c \u751f\u6210\u7f51\u7edc\u6784\u6210\u4e00\u4e2a\u6620\u5c04\u51fd\u6570<em>G<\/em>:&nbsp;<em>Z<\/em>\u2192<em>X<\/em>\uff08\u8f93\u5165\u566a\u58f0<em>z<\/em>, \u8f93\u51fa\u751f\u6210\u7684\u56fe\u50cf\u6570\u636e<em>x<\/em>\uff09, \u5224\u522b\u7f51\u7edc\u5224\u522b\u8f93\u5165\u662f\u6765\u81ea\u771f\u5b9e\u6570\u636e\u8fd8\u662f\u751f\u6210\u7f51\u7edc\u751f\u6210\u7684\u6570\u636e\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icz6yitj30tj08741z.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># DCGAN\u6a21\u578b\n\nclass GAN(keras.Model):\n    ...\n    def train_step(self, real_images):\n        batch_size = tf.shape(real_images)&#91;0]\n        random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))\n        # G: Z\u2192X\uff08\u8f93\u5165\u566a\u58f0z, \u8f93\u51fa\u751f\u6210\u7684\u56fe\u50cf\u6570\u636ex\uff09\n        generated_images = self.generator(random_latent_vectors)\n        # \u5408\u5e76\u751f\u6210\u53ca\u771f\u5b9e\u7684\u6837\u672c\u5e76\u8d4b\u5224\u5b9a\u7684\u6807\u7b7e\n        combined_images = tf.concat(&#91;generated_images, real_images], axis=0)\n        labels = tf.concat(\n            &#91;tf.ones((batch_size, 1)), tf.zeros((batch_size, 1))], axis=0\n        )\n        # \u6807\u7b7e\u52a0\u5165\u968f\u673a\u566a\u58f0\n        labels += 0.05 * tf.random.uniform(tf.shape(labels))\n        # \u8bad\u7ec3\u5224\u5b9a\u7f51\u7edc\n        with tf.GradientTape() as tape:\n            predictions = self.discriminator(combined_images)\n            d_loss = self.loss_fn(labels, predictions)\n        grads = tape.gradient(d_loss, self.discriminator.trainable_weights)\n        self.d_optimizer.apply_gradients(\n            zip(grads, self.discriminator.trainable_weights)\n        )\n\n        random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))\n        # \u8d4b\u751f\u6210\u7f51\u7edc\u6837\u672c\u7684\u6807\u7b7e(\u90fd\u8d4b\u4e3a\u771f\u5b9e\u6837\u672c)\n        misleading_labels = tf.zeros((batch_size, 1))\n        # \u8bad\u7ec3\u751f\u6210\u7f51\u7edc\n        with tf.GradientTape() as tape:\n            predictions = self.discriminator(self.generator(random_latent_vectors))\n            g_loss = self.loss_fn(misleading_labels, predictions)\n        grads = tape.gradient(g_loss, self.generator.trainable_weights)\n        self.g_optimizer.apply_gradients(zip(grads, self.generator.trainable_weights))\n        # \u66f4\u65b0\u635f\u5931\n        self.d_loss_metric.update_state(d_loss)\n        self.g_loss_metric.update_state(g_loss)\n        return {\n            \"d_loss\": self.d_loss_metric.result(),\n            \"g_loss\": self.g_loss_metric.result(),\n        }<\/code><\/pre>\n\n\n\n<h3>3.3 \u57fa\u4e8e\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\u7684\u6570\u636e\u589e\u5f3a<\/h3>\n\n\n\n<p>\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb(Neural Style Transfer)\u53ef\u4ee5\u5728\u4fdd\u7559\u539f\u59cb\u5185\u5bb9\u7684\u540c\u65f6\uff0c\u5c06\u4e00\u4e2a\u56fe\u50cf\u7684\u6837\u5f0f\u8f6c\u79fb\u5230\u53e6\u4e00\u4e2a\u56fe\u50cf\u4e0a\u3002\u9664\u4e86\u5b9e\u73b0\u7c7b\u4f3c\u8272\u5f69\u7a7a\u95f4\u7167\u660e\u8f6c\u6362\uff0c\u8fd8\u53ef\u4ee5\u751f\u6210\u4e0d\u540c\u7684\u7eb9\u7406\u548c\u827a\u672f\u98ce\u683c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icyyvrmj30j10dbq8i.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\u662f\u901a\u8fc7\u4f18\u5316\u4e09\u7c7b\u7684\u635f\u5931\u6765\u5b9e\u73b0\u7684\uff1a<\/p>\n\n\n\n<p>style_loss\uff1a\u4f7f\u751f\u6210\u7684\u56fe\u50cf\u63a5\u8fd1\u6837\u5f0f\u53c2\u8003\u56fe\u50cf\u7684\u5c40\u90e8\u7eb9\u7406\uff1b<\/p>\n\n\n\n<p>content_loss\uff1a\u4f7f\u751f\u6210\u7684\u56fe\u50cf\u7684\u5185\u5bb9\u8868\u793a\u63a5\u8fd1\u4e8e\u57fa\u672c\u56fe\u50cf\u7684\u8868\u793a\uff1b<\/p>\n\n\n\n<p>total_variation_loss\uff1a\u662f\u4e00\u4e2a\u6b63\u5219\u5316\u635f\u5931\uff0c\u5b83\u4f7f\u751f\u6210\u7684\u56fe\u50cf\u4fdd\u6301\u5c40\u90e8\u4e00\u81f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6837\u5f0f\u635f\u5931\ndef style_loss(style, combination):\n    S = gram_matrix(style)\n    C = gram_matrix(combination)\n    channels = 3\n    size = img_nrows * img_ncols\n    return tf.reduce_sum(tf.square(S - C)) \/ (4.0 * (channels ** 2) * (size ** 2))\n\n# \u5185\u5bb9\u635f\u5931\ndef content_loss(base, combination):\n    return tf.reduce_sum(tf.square(combination - base))\n\n# \u6b63\u5219\u635f\u5931\ndef total_variation_loss(x):\n    a = tf.square(\n        x&#91;:, : img_nrows - 1, : img_ncols - 1, :] - x&#91;:, 1:, : img_ncols - 1, :]\n    )\n    b = tf.square(\n        x&#91;:, : img_nrows - 1, : img_ncols - 1, :] - x&#91;:, : img_nrows - 1, 1:, :]\n    )\n    return tf.reduce_sum(tf.pow(a + b, 1.25))<\/code><\/pre>\n\n\n\n<h3>3.4 \u57fa\u4e8e\u5143\u5b66\u4e60\u7684\u6570\u636e\u589e\u5f3a<\/h3>\n\n\n\n<p>\u6df1\u5ea6\u5b66\u4e60\u7814\u7a76\u4e2d\u7684\u5143\u5b66\u4e60(Meta learning)\u901a\u5e38\u662f\u6307\u4f7f\u7528\u795e\u7ecf\u7f51\u7edc\u4f18\u5316\u795e\u7ecf\u7f51\u7edc\uff0c\u5143\u5b66\u4e60\u7684\u6570\u636e\u589e\u5f3a\u6709\u795e\u7ecf\u589e\u5f3a(Neural augmentation)\u7b49\u65b9\u6cd5\u3002<\/p>\n\n\n\n<ul><li>\u795e\u7ecf\u589e\u5f3a<\/li><\/ul>\n\n\n\n<p>\u795e\u7ecf\u589e\u5f3a(Neural augmentation)\u662f\u901a\u8fc7\u795e\u7ecf\u7f51\u7edc\u7ec4\u7684\u5b66\u4e60\u4ee5\u83b7\u5f97\u8f83\u4f18\u7684\u6570\u636e\u589e\u5f3a\u5e76\u6539\u5584\u5206\u7c7b\u6548\u679c\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u5176\u65b9\u6cd5\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>1\u3001\u83b7\u53d6\u4e0etarget\u56fe\u50cf\u540c\u4e00\u7c7b\u522b\u7684\u4e00\u5bf9\u968f\u673a\u56fe\u50cf\uff0c\u524d\u7f6e\u7684\u589e\u5f3a\u7f51\u7edc\u901a\u8fc7CNN\u5c06\u5b83\u4eec\u6620\u5c04\u4e3a\u5408\u6210\u56fe\u50cf\uff0c\u5408\u6210\u56fe\u50cf\u4e0etarget\u56fe\u50cf\u5bf9\u6bd4\u8ba1\u7b97\u635f\u5931\uff1b<\/p>\n\n\n\n<p>2\u3001\u5c06\u5408\u6210\u56fe\u50cf\u4e0etarget\u56fe\u50cf\u795e\u7ecf\u98ce\u683c\u8f6c\u6362\u540e\u8f93\u5165\u5230\u5206\u7c7b\u7f51\u7edc\u4e2d\uff0c\u5e76\u8f93\u51fa\u8be5\u56fe\u50cf\u5206\u7c7b\u635f\u5931\uff1b<\/p>\n\n\n\n<p>3\u3001\u5c06\u589e\u5f3a\u4e0e\u5206\u7c7b\u7684loss\u52a0\u6743\u5e73\u5747\u540e\uff0c\u53cd\u5411\u4f20\u64ad\u4ee5\u66f4\u65b0\u5206\u7c7b\u7f51\u7edc\u53ca\u589e\u5f3a\u7f51\u7edc\u6743\u91cd\u3002\u4f7f\u5f97\u5176\u8f93\u51fa\u56fe\u50cf\u7684\u540c\u7c7b\u5185\u5dee\u8ddd\u51cf\u5c0f\u4e14\u5206\u7c7b\u51c6\u786e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/tva1.sinaimg.cn\/large\/006C3FgEgy1gy9icyyuwij30u00ejae5.jpg\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005 | \u7b97\u6cd5\u8fdb\u9636\u6458\u81ea\uff1a \u7b97\u6cd5\u8fdb\u9636\u5fae\u4fe1\u516c\u4f17\u53f7 \u6570\u636e\u3001\u7b97\u6cd5\u3001\u7b97\u529b\u662f\u4eba\u5de5\u667a\u80fd\u53d1\u5c55\u7684\u4e09\u8981\u7d20\u3002\u6570\u636e\u51b3\u5b9a\u4e86Ai\u6a21\u578b\u5b66\u4e60\u7684 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/dataen\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u4e00\u6587\u5f52\u7eb3 AI \u6570\u636e\u589e\u5f3a\u4e4b\u6cd5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2280"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2280"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2280\/revisions"}],"predecessor-version":[{"id":2281,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2280\/revisions\/2281"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2280"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}