{"id":881,"date":"2026-05-25T07:10:19","date_gmt":"2026-05-24T23:10:19","guid":{"rendered":"https:\/\/www.loongdi.net\/blog\/?p=881"},"modified":"2026-05-25T07:10:19","modified_gmt":"2026-05-24T23:10:19","slug":"ai%e7%a1%ac%e4%bb%b6%e5%9c%a8%e5%93%aa%e9%87%8c%e5%ae%9e%e7%8e%b0%e5%9b%be%e5%83%8f%e8%af%86%e5%88%ab%e5%8a%9f%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.loongdi.net\/blog\/881.html","title":{"rendered":"AI\u786c\u4ef6\u5728\u54ea\u91cc\u5b9e\u73b0\u56fe\u50cf\u8bc6\u522b\u529f\u80fd\uff1f"},"content":{"rendered":"<p><p>\u968f\u7740\u4eba\u5de5\u667a\u80fd\u6280\u672f\u7684\u98de\u901f\u53d1\u5c55\uff0cAI\u786c\u4ef6\u5728\u6df1\u5ea6\u5b66\u4e60\u3001\u56fe\u50cf\u8bc6\u522b\u7b49\u9886\u57df\u626e\u6f14\u7740\u8d8a\u6765\u8d8a\u91cd\u8981\u7684\u89d2\u8272\u3002\u672c\u6587\u5c06\u4e3a\u60a8\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u642d\u5efa\u4e00\u4e2a\u57fa\u7840\u7684AI\u786c\u4ef6\u5e73\u53f0\uff0c\u5b9e\u73b0\u56fe\u50cf\u8bc6\u522b\u529f\u80fd\u3002\u6211\u4eec\u5c06\u4f7f\u7528Python\u7f16\u7a0b\u8bed\u8a00\u548cTensorFlow\u6846\u67b6\u6765\u5b8c\u6210\u8fd9\u4e00\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u524d\u7684\u51c6\u5907\u6216\u80cc\u666f\u4ecb\u7ecd<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5\u4ee5\u4e0b\u8f6f\u4ef6\u548c\u5de5\u5177\uff1a<\/p>\n<\/p>\n<ul>\n<li>Python 3.x<\/li>\n<li>pip<\/li>\n<li>TensorFlow<\/li>\n<li>OpenCV<\/li>\n<\/ul>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5TensorFlow\u548cOpenCV\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install tensorflow<\/p>\r\n<p>pip install opencv-python<\/code><\/pre>\n<\/p>\n<p><h2>\u5b8c\u6210\u4efb\u52a1\u6240\u9700\u7684\u8be6\u7ec6\u3001\u5206\u6b65\u64cd\u4f5c\u6307\u5357<\/h2>\n<\/p>\n<p><h3>\u6b65\u9aa4 1: \u5bfc\u5165\u6240\u9700\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165TensorFlow\u548cOpenCV\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code>import tensorflow as tf<\/p>\r\n<p>import cv2<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 2: \u52a0\u8f7d\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u52a0\u8f7d\u4e00\u5f20\u56fe\u50cf\u7528\u4e8e\u8bad\u7ec3\u3002<\/p>\n<\/p>\n<p><pre><code>image = cv2.imread('path_to_image.jpg')<\/code><\/pre>\n<\/p>\n<p><p>\u8bf7\u5c06 &#8216;path_to_image.jpg&#8217; \u66ff\u6362\u4e3a\u60a8\u7684\u56fe\u50cf\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<p><h3>\u6b65\u9aa4 3: \u56fe\u50cf\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u9002\u5e94TensorFlow\u6a21\u578b\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u56fe\u50cf\u8fdb\u884c\u9884\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code>image = cv2.resize(image, (224, 224))   \u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/p>\r\n<p>image = image \/ 255.0   \u5f52\u4e00\u5316\u56fe\u50cf\u6570\u636e<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 4: \u521b\u5efa\u6a21\u578b<\/h3>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code>model = tf.keras.Sequential([<\/p>\r\n<p>    tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),<\/p>\r\n<p>    tf.keras.layers.MaxPooling2D((2, 2)),<\/p>\r\n<p>    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),<\/p>\r\n<p>    tf.keras.layers.MaxPooling2D((2, 2)),<\/p>\r\n<p>    tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),<\/p>\r\n<p>    tf.keras.layers.MaxPooling2D((2, 2)),<\/p>\r\n<p>    tf.keras.layers.Flatten(),<\/p>\r\n<p>    tf.keras.layers.Dense(128, activation='relu'),<\/p>\r\n<p>    tf.keras.layers.Dense(1, activation='sigmoid')<\/p>\r\n<p>])<\/p>\r\n\r\n<p>model.compile(optimizer='adam',<\/p>\r\n<p>              loss='binary_crossentropy',<\/p>\r\n<p>              metrics=['accuracy'])<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4 5: \u8bad\u7ec3\u6a21\u578b<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u60a8\u7684\u6570\u636e\u96c6\u6765\u8bad\u7ec3\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code>model.fit(train_images, train_labels, epochs=10)<\/code><\/pre>\n<\/p>\n<p><p>\u8bf7\u5c06 &#8216;train_images&#8217; \u548c &#8216;train_labels&#8217; \u66ff\u6362\u4e3a\u60a8\u7684\u8bad\u7ec3\u6570\u636e\u548c\u6807\u7b7e\u3002<\/p>\n<p><h3>\u6b65\u9aa4 6: \u8bc4\u4f30\u6a21\u578b<\/h3>\n<\/p>\n<p><p>\u5728\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.loongdi.net\/blog\/wp-content\/uploads\/2026\/03\/85711.jpg\" alt=\"AI\u786c\u4ef6\u5728\u54ea\u91cc\u5b9e\u73b0\u56fe\u50cf\u8bc6\u522b\u529f\u80fd\uff1f\" title=\"AI\u786c\u4ef6\u5728\u54ea\u91cc\u5b9e\u73b0\u56fe\u50cf\u8bc6\u522b\u529f\u80fd\uff1f\"><\/p>\n<p><pre><code>test_loss, test_acc = model.evaluate(test_images, test_labels)<\/p>\r\n<p>print('Test accuracy:', test_acc)<\/code><\/pre>\n<\/p>\n<p><p>\u8bf7\u5c06 &#8216;test_images&#8217; \u548c &#8216;test_labels&#8217; \u66ff\u6362\u4e3a\u60a8\u7684\u6d4b\u8bd5\u6570\u636e\u548c\u6807\u7b7e\u3002<\/p>\n<p><h2>\u6d89\u53ca\u7684\u5173\u952e\u547d\u4ee4\u3001\u4ee3\u7801\u6216\u914d\u7f6e\u793a\u4f8b<\/h2>\n<\/p>\n<ul>\n<li><strong>pip install tensorflow<\/strong>: \u5b89\u88c5TensorFlow\u5e93<\/li>\n<li><strong>pip install opencv-python<\/strong>: \u5b89\u88c5OpenCV\u5e93<\/li>\n<li><strong>cv2.imread<\/strong>: \u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6<\/li>\n<li><strong>tf.keras.Sequential<\/strong>: \u521b\u5efa\u4e00\u4e2a\u5e8f\u5217\u6a21\u578b<\/li>\n<li><strong>model.fit<\/strong>: \u8bad\u7ec3\u6a21\u578b<\/li>\n<li><strong>model.evaluate<\/strong>: \u8bc4\u4f30\u6a21\u578b<\/li>\n<\/ul>\n<p><h2>\u5bf9\u547d\u4ee4\u3001\u4ee3\u7801\u6216\u91cd\u8981\u6982\u5ff5\u7684\u6e05\u6670\u89e3\u91ca<\/h2>\n<\/p>\n<p><p><strong>cv2.imread<\/strong>: \u8fd9\u662f\u4e00\u4e2aOpenCV\u51fd\u6570\uff0c\u7528\u4e8e\u4ece\u6587\u4ef6\u8def\u5f84\u8bfb\u53d6\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p><strong>tf.keras.Sequential<\/strong>: \u8fd9\u662fTensorFlow\u4e2d\u7528\u4e8e\u521b\u5efa\u5e8f\u5217\u6a21\u578b\u7684\u4e00\u4e2a\u7c7b\u3002\u5e8f\u5217\u6a21\u578b\u5141\u8bb8\u60a8\u5c06\u591a\u4e2a\u5c42\u6309\u7167\u987a\u5e8f\u5806\u53e0\u8d77\u6765\u3002<\/p>\n<\/p>\n<p><p><strong>model.fit<\/strong>: \u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u5728\u7ed9\u5b9a\u7684\u8bad\u7ec3\u6570\u636e\u4e0a\u8bad\u7ec3\u6a21\u578b\u3002\u5b83\u9700\u8981\u8bad\u7ec3\u6570\u636e\u3001\u6807\u7b7e\u548c\u8fed\u4ee3\u6b21\u6570\u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><p><strong>model.evaluate<\/strong>: \u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u5728\u7ed9\u5b9a\u7684\u6d4b\u8bd5\u6570\u636e\u4e0a\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002\u5b83\u8fd4\u56de\u635f\u5931\u548c\u51c6\u786e\u7387\u7b49\u6307\u6807\u3002<\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u3001\u6ce8\u610f\u4e8b\u9879\u6216\u76f8\u5173\u7684\u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u7684\u56fe\u50cf\u6570\u636e\u96c6\u683c\u5f0f\u6b63\u786e\uff0c\u5426\u5219\u6a21\u578b\u53ef\u80fd\u65e0\u6cd5\u8bad\u7ec3\u3002<\/li>\n<li>\u5728\u8bad\u7ec3\u6a21\u578b\u65f6\uff0c\u5982\u679c\u9047\u5230\u8fc7\u62df\u5408\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u51cf\u5c11\u7f51\u7edc\u6df1\u5ea6\u6216\u4f7f\u7528\u6b63\u5219\u5316\u6280\u672f\u3002<\/li>\n<li>\u5982\u679c\u6a21\u578b\u6027\u80fd\u4e0d\u4f73\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u589e\u52a0\u66f4\u591a\u7684\u8bad\u7ec3\u8fed\u4ee3\u6b21\u6570\u6216\u8c03\u6574\u5b66\u4e60\u7387\u3002<\/li>\n<li>\u5728\u5b9e\u9645\u90e8\u7f72AI\u786c\u4ef6\u5e73\u53f0\u65f6\uff0c\u8bf7\u786e\u4fdd\u786c\u4ef6\u914d\u7f6e\u6ee1\u8db3\u6a21\u578b\u8fd0\u884c\u7684\u9700\u6c42\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u4eba\u5de5\u667a\u80fd\u6280\u672f\u7684\u98de\u901f\u53d1\u5c55\uff0cAI\u786c\u4ef6\u5728\u6df1\u5ea6\u5b66\u4e60\u3001\u56fe\u50cf\u8bc6\u522b\u7b49\u9886\u57df\u626e\u6f14\u7740\u8d8a\u6765\u8d8a\u91cd\u8981\u7684\u89d2\u8272\u3002\u672c\u6587\u5c06\u4e3a\u60a8\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u642d\u5efa\u4e00\u4e2a\u57fa\u7840\u7684AI\u786c\u4ef6\u5e73\u53f0\uff0c\u5b9e\u73b0\u56fe\u50cf\u8bc6\u522b\u529f\u80fd\u3002\u6211\u4eec\u5c06\u4f7f\u7528Python\u7f16\u7a0b\u8bed\u8a00\u548cTensorFlow\u6846\u67b6\u6765\u5b8c\u6210\u8fd9\u4e00\u4efb\u52a1\u3002 \u64cd\u4f5c\u524d\u7684\u51c6\u5907&#8230;<\/p>\n","protected":false},"author":1,"featured_media":52,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-yun"],"_links":{"self":[{"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/posts\/881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":1,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions\/882"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/media\/52"}],"wp:attachment":[{"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/tags?post=881"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.loongdi.net\/blog\/wp-json\/wp\/v2\/topic?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}