{"id":1110412,"date":"2025-01-08T17:19:32","date_gmt":"2025-01-08T09:19:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1110412.html"},"modified":"2025-01-08T17:19:34","modified_gmt":"2025-01-08T09:19:34","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e4%b8%80%e4%ba%9b%e5%9b%be%e7%89%87%e9%a3%8e%e6%a0%bc%e5%8c%96","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1110412.html","title":{"rendered":"Python\u5982\u4f55\u628a\u4e00\u4e9b\u56fe\u7247\u98ce\u683c\u5316"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073252\/1c1e5365-df5d-4f99-9cdc-4d288c5e77ff.webp\" alt=\"Python\u5982\u4f55\u628a\u4e00\u4e9b\u56fe\u7247\u98ce\u683c\u5316\" \/><\/p>\n<p><p> \u4e00\u3001Python\u5982\u4f55\u628a\u4e00\u4e9b\u56fe\u7247\u98ce\u683c\u5316<\/p>\n<\/p>\n<p><p><strong>Python\u5c06\u56fe\u7247\u98ce\u683c\u5316\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5e38\u89c1\u7684\u6709\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3001\u5229\u7528\u56fe\u50cf\u5904\u7406\u5e93\u3001\u901a\u8fc7\u6ee4\u955c\u548c\u7279\u6548\u6765\u5b9e\u73b0\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u662f\u6700\u5148\u8fdb\u7684\u6280\u672f\uff0c\u6548\u679c\u4e5f\u6700\u4f73\u3002<\/strong> \u4f8b\u5982\uff0c\u5229\u7528\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\uff08Neural Style Transfer\uff09\u53ef\u4ee5\u5c06\u4e00\u5f20\u56fe\u7247\u7684\u98ce\u683c\u8fc1\u79fb\u5230\u53e6\u4e00\u5f20\u56fe\u7247\u4e0a\u3002\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\u5229\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u6765\u63d0\u53d6\u56fe\u50cf\u7684\u5185\u5bb9\u548c\u98ce\u683c\u7279\u5f81\uff0c\u901a\u8fc7\u4f18\u5316\u7b97\u6cd5\u5c06\u8fd9\u4e24\u8005\u7ed3\u5408\u5728\u4e00\u8d77\uff0c\u4ece\u800c\u751f\u6210\u98ce\u683c\u5316\u7684\u56fe\u7247\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u56fe\u7247\u98ce\u683c\u5316\u7684\u591a\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u8fdb\u884c\u56fe\u7247\u98ce\u683c\u5316\u662f\u5f53\u524d\u6700\u70ed\u95e8\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u5c24\u5176\u662f\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\uff08Neural Style Transfer\uff09\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u662f\u5c06\u4e00\u5f20\u56fe\u50cf\u7684\u5185\u5bb9\u4e0e\u53e6\u4e00\u5f20\u56fe\u50cf\u7684\u98ce\u683c\u8fdb\u884c\u7ed3\u5408\uff0c\u751f\u6210\u65b0\u7684\u98ce\u683c\u5316\u56fe\u50cf\u3002\u5e38\u7528\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u6709TensorFlow\u548cPyTorch\u3002<\/p>\n<\/p>\n<ol>\n<li>TensorFlow\u5b9e\u73b0\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb<\/li>\n<\/ol>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684API\u6765\u5b9e\u73b0\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<p>from tensorflow.keras.applications import VGG19<\/p>\n<p>from tensorflow.keras.preprocessing.image import load_img, img_to_array<\/p>\n<p>from tensorflow.keras.models import Model<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7d\u5185\u5bb9\u56fe\u50cf\u548c\u98ce\u683c\u56fe\u50cf<\/strong><\/h2>\n<p>content_image = load_img(&#39;content.jpg&#39;)<\/p>\n<p>style_image = load_img(&#39;style.jpg&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/h2>\n<p>content_array = img_to_array(content_image)<\/p>\n<p>style_array = img_to_array(style_image)<\/p>\n<h2><strong>\u9884\u5904\u7406\u56fe\u50cf<\/strong><\/h2>\n<p>content_array = tf.keras.applications.vgg19.preprocess_input(content_array)<\/p>\n<p>style_array = tf.keras.applications.vgg19.preprocess_input(style_array)<\/p>\n<h2><strong>\u52a0\u8f7dVGG19\u6a21\u578b<\/strong><\/h2>\n<p>vgg = VGG19(include_top=False, weights=&#39;imagenet&#39;)<\/p>\n<p>vgg.tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nable = False<\/p>\n<h2><strong>\u63d0\u53d6\u5185\u5bb9\u548c\u98ce\u683c\u7279\u5f81<\/strong><\/h2>\n<p>content_layer = &#39;block5_conv2&#39;<\/p>\n<p>style_layers = [&#39;block1_conv1&#39;, &#39;block2_conv1&#39;, &#39;block3_conv1&#39;, &#39;block4_conv1&#39;, &#39;block5_conv1&#39;]<\/p>\n<p>content_model = Model(inputs=vgg.input, outputs=vgg.get_layer(content_layer).output)<\/p>\n<p>style_models = [Model(inputs=vgg.input, outputs=vgg.get_layer(layer).output) for layer in style_layers]<\/p>\n<h2><strong>\u5b9a\u4e49\u635f\u5931\u51fd\u6570<\/strong><\/h2>\n<p>def compute_loss(content_output, style_outputs, generated_output):<\/p>\n<p>    content_loss = tf.reduce_mean((generated_output - content_output)  2)<\/p>\n<p>    style_loss = 0<\/p>\n<p>    for style_output, generated_style in zip(style_outputs, generated_output):<\/p>\n<p>        style_loss += tf.reduce_mean((generated_style - style_output)  2)<\/p>\n<p>    total_loss = content_loss + style_loss<\/p>\n<p>    return total_loss<\/p>\n<h2><strong>\u4f18\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>generated_image = tf.Variable(content_array)<\/p>\n<p>optimizer = tf.optimizers.Adam(learning_rate=0.02)<\/p>\n<p>for step in range(1000):<\/p>\n<p>    with tf.GradientTape() as tape:<\/p>\n<p>        generated_output = content_model(generated_image)<\/p>\n<p>        style_outputs = [style_model(generated_image) for style_model in style_models]<\/p>\n<p>        loss = compute_loss(content_model(content_array), style_outputs, generated_output)<\/p>\n<p>    grads = tape.gradient(loss, generated_image)<\/p>\n<p>    optimizer.apply_gradients([(grads, generated_image)])<\/p>\n<h2><strong>\u53cd\u9884\u5904\u7406\u56fe\u50cf<\/strong><\/h2>\n<p>generated_image = tf.keras.applications.vgg19.deprocess_input(generated_image.numpy())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>PyTorch\u5b9e\u73b0\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb<\/li>\n<\/ol>\n<p><p>PyTorch\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528PyTorch\u5b9e\u73b0\u795e\u7ecf\u98ce\u683c\u8fc1\u79fb\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import torch<\/p>\n<p>import torch.nn as nn<\/p>\n<p>import torch.optim as optim<\/p>\n<p>from torchvision import models, transforms<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\u5185\u5bb9\u56fe\u50cf\u548c\u98ce\u683c\u56fe\u50cf<\/strong><\/h2>\n<p>content_image = Image.open(&#39;content.jpg&#39;)<\/p>\n<p>style_image = Image.open(&#39;style.jpg&#39;)<\/p>\n<h2><strong>\u56fe\u50cf\u9884\u5904\u7406<\/strong><\/h2>\n<p>transform = transforms.Compose([<\/p>\n<p>    transforms.Resize((512, 512)),<\/p>\n<p>    transforms.ToTensor(),<\/p>\n<p>    transforms.Lambda(lambda x: x.mul(255))<\/p>\n<p>])<\/p>\n<p>content_tensor = transform(content_image).unsqueeze(0)<\/p>\n<p>style_tensor = transform(style_image).unsqueeze(0)<\/p>\n<h2><strong>\u52a0\u8f7dVGG19\u6a21\u578b<\/strong><\/h2>\n<p>vgg = models.vgg19(pretrained=True).features<\/p>\n<p>for param in vgg.parameters():<\/p>\n<p>    param.requires_grad_(False)<\/p>\n<h2><strong>\u63d0\u53d6\u5185\u5bb9\u548c\u98ce\u683c\u7279\u5f81<\/strong><\/h2>\n<p>def get_features(image, model):<\/p>\n<p>    layers = {<\/p>\n<p>        &#39;0&#39;: &#39;conv1_1&#39;,<\/p>\n<p>        &#39;5&#39;: &#39;conv2_1&#39;,<\/p>\n<p>        &#39;10&#39;: &#39;conv3_1&#39;,<\/p>\n<p>        &#39;19&#39;: &#39;conv4_1&#39;,<\/p>\n<p>        &#39;21&#39;: &#39;conv4_2&#39;,  # content layer<\/p>\n<p>        &#39;28&#39;: &#39;conv5_1&#39;<\/p>\n<p>    }<\/p>\n<p>    features = {}<\/p>\n<p>    x = image<\/p>\n<p>    for name, layer in model._modules.items():<\/p>\n<p>        x = layer(x)<\/p>\n<p>        if name in layers:<\/p>\n<p>            features[layers[name]] = x<\/p>\n<p>    return features<\/p>\n<p>content_features = get_features(content_tensor, vgg)<\/p>\n<p>style_features = get_features(style_tensor, vgg)<\/p>\n<h2><strong>\u8ba1\u7b97\u98ce\u683c\u77e9\u9635<\/strong><\/h2>\n<p>def gram_matrix(tensor):<\/p>\n<p>    _, d, h, w = tensor.size()<\/p>\n<p>    tensor = tensor.view(d, h * w)<\/p>\n<p>    gram = torch.mm(tensor, tensor.t())<\/p>\n<p>    return gram<\/p>\n<p>style_grams = {layer: gram_matrix(style_features[layer]) for layer in style_features}<\/p>\n<h2><strong>\u5b9a\u4e49\u635f\u5931\u51fd\u6570<\/strong><\/h2>\n<p>def compute_loss(content_features, style_grams, target_features):<\/p>\n<p>    content_loss = torch.mean((target_features[&#39;conv4_2&#39;] - content_features[&#39;conv4_2&#39;])  2)<\/p>\n<p>    style_loss = 0<\/p>\n<p>    for layer in style_grams:<\/p>\n<p>        target_feature = target_features[layer]<\/p>\n<p>        target_gram = gram_matrix(target_feature)<\/p>\n<p>        style_gram = style_grams[layer]<\/p>\n<p>        layer_loss = torch.mean((target_gram - style_gram)  2)<\/p>\n<p>        style_loss += layer_loss<\/p>\n<p>    total_loss = content_loss + style_loss<\/p>\n<p>    return total_loss<\/p>\n<h2><strong>\u4f18\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>target = content_tensor.clone().requires_grad_(True)<\/p>\n<p>optimizer = optim.Adam([target], lr=0.003)<\/p>\n<p>for step in range(2000):<\/p>\n<p>    target_features = get_features(target, vgg)<\/p>\n<p>    loss = compute_loss(content_features, style_grams, target_features)<\/p>\n<p>    optimizer.zero_grad()<\/p>\n<p>    loss.backward()<\/p>\n<p>    optimizer.step()<\/p>\n<h2><strong>\u8f6c\u6362\u56fe\u50cf\u683c\u5f0f<\/strong><\/h2>\n<p>target = target.squeeze().detach().cpu().numpy().transpose(1, 2, 0)<\/p>\n<p>target = np.clip(target, 0, 255).astype(&#39;uint8&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u56fe\u50cf\u5904\u7406\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u8fdb\u884c\u56fe\u7247\u98ce\u683c\u5316\uff0cPython\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982PIL\uff08Pillow\uff09\u3001OpenCV\u7b49\u3002\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u5b9e\u73b0\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\uff0c\u5982\u6ee4\u955c\u3001\u7279\u6548\u7b49\uff0c\u4ece\u800c\u8fbe\u5230\u98ce\u683c\u5316\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<ol>\n<li>PIL\uff08Pillow\uff09<\/li>\n<\/ol>\n<p><p>Pillow\u662fPython Imaging Library\u7684\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Pillow\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageFilter, ImageEnhance<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;image.jpg&#39;)<\/p>\n<h2><strong>\u5e94\u7528\u6ee4\u955c<\/strong><\/h2>\n<p>image = image.filter(ImageFilter.DETAIL)<\/p>\n<h2><strong>\u589e\u5f3a\u5bf9\u6bd4\u5ea6<\/strong><\/h2>\n<p>enhancer = ImageEnhance.Contrast(image)<\/p>\n<p>image = enhancer.enhance(2.0)<\/p>\n<h2><strong>\u4fdd\u5b58\u98ce\u683c\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&#39;stylized_image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>OpenCV<\/li>\n<\/ol>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u56fe\u50cf\u5904\u7406\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528OpenCV\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;image.jpg&#39;)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf<\/strong><\/h2>\n<p>gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<\/p>\n<h2><strong>\u5e94\u7528\u9ad8\u65af\u6a21\u7cca<\/strong><\/h2>\n<p>blurred = cv2.GaussianBlur(gray, (21, 21), 0)<\/p>\n<h2><strong>\u68c0\u6d4b\u8fb9\u7f18<\/strong><\/h2>\n<p>edges = cv2.Canny(blurred, 50, 150)<\/p>\n<h2><strong>\u53cd\u8f6c\u989c\u8272<\/strong><\/h2>\n<p>edges = cv2.bitwise_not(edges)<\/p>\n<h2><strong>\u5408\u5e76\u8fb9\u7f18\u548c\u539f\u59cb\u56fe\u50cf<\/strong><\/h2>\n<p>stylized_image = cv2.bitwise_and(image, image, mask=edges)<\/p>\n<h2><strong>\u4fdd\u5b58\u98ce\u683c\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;stylized_image.jpg&#39;, stylized_image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6ee4\u955c\u548c\u7279\u6548<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u548c\u56fe\u50cf\u5904\u7406\u5e93\uff0cPython\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u6ee4\u955c\u548c\u7279\u6548\u6765\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6ee4\u955c\u548c\u7279\u6548\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6000\u65e7\u6ee4\u955c<\/li>\n<\/ol>\n<p><p>\u6000\u65e7\u6ee4\u955c\u53ef\u4ee5\u8ba9\u56fe\u50cf\u770b\u8d77\u6765\u50cf\u65e7\u7167\u7247\u4e00\u6837\uff0c\u589e\u52a0\u590d\u53e4\u611f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u73b0\u6000\u65e7\u6ee4\u955c\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;image.jpg&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u6000\u65e7\u6ee4\u955c<\/strong><\/h2>\n<p>filter = np.array([[0.272, 0.534, 0.131],<\/p>\n<p>                   [0.349, 0.686, 0.168],<\/p>\n<p>                   [0.393, 0.769, 0.189]])<\/p>\n<h2><strong>\u5e94\u7528\u6ee4\u955c<\/strong><\/h2>\n<p>stylized_image = cv2.transform(image, filter)<\/p>\n<h2><strong>\u4fdd\u5b58\u98ce\u683c\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;stylized_image.jpg&#39;, stylized_image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u5361\u901a\u7279\u6548<\/li>\n<\/ol>\n<p><p>\u5361\u901a\u7279\u6548\u53ef\u4ee5\u8ba9\u56fe\u50cf\u770b\u8d77\u6765\u50cf\u5361\u901a\u753b\u4e00\u6837\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u73b0\u5361\u901a\u7279\u6548\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;image.jpg&#39;)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf<\/strong><\/h2>\n<p>gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<\/p>\n<h2><strong>\u5e94\u7528\u9ad8\u65af\u6a21\u7cca<\/strong><\/h2>\n<p>blurred = cv2.GaussianBlur(gray, (5, 5), 0)<\/p>\n<h2><strong>\u68c0\u6d4b\u8fb9\u7f18<\/strong><\/h2>\n<p>edges = cv2.Canny(blurred, 100, 200)<\/p>\n<h2><strong>\u53cd\u8f6c\u989c\u8272<\/strong><\/h2>\n<p>edges = cv2.bitwise_not(edges)<\/p>\n<h2><strong>\u5e94\u7528\u9ad8\u65af\u6a21\u7cca<\/strong><\/h2>\n<p>color = cv2.bilateralFilter(image, 9, 300, 300)<\/p>\n<h2><strong>\u5408\u5e76\u8fb9\u7f18\u548c\u989c\u8272\u56fe\u50cf<\/strong><\/h2>\n<p>stylized_image = cv2.bitwise_and(color, color, mask=edges)<\/p>\n<h2><strong>\u4fdd\u5b58\u98ce\u683c\u5316\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;stylized_image.jpg&#39;, stylized_image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u5230Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\uff0c\u5305\u62ec\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3001\u56fe\u50cf\u5904\u7406\u5e93\u4ee5\u53ca\u5e94\u7528\u6ee4\u955c\u548c\u7279\u6548\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u53ef\u4ee5\u5b9e\u73b0\u6700\u5148\u8fdb\u7684\u98ce\u683c\u5316\u6548\u679c\uff0c\u4f46\u9700\u8981\u8f83\u9ad8\u7684\u8ba1\u7b97\u8d44\u6e90\uff1b\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u5e93\u5219\u66f4\u52a0\u7075\u6d3b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5404\u79cd\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\uff1b\u5e94\u7528\u6ee4\u955c\u548c\u7279\u6548\u5219\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u5feb\u901f\u5b9e\u73b0\u7279\u5b9a\u6548\u679c\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5b9e\u73b0\u56fe\u7247\u98ce\u683c\u5316\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u5e93\uff0c\u5982TensorFlow\u6216PyTorch\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e86\u9884\u8bad\u7ec3\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\uff0c\u80fd\u591f\u5c06\u8f93\u5165\u56fe\u50cf\u8f6c\u6362\u4e3a\u827a\u672f\u98ce\u683c\u7684\u56fe\u50cf\u3002\u5177\u4f53\u6d41\u7a0b\u5305\u62ec\u52a0\u8f7d\u56fe\u50cf\u3001\u9009\u62e9\u98ce\u683c\u56fe\u50cf\u3001\u4f7f\u7528\u98ce\u683c\u8fc1\u79fb\u7b97\u6cd5\u5904\u7406\u56fe\u50cf\uff0c\u4ee5\u53ca\u4fdd\u5b58\u6216\u663e\u793a\u6700\u7ec8\u7ed3\u679c\u3002<\/p>\n<p><strong>\u54ea\u4e9bPython\u5e93\u9002\u5408\u8fdb\u884c\u56fe\u50cf\u98ce\u683c\u5316\uff1f<\/strong><br \/>\u8fdb\u884c\u56fe\u50cf\u98ce\u683c\u5316\u65f6\uff0c\u5e38\u7528\u7684Python\u5e93\u5305\u62ecTensorFlow\u3001Keras\u548cPyTorch\uff0c\u5b83\u4eec\u90fd\u6709\u5f3a\u5927\u7684\u795e\u7ecf\u7f51\u7edc\u529f\u80fd\u3002\u6b64\u5916\uff0cOpenCV\u4e5f\u53ef\u4ee5\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u548c\u9884\u5904\u7406\u3002\u4f7f\u7528\u8fd9\u4e9b\u5e93\u65f6\uff0c\u53ef\u4ee5\u627e\u5230\u8bb8\u591a\u793a\u4f8b\u4ee3\u7801\u548c\u6559\u7a0b\uff0c\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u5165\u95e8\u3002<\/p>\n<p><strong>\u98ce\u683c\u8fc1\u79fb\u7684\u6548\u679c\u5982\u4f55\u8bc4\u4f30\uff1f<\/strong><br \/>\u8bc4\u4f30\u98ce\u683c\u8fc1\u79fb\u6548\u679c\u901a\u5e38\u6d89\u53ca\u5230\u4e3b\u89c2\u548c\u5ba2\u89c2\u4e24\u4e2a\u65b9\u9762\u3002\u4e3b\u89c2\u65b9\u9762\uff0c\u53ef\u4ee5\u901a\u8fc7\u89c6\u89c9\u6548\u679c\u6765\u5224\u65ad\u98ce\u683c\u5316\u56fe\u50cf\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u5ba2\u89c2\u65b9\u9762\uff0c\u53ef\u4ee5\u8ba1\u7b97\u5185\u5bb9\u635f\u5931\u548c\u98ce\u683c\u635f\u5931\uff0c\u4f7f\u7528\u8fd9\u4e9b\u635f\u5931\u503c\u6765\u91cf\u5316\u56fe\u50cf\u7684\u98ce\u683c\u5316\u7a0b\u5ea6\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7528\u6237\u53cd\u9988\u6216\u4e13\u4e1a\u8bc4\u5ba1\u6765\u83b7\u53d6\u66f4\u5168\u9762\u7684\u8bc4\u4f30\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001Python\u5982\u4f55\u628a\u4e00\u4e9b\u56fe\u7247\u98ce\u683c\u5316 Python\u5c06\u56fe\u7247\u98ce\u683c\u5316\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5e38\u89c1\u7684\u6709\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3001\u5229\u7528\u56fe\u50cf [&hellip;]","protected":false},"author":3,"featured_media":1110424,"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\/1110412"}],"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=1110412"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1110412\/revisions"}],"predecessor-version":[{"id":1110426,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1110412\/revisions\/1110426"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1110424"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1110412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1110412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1110412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}