{"id":1003594,"date":"2024-12-27T10:18:38","date_gmt":"2024-12-27T02:18:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1003594.html"},"modified":"2024-12-27T10:18:40","modified_gmt":"2024-12-27T02:18:40","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e8%af%86%e5%88%ab","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1003594.html","title":{"rendered":"python\u5982\u4f55\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080904\/7ce67f52-d94b-4024-8c21-f113fec828bc.webp\" alt=\"python\u5982\u4f55\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\" \/><\/p>\n<p><p> <strong>Python\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff08\u5982TensorFlow\u3001Keras\uff09\u3001\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff08\u5982OpenCV\uff09\u3001\u9884\u8bad\u7ec3\u6a21\u578b\uff08\u5982VGG\u3001ResNet\uff09\u7b49\u3002<\/strong>\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u6765\u8bad\u7ec3\u548c\u90e8\u7f72\u795e\u7ecf\u7f51\u7edc\uff0c\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\u63d0\u4f9b\u4e86\u56fe\u50cf\u5904\u7406\u548c\u7279\u5f81\u63d0\u53d6\u7684\u529f\u80fd\uff0c\u800c\u9884\u8bad\u7ec3\u6a21\u578b\u5219\u80fd\u6709\u6548\u5229\u7528\u5df2\u6709\u7684\u77e5\u8bc6\u8fdb\u884c\u56fe\u50cf\u5206\u7c7b\u548c\u8bc6\u522b\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u548c\u6280\u672f\u6765\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6<\/p>\n<\/p>\n<p><p>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u548cKeras\u4e3a\u6784\u5efa\u548c\u8bad\u7ec3\u795e\u7ecf\u7f51\u7edc\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u5de5\u5177\u3002\u8fd9\u4e9b\u6846\u67b6\u652f\u6301\u591a\u79cd\u795e\u7ecf\u7f51\u7edc\u7ed3\u6784\uff0c\u5982\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\uff0c\u9002\u7528\u4e8e\u56fe\u50cf\u8bc6\u522b\u4efb\u52a1\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>TensorFlow<\/strong><\/li>\n<\/ol>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u67b6\u6784\u548c\u5e7f\u6cdb\u7684API\u652f\u6301\u3002\u901a\u8fc7TensorFlow\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u590d\u6742\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\u6765\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5TensorFlow\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install tensorflow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528TensorFlow\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7528\u4e8e\u56fe\u7247\u8bc6\u522b\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528MNIST\u6570\u636e\u96c6\u6765\u8bad\u7ec3\u4e00\u4e2a\u6a21\u578b\u6765\u8bc6\u522b\u624b\u5199\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<p>from tensorflow.keras import layers, models<\/p>\n<h2><strong>\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>mnist = tf.keras.datasets.mnist<\/p>\n<p>(x_tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n, y_train), (x_test, y_test) = mnist.load_data()<\/p>\n<h2><strong>\u6570\u636e\u5f52\u4e00\u5316<\/strong><\/h2>\n<p>x_train, x_test = x_train \/ 255.0, x_test \/ 255.0<\/p>\n<h2><strong>\u6784\u5efa\u6a21\u578b<\/strong><\/h2>\n<p>model = models.Sequential([<\/p>\n<p>    layers.Flatten(input_shape=(28, 28)),<\/p>\n<p>    layers.Dense(128, activation=&#39;relu&#39;),<\/p>\n<p>    layers.Dropout(0.2),<\/p>\n<p>    layers.Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<h2><strong>\u7f16\u8bd1\u6a21\u578b<\/strong><\/h2>\n<p>model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;sparse_categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(x_train, y_train, epochs=5)<\/p>\n<h2><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>model.evaluate(x_test, y_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>Keras<\/strong><\/li>\n<\/ol>\n<p><p>Keras\u662f\u4e00\u4e2a\u9ad8\u5c42\u795e\u7ecf\u7f51\u7edcAPI\uff0c\u80fd\u591f\u8fd0\u884c\u5728TensorFlow\u4e4b\u4e0a\u3002\u5b83\u7b80\u5316\u4e86\u6a21\u578b\u7684\u6784\u5efa\u548c\u8bad\u7ec3\u8fc7\u7a0b\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u539f\u578b\u5f00\u53d1\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Keras\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684CNN\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u7684\u8fc7\u7a0b\u4e0eTensorFlow\u7c7b\u4f3c\uff0c\u53ea\u662fKeras\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u61c2\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tensorflow.keras.models import Sequential<\/p>\n<p>from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D<\/p>\n<h2><strong>\u6784\u5efa\u6a21\u578b<\/strong><\/h2>\n<p>model = Sequential([<\/p>\n<p>    Conv2D(32, kernel_size=(3, 3), activation=&#39;relu&#39;, input_shape=(28, 28, 1)),<\/p>\n<p>    MaxPooling2D(pool_size=(2, 2)),<\/p>\n<p>    Flatten(),<\/p>\n<p>    Dense(128, activation=&#39;relu&#39;),<\/p>\n<p>    Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<h2><strong>\u7f16\u8bd1\u6a21\u578b<\/strong><\/h2>\n<p>model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;sparse_categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(x_train, y_train, epochs=5)<\/p>\n<h2><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>model.evaluate(x_test, y_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93<\/p>\n<\/p>\n<p><p>\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\u5982OpenCV\u4e3a\u56fe\u50cf\u5904\u7406\u548c\u7279\u5f81\u63d0\u53d6\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u7528\u4e8e\u56fe\u50cf\u9884\u5904\u7406\u3001\u7279\u5f81\u68c0\u6d4b\u548c\u63cf\u8ff0\u7b26\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>OpenCV<\/strong><\/li>\n<\/ol>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u8ba1\u7b97\u673a\u89c6\u89c9\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u8f6f\u4ef6\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u4e8e\u56fe\u7247\u8bc6\u522b\u7684\u9884\u5904\u7406\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528OpenCV\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4f7f\u7528OpenCV\u8fdb\u884c\u7b80\u5355\u56fe\u7247\u5904\u7406\u548c\u7279\u5f81\u63d0\u53d6\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;image.jpg&#39;, cv2.IMREAD_GRAYSCALE)<\/p>\n<h2><strong>\u56fe\u50cf\u5e73\u6ed1\u5904\u7406<\/strong><\/h2>\n<p>blurred_image = cv2.GaussianBlur(image, (5, 5), 0)<\/p>\n<h2><strong>\u8fb9\u7f18\u68c0\u6d4b<\/strong><\/h2>\n<p>edges = cv2.Canny(blurred_image, 100, 200)<\/p>\n<h2><strong>\u663e\u793a\u5904\u7406\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Edges&#39;, edges)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7OpenCV\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u5404\u79cd\u5904\u7406\uff0c\u5982\u8fb9\u7f18\u68c0\u6d4b\u3001\u7279\u5f81\u63d0\u53d6\u7b49\uff0c\u8fd9\u4e9b\u5904\u7406\u53ef\u4ee5\u4e3a\u540e\u7eed\u7684\u56fe\u7247\u8bc6\u522b\u63d0\u4f9b\u6709\u6548\u7684\u7279\u5f81\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u9884\u8bad\u7ec3\u6a21\u578b<\/p>\n<\/p>\n<p><p>\u9884\u8bad\u7ec3\u6a21\u578b\u5982VGG\u3001ResNet\u7b49\u5df2\u7ecf\u5728\u5927\u578b\u6570\u636e\u96c6\u4e0a\u8fdb\u884c\u4e86\u8bad\u7ec3\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u56fe\u7247\u8bc6\u522b\u4efb\u52a1\uff0c\u6216\u8005\u4f5c\u4e3a\u7279\u5f81\u63d0\u53d6\u5668\u7528\u4e8e\u8fc1\u79fb\u5b66\u4e60\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528VGG\u6a21\u578b<\/strong><\/li>\n<\/ol>\n<p><p>VGG\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\uff0c\u5b83\u5728ImageNet\u6570\u636e\u96c6\u4e0a\u8fdb\u884c\u4e86\u8bad\u7ec3\uff0c\u53ef\u4ee5\u7528\u4e8e\u591a\u79cd\u56fe\u7247\u8bc6\u522b\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Keras\u4e2d\u9884\u8bad\u7ec3\u7684VGG\u6a21\u578b\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tensorflow.keras.applications import VGG16<\/p>\n<p>from tensorflow.keras.preprocessing import image<\/p>\n<p>from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7dVGG16\u6a21\u578b<\/strong><\/h2>\n<p>model = VGG16(weights=&#39;imagenet&#39;)<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf\u5e76\u9884\u5904\u7406<\/strong><\/h2>\n<p>img_path = &#39;elephant.jpg&#39;<\/p>\n<p>img = image.load_img(img_path, target_size=(224, 224))<\/p>\n<p>x = image.img_to_array(img)<\/p>\n<p>x = np.expand_dims(x, axis=0)<\/p>\n<p>x = preprocess_input(x)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>preds = model.predict(x)<\/p>\n<p>print(&#39;Predicted:&#39;, decode_predictions(preds, top=3)[0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528ResNet\u6a21\u578b<\/strong><\/li>\n<\/ol>\n<p><p>ResNet\u662f\u53e6\u4e00\u79cd\u5f3a\u5927\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u6b8b\u5dee\u5b66\u4e60\u89e3\u51b3\u4e86\u6df1\u5ea6\u7f51\u7edc\u7684\u9000\u5316\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Keras\u4e2d\u9884\u8bad\u7ec3\u7684ResNet\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tensorflow.keras.applications import ResNet50<\/p>\n<p>from tensorflow.keras.preprocessing import image<\/p>\n<p>from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7dResNet50\u6a21\u578b<\/strong><\/h2>\n<p>model = ResNet50(weights=&#39;imagenet&#39;)<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf\u5e76\u9884\u5904\u7406<\/strong><\/h2>\n<p>img_path = &#39;cat.jpg&#39;<\/p>\n<p>img = image.load_img(img_path, target_size=(224, 224))<\/p>\n<p>x = image.img_to_array(img)<\/p>\n<p>x = np.expand_dims(x, axis=0)<\/p>\n<p>x = preprocess_input(x)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>preds = model.predict(x)<\/p>\n<p>print(&#39;Predicted:&#39;, decode_predictions(preds, top=3)[0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6570\u636e\u9884\u5904\u7406\u548c\u589e\u5f3a<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u4e4b\u524d\uff0c\u6570\u636e\u9884\u5904\u7406\u548c\u589e\u5f3a\u662f\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u901a\u8fc7\u6570\u636e\u9884\u5904\u7406\uff0c\u6211\u4eec\u53ef\u4ee5\u6807\u51c6\u5316\u56fe\u50cf\u6570\u636e\uff0c\u6539\u5584\u6a21\u578b\u7684\u8bad\u7ec3\u6548\u679c\uff1b\u800c\u901a\u8fc7\u6570\u636e\u589e\u5f3a\uff0c\u6211\u4eec\u53ef\u4ee5\u4eba\u4e3a\u589e\u52a0\u6570\u636e\u96c6\u7684\u591a\u6837\u6027\uff0c\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u9884\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u636e\u9884\u5904\u7406\u662f\u6307\u5bf9\u56fe\u50cf\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\uff0c\u4ee5\u4fbf\u4e8e\u6a21\u578b\u7684\u8bad\u7ec3\u3002\u5e38\u89c1\u7684\u9884\u5904\u7406\u65b9\u6cd5\u5305\u62ec\u5f52\u4e00\u5316\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tensorflow.keras.preprocessing.image import ImageDataGenerator<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u751f\u6210\u5668<\/strong><\/h2>\n<p>datagen = ImageDataGenerator(<\/p>\n<p>    rescale=1.\/255,<\/p>\n<p>    rotation_range=20,<\/p>\n<p>    width_shift_range=0.2,<\/p>\n<p>    height_shift_range=0.2,<\/p>\n<p>    shear_range=0.2,<\/p>\n<p>    zoom_range=0.2,<\/p>\n<p>    horizontal_flip=True,<\/p>\n<p>    fill_mode=&#39;nearest&#39;<\/p>\n<p>)<\/p>\n<h2><strong>\u751f\u6210\u589e\u5f3a\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>train_generator = datagen.flow_from_directory(<\/p>\n<p>    &#39;data\/train&#39;,<\/p>\n<p>    target_size=(150, 150),<\/p>\n<p>    batch_size=32,<\/p>\n<p>    class_mode=&#39;binary&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6570\u636e\u589e\u5f3a<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u636e\u589e\u5f3a\u662f\u901a\u8fc7\u5bf9\u539f\u59cb\u56fe\u50cf\u8fdb\u884c\u4e00\u7cfb\u5217\u53d8\u6362\uff0c\u751f\u6210\u65b0\u7684\u8bad\u7ec3\u6837\u672c\uff0c\u4ece\u800c\u589e\u52a0\u6570\u636e\u96c6\u7684\u591a\u6837\u6027\u3002\u5e38\u7528\u7684\u6570\u636e\u589e\u5f3a\u65b9\u6cd5\u5305\u62ec\u968f\u673a\u7ffb\u8f6c\u3001\u7f29\u653e\u3001\u65cb\u8f6c\u3001\u5e73\u79fb\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u6570\u636e\u589e\u5f3a\uff0c\u6211\u4eec\u53ef\u4ee5\u6709\u6548\u5730\u589e\u52a0\u8bad\u7ec3\u6570\u636e\u7684\u591a\u6837\u6027\uff0c\u4ece\u800c\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6570\u636e\u589e\u5f3a\u793a\u4f8b<\/p>\n<p>augmented_images = datagen.flow(x_train, y_train, batch_size=32)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(augmented_images, epochs=50)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7Python\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u3001\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\u4ee5\u53ca\u9884\u8bad\u7ec3\u6a21\u578b\u7b49\u5de5\u5177\u3002\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u548c\u8bad\u7ec3\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\uff0c\u5bf9\u56fe\u50cf\u8fdb\u884c\u9884\u5904\u7406\u548c\u589e\u5f3a\uff0c\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u8bc6\u522b\u80fd\u529b\u548c\u6cdb\u5316\u80fd\u529b\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u4efb\u52a1\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u56fe\u7247\u8bc6\u522b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u7684\u57fa\u7840\u77e5\u8bc6\uff1f<\/strong><br \/>Python\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u901a\u5e38\u4f9d\u8d56\u4e8e\u6df1\u5ea6\u5b66\u4e60\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u4f8b\u5982OpenCV\u548cTensorFlow\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u4f60\u53ef\u4ee5\u52a0\u8f7d\u3001\u5904\u7406\u548c\u5206\u6790\u56fe\u50cf\u6570\u636e\u3002\u7406\u89e3\u56fe\u50cf\u7684\u57fa\u672c\u7279\u5f81\u3001\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u7684\u7ed3\u6784\u4ee5\u53ca\u6570\u636e\u9884\u5904\u7406\u6280\u672f\u662f\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\u7684\u5173\u952e\u3002<\/p>\n<p><strong>\u9700\u8981\u54ea\u4e9b\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5e38\u7528\u7684\u5e93\u5305\u62ecOpenCV\u3001PIL\uff08Pillow\uff09\u3001TensorFlow\u3001Keras\u548cPyTorch\u7b49\u3002OpenCV\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff0cPIL\u7528\u4e8e\u57fa\u672c\u7684\u56fe\u50cf\u64cd\u4f5c\uff0c\u800cTensorFlow\u548cPyTorch\u5219\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6784\u5efa\u548c\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002\u5b89\u88c5\u8fd9\u4e9b\u5e93\u540e\uff0c\u4f60\u53ef\u4ee5\u5f00\u59cb\u6784\u5efa\u81ea\u5df1\u7684\u56fe\u7247\u8bc6\u522b\u9879\u76ee\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u9ad8\u56fe\u7247\u8bc6\u522b\u7684\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u63d0\u9ad8\u56fe\u7247\u8bc6\u522b\u51c6\u786e\u6027\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u66f4\u590d\u6742\u7684\u6a21\u578b\u3001\u589e\u52a0\u8bad\u7ec3\u6570\u636e\u96c6\u3001\u6570\u636e\u589e\u5f3a\u6280\u672f\u4ee5\u53ca\u8c03\u6574\u6a21\u578b\u53c2\u6570\u3002\u4f7f\u7528\u9884\u8bad\u7ec3\u6a21\u578b\uff08\u5982VGG\u3001ResNet\u7b49\uff09\u4e5f\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8bc6\u522b\u7387\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u6570\u636e\u96c6\u7684\u591a\u6837\u6027\u548c\u4ee3\u8868\u6027\u6709\u52a9\u4e8e\u6a21\u578b\u5b66\u4e60\u5230\u66f4\u6709\u6548\u7684\u7279\u5f81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5b9e\u73b0\u56fe\u7247\u8bc6\u522b\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff08\u5982TensorFlow\u3001Keras\uff09\u3001\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff08 [&hellip;]","protected":false},"author":3,"featured_media":1003599,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003594"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1003594"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003594\/revisions"}],"predecessor-version":[{"id":1003601,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1003594\/revisions\/1003601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1003599"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1003594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1003594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1003594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}