{"id":6311,"date":"2024-07-12T11:16:46","date_gmt":"2024-07-12T03:16:46","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6311"},"modified":"2024-07-12T11:20:52","modified_gmt":"2024-07-12T03:20:52","slug":"%e5%9b%be%e5%83%8f%e7%9b%b8%e4%bc%bc%e6%80%a7%e6%a3%80%e6%b5%8b%e5%8f%8a%e8%b4%a8%e9%87%8f%e8%af%84%e4%bc%b0","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6311","title":{"rendered":"\u56fe\u50cf\u76f8\u4f3c\u6027\u68c0\u6d4b\u53ca\u8d28\u91cf\u8bc4\u4f30"},"content":{"rendered":"<p>\u5728 iOS \u5e94\u7528\u4e2d\u5b9e\u73b0\u68c0\u6d4b\u76f8\u518c\u91cc\u7684\u76f8\u4f3c\u56fe\u7247\u5e76\u63a8\u8350\u8d28\u91cf\u6700\u597d\u7684\u90a3\u5f20\uff0c\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u6280\u672f\u548c\u6b65\u9aa4\uff1a<\/p>\n<h3>1. \u56fe\u50cf\u76f8\u4f3c\u6027\u68c0\u6d4b<\/h3>\n<h4>\u6280\u672f\uff1a<\/h4>\n<ul>\n<li><strong>\u56fe\u50cf\u7279\u5f81\u63d0\u53d6<\/strong>\uff1a\u4f7f\u7528\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u7b49\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u63d0\u53d6\u56fe\u50cf\u7279\u5f81\u3002\u5e38\u7528\u7684\u9884\u8bad\u7ec3\u6a21\u578b\u6709 VGG\u3001ResNet \u7b49\u3002<\/li>\n<li><strong>\u7279\u5f81\u5339\u914d<\/strong>\uff1a\u5c06\u63d0\u53d6\u7684\u56fe\u50cf\u7279\u5f81\u5411\u91cf\u8fdb\u884c\u5339\u914d\uff0c\u4f7f\u7528\u6b27\u6c0f\u8ddd\u79bb\u3001\u4f59\u5f26\u76f8\u4f3c\u5ea6\u7b49\u5ea6\u91cf\u65b9\u6cd5\u8ba1\u7b97\u76f8\u4f3c\u6027\u3002<\/li>\n<\/ul>\n<h4>\u5b9e\u73b0\uff1a<\/h4>\n<ul>\n<li><strong>Core ML<\/strong>\uff1a\u5229\u7528 Core ML \u5c06\u8bad\u7ec3\u597d\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u5bfc\u5165\u5230 iOS \u5e94\u7528\u4e2d\uff0c\u8fdb\u884c\u56fe\u50cf\u7279\u5f81\u63d0\u53d6\u3002<\/li>\n<li><strong>Vision \u6846\u67b6<\/strong>\uff1a\u82f9\u679c\u7684 Vision \u6846\u67b6\u53ef\u4ee5\u8fdb\u884c\u56fe\u50cf\u5206\u6790\u548c\u5904\u7406\uff0c\u5982\u4eba\u8138\u68c0\u6d4b\u3001\u7269\u4f53\u8bc6\u522b\u7b49\uff0c\u8f85\u52a9\u5b9e\u73b0\u56fe\u50cf\u76f8\u4f3c\u6027\u68c0\u6d4b\u3002<\/li>\n<\/ul>\n<h3>2. \u56fe\u50cf\u8d28\u91cf\u8bc4\u4f30<\/h3>\n<h4>\u6280\u672f\uff1a<\/h4>\n<ul>\n<li><strong>\u56fe\u50cf\u6e05\u6670\u5ea6\u68c0\u6d4b<\/strong>\uff1a\u4f7f\u7528\u62c9\u666e\u62c9\u65af\u53d8\u6362\u7b49\u65b9\u6cd5\u68c0\u6d4b\u56fe\u50cf\u7684\u6e05\u6670\u5ea6\u3002<\/li>\n<li><strong>\u56fe\u50cf\u7f8e\u5b66\u8bc4\u5206<\/strong>\uff1a\u5229\u7528\u8bad\u7ec3\u597d\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u8bc4\u4f30\u56fe\u50cf\u7684\u7f8e\u5b66\u8bc4\u5206\u3002<\/li>\n<li><strong>\u56fe\u50cf\u5b8c\u6574\u6027\u68c0\u67e5<\/strong>\uff1a\u68c0\u6d4b\u56fe\u50cf\u662f\u5426\u6709\u88c1\u526a\u3001\u65cb\u8f6c\u7b49\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h4>\u5b9e\u73b0\uff1a<\/h4>\n<ul>\n<li><strong>Core ML<\/strong>\uff1a\u540c\u6837\u53ef\u4ee5\u5229\u7528 Core ML \u5c06\u8bad\u7ec3\u597d\u7684\u56fe\u50cf\u8d28\u91cf\u8bc4\u4f30\u6a21\u578b\u5bfc\u5165\u5230\u5e94\u7528\u4e2d\u3002<\/li>\n<li><strong>Vision \u6846\u67b6<\/strong>\uff1a\u53ef\u4ee5\u7ed3\u5408 Vision \u6846\u67b6\u5bf9\u56fe\u50cf\u8fdb\u884c\u9884\u5904\u7406\u548c\u5206\u6790\u3002<\/li>\n<\/ul>\n<h3>3. \u6570\u636e\u5904\u7406\u548c\u7ba1\u7406<\/h3>\n<h4>\u6280\u672f\uff1a<\/h4>\n<ul>\n<li><strong>\u7167\u7247\u5e93\u8bbf\u95ee<\/strong>\uff1a\u4f7f\u7528 Photos \u6846\u67b6\u8bbf\u95ee\u7528\u6237\u7684\u76f8\u518c\u3002<\/li>\n<li><strong>\u591a\u7ebf\u7a0b\u5904\u7406<\/strong>\uff1a\u4e3a\u4e86\u5904\u7406\u5927\u91cf\u56fe\u7247\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528 GCD\uff08Grand Central Dispatch\uff09\u6216 OperationQueue \u8fdb\u884c\u591a\u7ebf\u7a0b\u5904\u7406\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<\/ul>\n<h4>\u5b9e\u73b0\uff1a<\/h4>\n<ul>\n<li><strong>Photos \u6846\u67b6<\/strong>\uff1a\u8bbf\u95ee\u76f8\u518c\u4e2d\u7684\u56fe\u7247\uff0c\u8bfb\u53d6\u56fe\u7247\u6570\u636e\u3002<\/li>\n<li><strong>GCD \/ OperationQueue<\/strong>\uff1a\u5728\u540e\u53f0\u7ebf\u7a0b\u5904\u7406\u56fe\u50cf\u5206\u6790\u4efb\u52a1\uff0c\u907f\u514d\u963b\u585e\u4e3b\u7ebf\u7a0b\u3002<\/li>\n<\/ul>\n<h3>\u5b9e\u73b0\u6b65\u9aa4\u603b\u7ed3<\/h3>\n<ol>\n<li><strong>\u8bbf\u95ee\u76f8\u518c<\/strong>\uff1a\u901a\u8fc7 Photos \u6846\u67b6\u83b7\u53d6\u76f8\u518c\u4e2d\u7684\u56fe\u7247\u3002<\/li>\n<li><strong>\u56fe\u50cf\u7279\u5f81\u63d0\u53d6<\/strong>\uff1a\u5229\u7528 Core ML \u52a0\u8f7d\u9884\u8bad\u7ec3\u7684 CNN \u6a21\u578b\uff0c\u63d0\u53d6\u6bcf\u5f20\u56fe\u7247\u7684\u7279\u5f81\u5411\u91cf\u3002<\/li>\n<li><strong>\u76f8\u4f3c\u6027\u8ba1\u7b97<\/strong>\uff1a\u8ba1\u7b97\u56fe\u7247\u7279\u5f81\u5411\u91cf\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\uff0c\u5206\u7ec4\u76f8\u4f3c\u56fe\u7247\u3002<\/li>\n<li><strong>\u8d28\u91cf\u8bc4\u4f30<\/strong>\uff1a\u4f7f\u7528 Core ML \u6a21\u578b\u8bc4\u4f30\u6bcf\u7ec4\u76f8\u4f3c\u56fe\u7247\u7684\u8d28\u91cf\uff0c\u9009\u62e9\u8d28\u91cf\u6700\u597d\u7684\u90a3\u5f20\u3002<\/li>\n<li><strong>\u63a8\u8350<\/strong>\uff1a\u5c06\u9009\u62e9\u7684\u6700\u4f73\u56fe\u7247\u63a8\u8350\u7ed9\u7528\u6237\u3002<\/li>\n<\/ol>\n<p>\u8fd9\u79cd\u5b9e\u73b0\u65b9\u6cd5\u7ed3\u5408\u4e86\u6df1\u5ea6\u5b66\u4e60\u3001\u56fe\u50cf\u5904\u7406\u548c\u591a\u7ebf\u7a0b\u6280\u672f\uff0c\u80fd\u591f\u6709\u6548\u5730\u8bc6\u522b\u548c\u63a8\u8350\u76f8\u518c\u4e2d\u7684\u6700\u4f73\u56fe\u7247\u3002<\/p>\n<p><strong>\u95ee\uff1a\u6709\u6ca1\u6709\u5f00\u6e90\u53ef\u7528\u7684\u7f8e\u5b66\u8bc4\u5206\u6a21\u578b\uff0c\u53ef\u4ee5\u5185\u7f6e\u5230 iOS \u8bbe\u5907\u6700\u4f73<\/strong><\/p>\n<p>\u786e\u5b9e\u6709\u4e00\u4e9b\u5f00\u6e90\u7684\u7f8e\u5b66\u8bc4\u5206\u6a21\u578b\u53ef\u4ee5\u5185\u7f6e\u5230 iOS \u8bbe\u5907\u4e2d\u6765\u8bc4\u4f30\u56fe\u50cf\u7684\u7f8e\u5b66\u8d28\u91cf\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u5f00\u6e90\u7f8e\u5b66\u8bc4\u5206\u6a21\u578b\u548c\u5b83\u4eec\u7684\u96c6\u6210\u65b9\u6cd5\uff1a<\/p>\n<h3>1. Aesthetic Visual Analysis (AVA) Dataset Model<\/h3>\n<p>AVA \u6570\u636e\u96c6\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6570\u636e\u96c6\uff0c\u7528\u4e8e\u8bad\u7ec3\u548c\u8bc4\u4f30\u56fe\u50cf\u7f8e\u5b66\u8d28\u91cf\u8bc4\u5206\u6a21\u578b\u3002\u5f88\u591a\u5f00\u6e90\u6a21\u578b\u90fd\u57fa\u4e8e\u8fd9\u4e2a\u6570\u636e\u96c6\u8fdb\u884c\u8bad\u7ec3\u3002<\/p>\n<h4>\u5f00\u6e90\u6a21\u578b\u793a\u4f8b\uff1a<\/h4>\n<ul>\n<li><strong>NIMA (Neural Image Assessment)<\/strong>\uff1a\u7531 Google \u63d0\u51fa\u7684 NIMA \u6a21\u578b\u662f\u4e00\u79cd\u7528\u4e8e\u56fe\u50cf\u7f8e\u5b66\u8d28\u91cf\u8bc4\u4f30\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002<\/li>\n<\/ul>\n<h3>2. NIMA \u6a21\u578b<\/h3>\n<p>NIMA \u6a21\u578b\u4f7f\u7528\u6df1\u5ea6\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08\u5982 MobileNet\uff09\u6765\u9884\u6d4b\u56fe\u50cf\u7684\u7f8e\u5b66\u8bc4\u5206\u3002\u5b83\u8f93\u51fa\u4e00\u4e2a\u4ece 1 \u5230 10 \u7684\u8bc4\u5206\uff0c\u7528\u4e8e\u8861\u91cf\u56fe\u50cf\u7684\u7f8e\u611f\u3002<\/p>\n<h4>\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/h4>\n<ol>\n<li><strong>\u83b7\u53d6 NIMA \u6a21\u578b<\/strong>\uff1a\u5728 GitHub \u4e0a\u53ef\u4ee5\u627e\u5230\u5f00\u6e90\u5b9e\u73b0\uff0c\u4f8b\u5982 <a href=\"https:\/\/github.com\/yunxiaoshi\/Neural-IMage-Assessment\">Neural-IMage-Assessment<\/a>\u3002<\/li>\n<li><strong>\u8f6c\u6362\u4e3a Core ML \u6a21\u578b<\/strong>\uff1a\u5c06 NIMA \u6a21\u578b\u8f6c\u6362\u4e3a Core ML \u6a21\u578b\uff0c\u4ee5\u4fbf\u5728 iOS \u5e94\u7528\u4e2d\u4f7f\u7528\u3002<\/li>\n<li><strong>\u96c6\u6210\u5230 iOS \u5e94\u7528\u4e2d<\/strong>\uff1a\u4f7f\u7528 Core ML \u6846\u67b6\u52a0\u8f7d\u548c\u8fd0\u884c\u6a21\u578b\uff0c\u8bc4\u4f30\u56fe\u50cf\u7684\u7f8e\u5b66\u8bc4\u5206\u3002<\/li>\n<\/ol>\n<h3>\u5177\u4f53\u6b65\u9aa4\uff1a<\/h3>\n<h4>1. \u8f6c\u6362 NIMA \u6a21\u578b\u4e3a Core ML \u6a21\u578b<\/h4>\n<p>\u4f7f\u7528 <code>coremltools<\/code> \u5c06 NIMA \u6a21\u578b\u8f6c\u6362\u4e3a Core ML \u683c\u5f0f\uff1a<\/p>\n<pre><code class=\"language-python\">import coremltools as ct\nimport tensorflow as tf\n\n# \u52a0\u8f7d TensorFlow \u6a21\u578b\nmodel = tf.keras.models.load_model(&#039;path_to_nima_model.h5&#039;)\n\n# \u8f6c\u6362\u4e3a Core ML \u6a21\u578b\ncoreml_model = ct.convert(model, inputs=[ct.ImageType()])\ncoreml_model.save(&#039;NIMA.mlmodel&#039;)<\/code><\/pre>\n<h4>2. \u5728 iOS \u5e94\u7528\u4e2d\u4f7f\u7528 Core ML \u6a21\u578b<\/h4>\n<p>\u5728 iOS \u5e94\u7528\u4e2d\u5bfc\u5165\u8f6c\u6362\u540e\u7684 Core ML \u6a21\u578b\uff0c\u5e76\u4f7f\u7528\u5b83\u8bc4\u4f30\u56fe\u50cf\u7684\u7f8e\u5b66\u8d28\u91cf\u3002<\/p>\n<h5>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h5>\n<pre><code class=\"language-swift\">import UIKit\nimport CoreML\n\nfunc loadModel() -&gt; VNCoreMLModel? {\n    do {\n        let config = MLModelConfiguration()\n        let model = try NIMA(configuration: config)\n        return try VNCoreMLModel(for: model.model)\n    } catch {\n        print(&quot;Failed to load Core ML model: \\(error)&quot;)\n        return nil\n    }\n}\n\nfunc evaluateImage(image: UIImage) -&gt; Float? {\n    guard let model = loadModel() else { return nil }\n    guard let ciImage = CIImage(image: image) else { return nil }\n\n    let handler = VNImageRequestHandler(ciImage: ciImage, options: [:])\n    let request = VNCoreMLRequest(model: model) { request, error in\n        guard let results = request.results as? [VNClassificationObservation],\n              let bestResult = results.first else {\n            print(&quot;Failed to get results: \\(error?.localizedDescription ?? &quot;Unknown error&quot;)&quot;)\n            return\n        }\n\n        print(&quot;Predicted aesthetic score: \\(bestResult.confidence * 10)&quot;)\n    }\n\n    do {\n        try handler.perform([request])\n    } catch {\n        print(&quot;Failed to perform request: \\(error)&quot;)\n        return nil\n    }\n\n    return nil \/\/ Replace with actual score extraction if needed\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b\nif let image = UIImage(named: &quot;example.jpg&quot;) {\n    evaluateImage(image: image)\n}<\/code><\/pre>\n<h3>\u5176\u4ed6\u53ef\u7528\u8d44\u6e90<\/h3>\n<p>\u9664\u4e86 NIMA \u6a21\u578b\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5f00\u6e90\u7684\u7f8e\u5b66\u8bc4\u5206\u6a21\u578b\u548c\u8d44\u6e90\uff1a<\/p>\n<ul>\n<li><strong>Microsoft's Photo Aesthetics Tool<\/strong>\uff1a\u5fae\u8f6f\u7684\u7167\u7247\u7f8e\u5b66\u5de5\u5177\u6709\u76f8\u5173\u7684\u7814\u7a76\u548c\u5f00\u6e90\u4ee3\u7801\uff0c\u53ef\u4ee5\u53c2\u8003\u3002<\/li>\n<li><strong>Flickr Aesthetic Quality Dataset (FAQD)<\/strong>\uff1aFAQD \u6570\u636e\u96c6\u7528\u4e8e\u8bad\u7ec3\u548c\u8bc4\u4f30\u7f8e\u5b66\u8bc4\u5206\u6a21\u578b\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u6a21\u578b\u548c\u5de5\u5177\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u4fee\u6539\u548c\u4f18\u5316\uff0c\u4ee5\u4fbf\u5728 iOS \u5e94\u7528\u4e2d\u66f4\u597d\u5730\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 iOS \u5e94\u7528\u4e2d\u5b9e\u73b0\u68c0\u6d4b\u76f8\u518c\u91cc\u7684\u76f8\u4f3c\u56fe\u7247\u5e76\u63a8\u8350\u8d28\u91cf\u6700\u597d\u7684\u90a3\u5f20\uff0c\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u6280\u672f\u548c\u6b65\u9aa4\uff1a 1. \u56fe\u50cf\u76f8\u4f3c\u6027\u68c0\u6d4b&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6311\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[51,86,120],"class_list":["post-6311","post","type-post","status-publish","format-standard","hentry","category-5","tag-51","tag-86","tag-120"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6311"}],"version-history":[{"count":2,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6311\/revisions"}],"predecessor-version":[{"id":6313,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6311\/revisions\/6313"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}