{"id":554297,"date":"2022-02-08T10:30:27","date_gmt":"2022-02-08T02:30:27","guid":{"rendered":"http:\/\/4563.org\/?p=554297"},"modified":"2022-02-08T10:30:27","modified_gmt":"2022-02-08T02:30:27","slug":"%e6%96%b0%e4%ba%ba%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%8b%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0%e5%88%a4%e6%96%ad-3","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=554297","title":{"rendered":"\u65b0\u4eba\u8bf7\u6559\u4e00\u4e0b\u600e\u4e48\u6dfb\u52a0\u5224\u65ad"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u65b0\u4eba\u8bf7\u6559\u4e00\u4e0b\u600e\u4e48\u6dfb\u52a0\u5224\u65ad <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : toyst <\/span>  <span><i><\/i> 29<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u539f\u4ee3\u7801\uff1a<\/p>\n<pre><code>def extract_features(img_dir, model):     try:         cache = Cache('.\/tmp')         feats = []         names = []         img_list = get_imgs(img_dir)         total = len(img_list)         cache['total'] = total         for i, img_path in enumerate(img_list):             try:                 norm_feat = model.resnet50_extract_feat(img_path)                 feats.append(norm_feat)                 names.append(img_path.encode())                 cache['current'] = i + 1                 print(f\"Extracting feature from image No. {i + 1} , {total} images in total\")             except Exception as e:                 LOGGER.error(f\"Error with extracting feature from image {e}\")                 continue         return feats, names     except Exception as e:         LOGGER.error(f\"Error with extracting feature from image {e}\")         sys.exit(1) <\/code><\/pre>\n<p>\u5927\u6982\u4f4d\u7f6e\u662f\u4e0b\u9762\u8fd9\u91cc\uff1a<\/p>\n<pre><code>def extract_features(img_dir, model):     try:         cache = Cache('.\/tmp')         feats = []         names = []         img_list = get_imgs(img_dir)         total = len(img_list)         cache['total'] = total         #check if img_dir is a image or image_path         #if it is image, create embedding and return, else, traverse the directory         for i, img_path in enumerate(img_list):             #extract feature         return feats, names     except Exception as e:         LOGGER.error(f\"Error with extracting feature from image {e}\")         sys.exit(1) <\/code><\/pre>\n<p>\u8bf7\u95ee\u4e00\u4e0b\u5e94\u8be5\u5982\u4f55\u5199\u554a\uff1f \u5224\u65ad\u4f20\u5165\u7684\u662f\u56fe\u7247\u6587\u4ef6\u540d\u8fd8\u662f\u76ee\u5f55<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"7142938\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : corningsun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> filetype ? <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7142939\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Latin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> import os<br \/>flag = os.path.exists(dir_name)<br \/>from pathlib import Path<br \/>filePath = path(&#8220;\/data\/mydir&#8221;)<br \/>flag = True if filePath.is_dir() else False <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7142940\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : advancejar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u4f60\u662f\u521a\u5b66\u5417\uff1f<br \/>str.endswith(&#8216;.jpg&#8217;)<br \/>\u8fd8\u6709\u5c31\u662f<br \/>os.path.isdir<br \/>\u8fd9\u4e2a\u51fd\u6570\u6700\u51c6\uff0c\u4f46\u662f\u6709\u5751\uff0c\u5343\u4e07\u591a\u6d4b\u8bd5 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7142941\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : deplivesb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div>  \u770b\u4e86\u4e0b\u4e3b\u7684\u53d1\u5e16\u8bb0\u5f55\u3002\u3002\u3002\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7142942\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ChrisFreeMan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @deplivesb \u9762\u5411 V2EX \u7f16\u7a0b <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7142943\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : efaun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @deplivesb #4 <br \/>@ChrisFreeMan #5 <br \/>\u54c8\u54c8\u54c8, \u8981\u4e0d\u4f60\u4eec\u5efa\u4e2a\u77e5\u8bc6\u661f\u7403\u628a\u4e3b\u62c9\u8fdb\u53bb\u5427 <img decoding=\"async\" src=\"https:\/\/i.imgur.com\/P5gN5BH.png\" rel=\"noreferrer\" alt=\"\u65b0\u4eba\u8bf7\u6559\u4e00\u4e0b\u600e\u4e48\u6dfb\u52a0\u5224\u65ad\"> <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u65b0\u4eba\u8bf7\u6559\u4e00\u4e0b\u600e\u4e48\u6dfb\u52a0\u5224\u65ad \u8cc7\u6df1\u5927\u4f6c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554297"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=554297"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554297\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=554297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=554297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=554297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}