{"id":75471,"date":"2026-02-12T12:17:42","date_gmt":"2026-02-12T04:17:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/75471.html"},"modified":"2026-02-12T12:17:42","modified_gmt":"2026-02-12T04:17:42","slug":"%e5%9f%ba%e4%ba%8e-pytorch-%e7%9a%84%e5%8d%8a%e7%9b%91%e7%9d%a3%e9%a3%9f%e5%93%81%e5%88%86%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/75471.html","title":{"rendered":"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b"},"content":{"rendered":"<h4>1. \u4ee3\u7801\u6574\u4f53\u529f\u80fd\u6982\u8ff0<\/h4>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u534a\u76d1\u7763\u5b66\u4e60\u7684\u98df\u54c1\u56fe\u50cf\u5206\u7c7b\u4efb\u52a1&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<li>\u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u5b9e\u9a8c\u7ed3\u679c\u53ef\u590d\u73b0<\/li>\n<li>\u5b9a\u4e49\u56fe\u50cf\u9884\u5904\u7406\u7b56\u7565&#xff08;\u8bad\u7ec3\u96c6\u6570\u636e\u589e\u5f3a\u3001\u9a8c\u8bc1\u96c6\u4ec5\u6807\u51c6\u5316&#xff09;<\/li>\n<li>\u81ea\u5b9a\u4e49\u6570\u636e\u96c6\u7c7b&#xff1a;\u652f\u6301\u8bfb\u53d6\u6709\u6807\u7b7e\u6570\u636e&#xff08;\u8bad\u7ec3 \/ \u9a8c\u8bc1&#xff09;\u548c\u65e0\u6807\u7b7e\u6570\u636e&#xff08;\u534a\u76d1\u7763&#xff09;<\/li>\n<li>\u5b9e\u73b0\u534a\u76d1\u7763\u903b\u8f91&#xff1a;\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e&#xff0c;\u7b5b\u9009\u7f6e\u4fe1\u5ea6\u9ad8\u7684\u6837\u672c\u52a0\u5165\u8bad\u7ec3<\/li>\n<li>\u6784\u5efa\u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff08;\u6216\u8c03\u7528\u9884\u8bad\u7ec3 VGG&#xff09;&#xff0c;\u5b8c\u6210\u6709\u76d1\u7763 &#043; \u534a\u76d1\u7763\u7684\u6df7\u5408\u8bad\u7ec3<\/li>\n<li>\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u76d1\u63a7\u635f\u5931\u548c\u51c6\u786e\u7387&#xff0c;\u4fdd\u5b58\u6700\u4f18\u6a21\u578b&#xff0c;\u7ed8\u5236\u8bad\u7ec3\u66f2\u7ebf<\/li>\n<h4>2. \u6838\u5fc3\u6a21\u5757\u9010\u884c\u62c6\u89e3<\/h4>\n<h5>&#xff08;1&#xff09;\u968f\u673a\u79cd\u5b50\u56fa\u5b9a&#xff1a;\u4fdd\u8bc1\u5b9e\u9a8c\u53ef\u590d\u73b0<\/h5>\n<p>def seed_everything(seed):<br \/>\n    torch.manual_seed(seed)          # CPU\u968f\u673a\u79cd\u5b50<br \/>\n    torch.cuda.manual_seed(seed)     # \u5355\u4e2aGPU\u968f\u673a\u79cd\u5b50<br \/>\n    torch.cuda.manual_seed_all(seed) # \u591aGPU\u968f\u673a\u79cd\u5b50<br \/>\n    torch.backends.cudnn.benchmark &#061; False  # \u5173\u95ed\u81ea\u52a8\u4f18\u5316&#xff0c;\u907f\u514d\u968f\u673a\u6027<br \/>\n    torch.backends.cudnn.deterministic &#061; True  # \u5f3a\u5236\u786e\u5b9a\u6027\u7b97\u6cd5<br \/>\n    random.seed(seed)                # Python\u539f\u751f\u968f\u673a\u79cd\u5b50<br \/>\n    np.random.seed(seed)             # Numpy\u968f\u673a\u79cd\u5b50<br \/>\n    os.environ[&#039;PYTHONHASHSEED&#039;] &#061; str(seed)  # \u54c8\u5e0c\u79cd\u5b50<\/p>\n<p>seed_everything(0)  # \u56fa\u5b9a\u79cd\u5b50\u4e3a0&#xff0c;\u6bcf\u6b21\u8fd0\u884c\u7ed3\u679c\u4e00\u81f4<\/p>\n<p>\u5173\u952e\u77e5\u8bc6\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u6df1\u5ea6\u5b66\u4e60\u4e2d GPU \u8fd0\u7b97\u3001\u6570\u636e\u6d17\u724c\u7b49\u64cd\u4f5c\u81ea\u5e26\u968f\u673a\u6027&#xff0c;\u56fa\u5b9a\u79cd\u5b50\u662f\u5b9e\u9a8c\u53ef\u590d\u73b0\u7684\u6838\u5fc3<\/li>\n<li>cudnn.deterministic &#061; True \u4f1a\u727a\u7272\u4e00\u70b9\u901f\u5ea6&#xff0c;\u4f46\u4fdd\u8bc1\u6bcf\u6b21\u8ba1\u7b97\u7ed3\u679c\u5b8c\u5168\u4e00\u81f4<\/li>\n<\/ul>\n<p>&#xff08;2&#xff09;\u56fe\u50cf\u9884\u5904\u7406&#xff1a;\u6570\u636e\u589e\u5f3a&#xff08;\u8bad\u7ec3&#xff09;vs \u7eaf\u8f6c\u6362&#xff08;\u9a8c\u8bc1&#xff09;<\/p>\n<p>HW &#061; 224  # \u56fe\u50cf\u7edf\u4e00\u7f29\u653e\u5230224&#215;224&#xff08;\u9002\u914dVGG\u7b49\u9884\u8bad\u7ec3\u6a21\u578b&#xff09;<\/p>\n<p># \u8bad\u7ec3\u96c6&#xff1a;\u6570\u636e\u589e\u5f3a&#xff08;\u63d0\u5347\u6cdb\u5316\u80fd\u529b&#xff09;<br \/>\ntrain_transform &#061; transforms.Compose([<br \/>\n    transforms.ToPILImage(),   # \u628anumpy\u6570\u7ec4\u8f6c\u6210PIL\u56fe\u50cf&#xff08;\u56e0\u4e3a\u540e\u7eed\u64cd\u4f5c\u9700\u8981PIL\u683c\u5f0f&#xff09;<br \/>\n    transforms.RandomResizedCrop(224),  # \u968f\u673a\u88c1\u526a&#043;\u7f29\u653e&#xff08;\u6a21\u62df\u4e0d\u540c\u89c6\u89d2&#xff09;<br \/>\n    transforms.RandomRotation(50),      # \u968f\u673a\u65cb\u8f6c\u00b150\u5ea6<br \/>\n    transforms.ToTensor()               # \u8f6cTensor&#xff1a;(H,W,C)\u2192(C,H,W)&#xff0c;\u503c\u5f52\u4e00\u5316\u5230[0,1]<br \/>\n])<\/p>\n<p># \u9a8c\u8bc1\u96c6&#xff1a;\u65e0\u589e\u5f3a&#xff08;\u907f\u514d\u5f15\u5165\u566a\u58f0&#xff0c;\u4fdd\u8bc1\u8bc4\u4f30\u51c6\u786e&#xff09;<br \/>\nval_transform &#061; transforms.Compose([<br \/>\n    transforms.ToPILImage(),<br \/>\n    transforms.ToTensor()<br \/>\n])<\/p>\n<p>\u6838\u5fc3\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u8bad\u7ec3\u96c6\u589e\u5f3a&#xff1a;\u901a\u8fc7\u968f\u673a\u88c1\u526a\u3001\u65cb\u8f6c\u589e\u52a0\u6570\u636e\u591a\u6837\u6027&#xff0c;\u9632\u6b62\u8fc7\u62df\u5408<\/li>\n<li>\u9a8c\u8bc1\u96c6\u4e0d\u589e\u5f3a&#xff1a;\u7528 \u201c\u5e72\u51c0\u201d \u7684\u6570\u636e\u8bc4\u4f30\u6a21\u578b\u771f\u5b9e\u6027\u80fd<\/li>\n<li>ToTensor() \u662f\u5173\u952e&#xff1a;PyTorch \u6a21\u578b\u8981\u6c42\u8f93\u5165\u662f (\u901a\u9053\u6570, \u9ad8\u5ea6, \u5bbd\u5ea6) \u7684 Tensor&#xff0c;\u800c PIL\/OpenCV \u8bfb\u53d6\u7684\u662f (H,W,C) \u7684\u6570\u7ec4&#xff0c;H\u662f\u9ad8\u5ea6\u3001W\u662f\u5bbd\u5ea6\u3001C\u662f\u901a\u9053\u6570<\/li>\n<\/ul>\n<h5>&#xff08;3&#xff09;\u81ea\u5b9a\u4e49\u6570\u636e\u96c6\u7c7b food_Dataset&#xff1a;\u5904\u7406\u6709\u6807\u7b7e \/ \u65e0\u6807\u7b7e\u6570\u636e<\/h5>\n<p>\u8fd9\u662f\u4ee3\u7801\u7684\u6838\u5fc3\u4e4b\u4e00&#xff0c;\u652f\u6301 3 \u79cd\u6a21\u5f0f&#xff08;train\/val\/semi&#xff09;&#xff0c;\u9002\u914d\u4e0d\u540c\u6570\u636e\u7c7b\u578b&#xff1a;<\/p>\n<p>class food_Dataset(Dataset):<br \/>\n    def __init__(self, path, mode&#061;&#034;train&#034;):<br \/>\n        self.mode &#061; mode<br \/>\n        # \u534a\u76d1\u7763\u6a21\u5f0f&#xff1a;\u53ea\u8bfb\u53d6\u65e0\u6807\u7b7e\u6570\u636e&#xff08;\u65e0Y&#xff09;<br \/>\n        if mode &#061;&#061; &#034;semi&#034;:<br \/>\n            self.X &#061; self.read_file(path)<br \/>\n        # \u8bad\u7ec3\/\u9a8c\u8bc1\u6a21\u5f0f&#xff1a;\u8bfb\u53d6\u6709\u6807\u7b7e\u6570\u636e&#xff08;X&#043;Y&#xff09;<br \/>\n        else:<br \/>\n            self.X, self.Y &#061; self.read_file(path)<br \/>\n            self.Y &#061; torch.LongTensor(self.Y)  # \u6807\u7b7e\u8f6cLongTensor&#xff08;\u5206\u7c7b\u4efb\u52a1\u8981\u6c42&#xff09;<\/p>\n<p>        # \u7ed1\u5b9a\u9884\u5904\u7406\u7b56\u7565<br \/>\n        if mode &#061;&#061; &#034;train&#034;:<br \/>\n            self.transform &#061; train_transform<br \/>\n        else:<br \/>\n            self.transform &#061; val_transform<\/p>\n<p>    # \u6838\u5fc3&#xff1a;\u8bfb\u53d6\u6587\u4ef6\u7684\u51fd\u6570&#xff08;\u533a\u5206\u6709\u6807\u7b7e\/\u65e0\u6807\u7b7e&#xff09;<br \/>\n    def read_file(self, path):<br \/>\n        # \u534a\u76d1\u7763\u6a21\u5f0f&#xff1a;\u8bfb\u53d6\u65e0\u6807\u7b7e\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u56fe\u7247<br \/>\n        if self.mode &#061;&#061; &#034;semi&#034;:<br \/>\n            file_list &#061; os.listdir(path)  # \u5217\u51fa\u6587\u4ef6\u5939\u4e0b\u6240\u6709\u56fe\u7247\u540d<br \/>\n            # \u521d\u59cb\u5316\u6570\u7ec4&#xff1a;(\u6837\u672c\u6570, 224, 224, 3)&#xff0c;uint8\u8282\u7701\u5185\u5b58<br \/>\n            xi &#061; np.zeros((len(file_list), HW, HW, 3), dtype&#061;np.uint8)<br \/>\n            for j, img_name in enumerate(file_list):<br \/>\n                img_path &#061; os.path.join(path, img_name)<br \/>\n                img &#061; Image.open(img_path).resize((HW, HW))  # \u7f29\u653e\u81f3224&#215;224<br \/>\n                xi[j, &#8230;] &#061; img  # \u5b58\u5165\u6570\u7ec4<br \/>\n            print(&#034;\u8bfb\u5230\u4e86%d\u4e2a\u6570\u636e&#034; % len(xi))<br \/>\n            return xi<br \/>\n        # \u6709\u6807\u7b7e\u6a21\u5f0f&#xff1a;\u6309\u7c7b\u522b\u6587\u4ef6\u5939\u8bfb\u53d6&#xff08;00\/01\/&#8230;\/10\u517111\u7c7b&#xff09;<br \/>\n        else:<br \/>\n            for i in tqdm(range(11)):  # tqdm\u663e\u793a\u8fdb\u5ea6\u6761<br \/>\n                file_dir &#061; path &#043; &#034;\/%02d&#034; % i  # \u62fc\u63a5\u7c7b\u522b\u6587\u4ef6\u5939\u8def\u5f84&#xff08;00~10&#xff09;<br \/>\n                file_list &#061; os.listdir(file_dir)<br \/>\n                # \u521d\u59cb\u5316\u5f53\u524d\u7c7b\u522b\u7684\u6570\u636e\/\u6807\u7b7e<br \/>\n                xi &#061; np.zeros((len(file_list), HW, HW, 3), dtype&#061;np.uint8)<br \/>\n                yi &#061; np.zeros(len(file_list), dtype&#061;np.uint8)<\/p>\n<p>                for j, img_name in enumerate(file_list):<br \/>\n                    img_path &#061; os.path.join(file_dir, img_name)<br \/>\n                    img &#061; Image.open(img_path).resize((HW, HW))<br \/>\n                    xi[j, &#8230;] &#061; img<br \/>\n                    yi[j] &#061; i  # \u6807\u7b7e&#061;\u6587\u4ef6\u5939\u5bf9\u5e94\u7684\u7c7b\u522b&#xff08;0~10&#xff09;<\/p>\n<p>                # \u62fc\u63a5\u6240\u6709\u7c7b\u522b\u7684\u6570\u636e<br \/>\n                if i &#061;&#061; 0:<br \/>\n                    X &#061; xi<br \/>\n                    Y &#061; yi<br \/>\n                else:<br \/>\n                    X &#061; np.concatenate((X, xi), axis&#061;0)<br \/>\n                    Y &#061; np.concatenate((Y, yi), axis&#061;0)<br \/>\n            print(&#034;\u8bfb\u5230\u4e86%d\u4e2a\u6570\u636e&#034; % len(Y))<br \/>\n            return X, Y<\/p>\n<p>    # \u83b7\u53d6\u5355\u4e2a\u6837\u672c&#xff08;Dataset\u5fc5\u987b\u5b9e\u73b0&#xff09;<br \/>\n    def __getitem__(self, item):<br \/>\n        if self.mode &#061;&#061; &#034;semi&#034;:<br \/>\n            # \u534a\u76d1\u7763&#xff1a;\u8fd4\u56de\u9884\u5904\u7406\u540e\u7684\u56fe\u7247 &#043; \u539f\u59cb\u56fe\u7247&#xff08;\u540e\u7eed\u6253\u4f2a\u6807\u7b7e\u7528&#xff09;<br \/>\n            return self.transform(self.X[item]), self.X[item]<br \/>\n        else:<br \/>\n            # \u6709\u6807\u7b7e&#xff1a;\u8fd4\u56de\u9884\u5904\u7406\u540e\u7684\u56fe\u7247 &#043; \u6807\u7b7e<br \/>\n            return self.transform(self.X[item]), self.Y[item]<\/p>\n<p>    # \u8fd4\u56de\u6570\u636e\u96c6\u957f\u5ea6&#xff08;Dataset\u5fc5\u987b\u5b9e\u73b0&#xff09;<br \/>\n    def __len__(self):<br \/>\n        return len(self.X)<\/p>\n<p>\u5bf9\u4e8e\u56fe\u50cf\u6570\u636e\u96c6\u7684\u8bfb\u53d6\u51fd\u6570\u00a0\u6709\u4e24\u79cd\u6a21\u5f0f<\/p>\n<p>1.\u5728\u534a\u76d1\u7763\u6a21\u5f0f\u4e0b&#xff1a;<\/p>\n<p>if self.mode &#061;&#061; &#034;semi&#034;:<br \/>\n    # \u5217\u51fa\u6587\u4ef6\u5939\u4e0b\u6240\u6709\u6587\u4ef6<br \/>\n    file_list &#061; os.listdir(path)<\/p>\n<p>    # \u521d\u59cb\u5316\u6570\u7ec4: [\u6587\u4ef6\u6570, \u56fe\u7247\u9ad8\u5ea6, \u56fe\u7247\u5bbd\u5ea6, 3\u901a\u9053]<br \/>\n    xi &#061; np.zeros((len(file_list), HW, HW, 3), dtype&#061;np.uint8)<\/p>\n<p>    # \u904d\u5386\u6bcf\u4e2a\u56fe\u7247\u6587\u4ef6<br \/>\n    for j, img_name in enumerate(file_list):<br \/>\n        # \u5b8c\u6574\u7684\u56fe\u7247\u8def\u5f84<br \/>\n        img_path &#061; os.path.join(path, img_name)<\/p>\n<p>        # \u6253\u5f00\u56fe\u7247<br \/>\n        img &#061; Image.open(img_path)<\/p>\n<p>        # \u8c03\u6574\u5927\u5c0f\u5230\u7edf\u4e00\u5c3a\u5bf8 (HW \u00d7 HW)<br \/>\n        img &#061; img.resize((HW, HW))<\/p>\n<p>        # \u5b58\u50a8\u56fe\u7247\u6570\u636e<br \/>\n        xi[j, &#8230;] &#061; img  # &#8230; \u8868\u793a\u6240\u6709\u7ef4\u5ea6<\/p>\n<p>    print(&#034;\u8bfb\u5230\u4e86%d\u4e2a\u6570\u636e&#034; % len(xi))<br \/>\n    return xi  # \u53ea\u8fd4\u56de\u56fe\u50cf\u6570\u636e&#xff0c;\u4e0d\u8fd4\u56de\u6807\u7b7e<\/p>\n<p>\u534a\u76d1\u7763\u6a21\u5f0f\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6240\u6709\u56fe\u7247\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u5939<\/p>\n<\/li>\n<li>\n<p>\u6ca1\u6709\u6807\u7b7e&#xff08;\u53ea\u8fd4\u56deX&#xff0c;\u4e0d\u8fd4\u56deY&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7528\u4e8e\u8bad\u7ec3\u65f6\u4e0d\u9700\u8981\u6807\u7b7e\u7684\u60c5\u51b5<\/p>\n<\/li>\n<\/ul>\n<p>2. \u5b8c\u6574\u76d1\u7763\u6a21\u5f0f:<\/p>\n<p>else:<br \/>\n    # \u4f7f\u7528tqdm\u663e\u793a\u8fdb\u5ea6\u6761<br \/>\n    for i in tqdm(range(11)):  # \u904d\u53860-10\u517111\u4e2a\u7c7b\u522b<br \/>\n        # \u7c7b\u522b\u6587\u4ef6\u5939\u8def\u5f84: path\/00, path\/01, &#8230;<br \/>\n        file_dir &#061; path &#043; &#034;\/%02d&#034; % i  # %02d \u8868\u793a\u4e24\u4f4d\u6570\u5b57&#xff0c;\u598200,01<\/p>\n<p>        # \u5217\u51fa\u8be5\u7c7b\u522b\u4e0b\u6240\u6709\u56fe\u7247<br \/>\n        file_list &#061; os.listdir(file_dir)<\/p>\n<p>        # \u521d\u59cb\u5316\u5f53\u524d\u7c7b\u522b\u7684\u6570\u636e<br \/>\n        xi &#061; np.zeros((len(file_list), HW, HW, 3), dtype&#061;np.uint8)  # \u56fe\u50cf<br \/>\n        yi &#061; np.zeros(len(file_list), dtype&#061;np.uint8)               # \u6807\u7b7e<\/p>\n<p>        # \u904d\u5386\u8be5\u7c7b\u522b\u7684\u6240\u6709\u56fe\u7247<br \/>\n        for j, img_name in enumerate(file_list):<br \/>\n            img_path &#061; os.path.join(file_dir, img_name)<br \/>\n            img &#061; Image.open(img_path)<br \/>\n            img &#061; img.resize((HW, HW))<br \/>\n            xi[j, &#8230;] &#061; img<br \/>\n            yi[j] &#061; i  # \u6587\u4ef6\u5939\u540d\u5c31\u662f\u6807\u7b7e&#xff08;0,1,2&#8230;&#xff09;<\/p>\n<p>        # \u62fc\u63a5\u6240\u6709\u7c7b\u522b\u7684\u6570\u636e<br \/>\n        if i &#061;&#061; 0:<br \/>\n            X &#061; xi  # \u7b2c\u4e00\u4e2a\u7c7b\u522b<br \/>\n            Y &#061; yi<br \/>\n        else:<br \/>\n            X &#061; np.concatenate((X, xi), axis&#061;0)  # \u6cbf\u7b2c0\u7ef4&#xff08;\u6837\u672c\u7ef4\u5ea6&#xff09;\u62fc\u63a5<br \/>\n            Y &#061; np.concatenate((Y, yi), axis&#061;0)<\/p>\n<p>    print(&#034;\u8bfb\u5230\u4e86%d\u4e2a\u6570\u636e&#034; % len(Y))<br \/>\n    return X, Y  # \u8fd4\u56de\u56fe\u50cf\u548c\u6807\u7b7e<\/p>\n<h5>&#xff08;4&#xff09;\u534a\u76d1\u7763\u6838\u5fc3&#xff1a;semiDataset \u7c7b&#xff08;\u7ed9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e&#xff09;<\/h5>\n<p>\u8fd9\u662f\u534a\u76d1\u7763\u5b66\u4e60\u7684\u5173\u952e&#xff0c;\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u9884\u6d4b&#xff0c;\u7b5b\u9009\u7f6e\u4fe1\u5ea6\u9ad8\u7684\u6837\u672c&#xff1a;<\/p>\n<p>class semiDataset(Dataset):<br \/>\n    def __init__(self, no_label_loder, model, device, thres&#061;0.99):<br \/>\n        # \u6838\u5fc3&#xff1a;\u7528\u6a21\u578b\u7ed9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e<br \/>\n        x, y &#061; self.get_label(no_label_loder, model, device, thres)<br \/>\n        # \u65e0\u9ad8\u7f6e\u4fe1\u5ea6\u6837\u672c&#xff1a;\u6807\u8bb0\u4e3a\u65e0\u6548<br \/>\n        if x &#061;&#061; []:<br \/>\n            self.flag &#061; False<br \/>\n        # \u6709\u9ad8\u7f6e\u4fe1\u5ea6\u6837\u672c&#xff1a;\u6784\u5efa\u6570\u636e\u96c6<br \/>\n        else:<br \/>\n            self.flag &#061; True<br \/>\n            self.X &#061; np.array(x)<br \/>\n            self.Y &#061; torch.LongTensor(y)<br \/>\n            self.transform &#061; train_transform  # \u7528\u8bad\u7ec3\u96c6\u589e\u5f3a\u7b56\u7565<\/p>\n<p>    def get_label(self, no_label_loder, model, device, thres):<br \/>\n        model &#061; model.to(device)<br \/>\n        pred_prob &#061; []  # \u5b58\u50a8\u9884\u6d4b\u7f6e\u4fe1\u5ea6<br \/>\n        labels &#061; []     # \u5b58\u50a8\u9884\u6d4b\u6807\u7b7e<br \/>\n        x &#061; []          # \u5b58\u50a8\u9ad8\u7f6e\u4fe1\u5ea6\u7684\u539f\u59cb\u56fe\u7247<br \/>\n        y &#061; []          # \u5b58\u50a8\u9ad8\u7f6e\u4fe1\u5ea6\u7684\u4f2a\u6807\u7b7e<br \/>\n        soft &#061; nn.Softmax()  # \u628a\u6a21\u578b\u8f93\u51fa\u8f6c\u6210\u6982\u7387<\/p>\n<p>        with torch.no_grad():  # \u7981\u7528\u68af\u5ea6&#xff0c;\u63d0\u901f&#043;\u7701\u5185\u5b58<br \/>\n            for bat_x, _ in no_label_loder:  # \u904d\u5386\u65e0\u6807\u7b7e\u6570\u636e<br \/>\n                bat_x &#061; bat_x.to(device)<br \/>\n                pred &#061; model(bat_x)         # \u6a21\u578b\u9884\u6d4b&#xff08;logits&#xff09;<br \/>\n                pred_soft &#061; soft(pred)      # \u8f6c\u6982\u7387&#xff08;0~1&#xff09;<br \/>\n                # \u53d6\u6bcf\u4e2a\u6837\u672c\u7684\u6700\u5927\u6982\u7387\u548c\u5bf9\u5e94\u6807\u7b7e<br \/>\n                pred_max, pred_value &#061; pred_soft.max(1)<br \/>\n                pred_prob.extend(pred_max.cpu().numpy().tolist())<br \/>\n                labels.extend(pred_value.cpu().numpy().tolist())<\/p>\n<p>        # \u7b5b\u9009\u7f6e\u4fe1\u5ea6&gt;\u9608\u503c\u7684\u6837\u672c<br \/>\n        for index, prob in enumerate(pred_prob):<br \/>\n            if prob &gt; thres:  # \u7f6e\u4fe1\u5ea6&gt;0.99\u624d\u4fdd\u7559<br \/>\n                x.append(no_label_loder.dataset[index][1])  # \u539f\u59cb\u56fe\u7247<br \/>\n                y.append(labels[index])                     # \u4f2a\u6807\u7b7e<br \/>\n        return x, y<\/p>\n<p>    def __getitem__(self, item):<br \/>\n        return self.transform(self.X[item]), self.Y[item]<\/p>\n<p>    def __len__(self):<br \/>\n        return len(self.X)<\/p>\n<p># \u8f85\u52a9\u51fd\u6570&#xff1a;\u521b\u5efa\u534a\u76d1\u7763\u6570\u636e\u52a0\u8f7d\u5668<br \/>\ndef get_semi_loader(no_label_loder, model, device, thres):<br \/>\n    semiset &#061; semiDataset(no_label_loder, model, device, thres)<br \/>\n    if semiset.flag &#061;&#061; False:<br \/>\n        return None<br \/>\n    else:<br \/>\n        semi_loader &#061; DataLoader(semiset, batch_size&#061;16, shuffle&#061;False)<br \/>\n        return semi_loader<\/p>\n<p>\u00a0 \u00a0 \u5bf9\u4e8e\u4ee3\u7801\u4e2d\u7684\u6838\u5fc3\u51fd\u6570get_label\u8fd9\u91cc\u7ed9\u51fa\u8be6\u7ec6\u6ce8\u91ca&#xff1a;<\/p>\n<p>def get_label(self, no_label_loder, model, device, thres):<br \/>\n    # \u51c6\u5907\u5de5\u4f5c<br \/>\n    model &#061; model.to(device)  # \u628a\u6a21\u578b\u642c\u5230GPU&#xff08;\u5982\u679c\u6709&#xff09;<br \/>\n    pred_prob &#061; []  # \u5b58\u50a8\u6240\u6709\u56fe\u7247\u7684\u9884\u6d4b\u7f6e\u4fe1\u5ea6<br \/>\n    labels &#061; []     # \u5b58\u50a8\u6240\u6709\u56fe\u7247\u7684\u9884\u6d4b\u6807\u7b7e<br \/>\n    x &#061; []          # \u5b58\u50a8\u9ad8\u7f6e\u4fe1\u5ea6\u56fe\u7247&#xff08;\u8981\u8fd4\u56de\u7684&#xff09;<br \/>\n    y &#061; []          # \u5b58\u50a8\u9ad8\u7f6e\u4fe1\u5ea6\u4f2a\u6807\u7b7e&#xff08;\u8981\u8fd4\u56de\u7684&#xff09;<br \/>\n    soft &#061; nn.Softmax()  # Softmax\u5c42&#xff1a;\u628a\u6a21\u578b\u8f93\u51fa\u8f6c\u6210\u6982\u7387&#xff08;0~1\u4e4b\u95f4&#xff09;<\/p>\n<p>    with torch.no_grad():  # &#x1f6a9;\u975e\u5e38\u91cd\u8981&#xff01;\u7981\u7528\u68af\u5ea6\u8ba1\u7b97&#xff0c;\u52a0\u901f\u63a8\u7406&#xff0c;\u8282\u7701\u663e\u5b58<br \/>\n        for bat_x, _ in no_label_loder:  # \u904d\u5386\u65e0\u6807\u7b7e\u6570\u636e&#xff0c;_\u5360\u4f4d\u7b26\u8868\u793a\u201c\u5ffd\u7565\u6807\u7b7e\u201d<br \/>\n            bat_x &#061; bat_x.to(device)      # \u628a\u56fe\u7247\u642c\u5230GPU<br \/>\n            pred &#061; model(bat_x)           # \u6a21\u578b\u524d\u5411\u4f20\u64ad&#xff0c;\u8f93\u51falogits&#xff08;\u672a\u5f52\u4e00\u5316\u7684\u5206\u6570&#xff09;<br \/>\n            pred_soft &#061; soft(pred)        # Softmax\u5f52\u4e00\u5316&#xff0c;\u53d8\u6210\u6982\u7387<\/p>\n<p>            # max(1)\u7684\u542b\u4e49&#xff1a;<br \/>\n            # &#8211; \u53c2\u65701\u8868\u793a\u5728\u7ef4\u5ea61&#xff08;\u7c7b\u522b\u7ef4\u5ea6&#xff09;\u4e0a\u53d6\u6700\u5927\u503c<br \/>\n            # &#8211; \u8fd4\u56de\u503c1: \u6700\u5927\u6982\u7387\u503c&#xff08;\u59820.99&#xff09;<br \/>\n            # &#8211; \u8fd4\u56de\u503c2: \u6700\u5927\u6982\u7387\u5bf9\u5e94\u7684\u7d22\u5f15&#xff08;\u59823&#xff0c;\u4ee3\u8868\u7b2c3\u7c7b&#xff09;<br \/>\n            pred_max, pred_value &#061; pred_soft.max(1)<\/p>\n<p>            # \u6536\u96c6\u8fd9\u4e00\u6279\u6b21\u7684\u7ed3\u679c<br \/>\n            # .cpu()&#xff1a;\u4eceGPU\u642c\u5230CPU<br \/>\n            # .numpy()&#xff1a;\u8f6c\u6210numpy\u6570\u7ec4<br \/>\n            # .tolist()&#xff1a;\u8f6c\u6210Python\u5217\u8868<br \/>\n            pred_prob.extend(pred_max.cpu().numpy().tolist())<br \/>\n            labels.extend(pred_value.cpu().numpy().tolist())<\/p>\n<p>    # &#x1f6a9;\u7b5b\u9009\u7f6e\u4fe1\u5ea6&gt;\u9608\u503c\u7684\u6837\u672c<br \/>\n    for index, prob in enumerate(pred_prob):<br \/>\n        if prob &gt; thres:  # \u53ea\u6709\u9ad8\u7f6e\u4fe1\u5ea6\u7684\u624d\u4fdd\u7559<br \/>\n            # \u6ce8\u610f\u8fd9\u91cc&#xff1a;no_label_loder.dataset[index][1]<br \/>\n            # &#8211; no_label_loder.dataset: \u539f\u59cb\u6570\u636e\u96c6<br \/>\n            # &#8211; [index]: \u7b2cindex\u4e2a\u6837\u672c<br \/>\n            # &#8211; [1]: \u53d6\u8fd9\u4e2a\u6837\u672c\u7684\u7b2c2\u4e2a\u5143\u7d20&#xff08;\u901a\u5e38\u662f\u56fe\u7247&#xff09;<br \/>\n            x.append(no_label_loder.dataset[index][1])  # \u539f\u59cb\u56fe\u7247<br \/>\n            y.append(labels[index])                     # \u5bf9\u5e94\u7684\u4f2a\u6807\u7b7e<\/p>\n<p>    return x, y<\/p>\n<p>\u6838\u5fc3\u903b\u8f91&#xff08;\u534a\u76d1\u7763\u5173\u952e&#xff09;&#xff1a;<\/p>\n<li>\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u9884\u6d4b&#xff0c;\u901a\u8fc7Softmax\u8f6c\u6982\u7387<\/li>\n<li>\u7b5b\u9009\u7f6e\u4fe1\u5ea6 &gt; 0.99 \u7684\u6837\u672c&#xff08;\u8ba4\u4e3a\u6a21\u578b\u5bf9\u8fd9\u4e9b\u6837\u672c\u7684\u9884\u6d4b\u8db3\u591f\u53ef\u9760&#xff09;<\/li>\n<li>\u628a\u8fd9\u4e9b\u9ad8\u7f6e\u4fe1\u5ea6\u6837\u672c\u7684 \u201c\u4f2a\u6807\u7b7e\u201d \u5f53\u4f5c\u771f\u5b9e\u6807\u7b7e&#xff0c;\u52a0\u5165\u8bad\u7ec3\u96c6<\/li>\n<li>\u9608\u503cthres&#061;0.99 \u662f\u8d85\u53c2\u6570&#xff1a;\u503c\u8d8a\u9ad8&#xff0c;\u4f2a\u6807\u7b7e\u8d8a\u53ef\u9760&#xff0c;\u4f46\u6837\u672c\u8d8a\u5c11&#xff1b;\u503c\u8d8a\u4f4e&#xff0c;\u6837\u672c\u8d8a\u591a&#xff0c;\u4f46\u566a\u58f0\u8d8a\u5927<\/li>\n<h5>&#xff08;5&#xff09;\u81ea\u5b9a\u4e49 CNN \u6a21\u578b myModel<\/h5>\n<p>\u4ee3\u7801\u4e2d\u5b9e\u9645\u7528\u4e86\u9884\u8bad\u7ec3 VGG&#xff0c;\u4f46\u4fdd\u7559\u4e86\u81ea\u5b9a\u4e49 CNN \u4f5c\u4e3a\u5907\u9009&#xff0c;\u7ed3\u6784\u5982\u4e0b&#xff1a;<\/p>\n<p>class myModel(nn.Module):<br \/>\n    def __init__(self, num_class):<br \/>\n        super(myModel, self).__init__()<br \/>\n        # \u5377\u79ef\u5c42&#xff1a;\u63d0\u53d6\u56fe\u50cf\u7279\u5f81&#xff08;\u7c7b\u4f3cVGG\u7684\u7b80\u5316\u7248&#xff09;<br \/>\n        self.conv1 &#061; nn.Conv2d(3, 64, 3, 1, 1)  # 3\u219264\u901a\u9053&#xff0c;3&#215;3\u5377\u79ef&#xff0c;padding&#061;1&#xff08;\u4fdd\u6301\u5c3a\u5bf8&#xff09;<br \/>\n        self.bn1 &#061; nn.BatchNorm2d(64)           # \u6279\u91cf\u5f52\u4e00\u5316&#xff1a;\u52a0\u901f\u8bad\u7ec3&#xff0c;\u9632\u6b62\u68af\u5ea6\u6d88\u5931<br \/>\n        self.relu &#061; nn.ReLU()<br \/>\n        self.pool1 &#061; nn.MaxPool2d(2)            # \u6c60\u5316&#xff1a;\u7f29\u5c0f\u5c3a\u5bf8&#xff0c;\u4fdd\u7559\u5173\u952e\u7279\u5f81<\/p>\n<p>        # \u5806\u53e0\u5377\u79ef\u5c42&#xff08;\u6bcf\u5c42\u901a\u9053\u6570\u7ffb\u500d&#xff0c;\u5c3a\u5bf8\u51cf\u534a&#xff09;<br \/>\n        self.layer1 &#061; nn.Sequential(nn.Conv2d(64, 128, 3, 1, 1), nn.BatchNorm2d(128), nn.ReLU(), nn.MaxPool2d(2))<br \/>\n        self.layer2 &#061; nn.Sequential(nn.Conv2d(128, 256, 3, 1, 1), nn.BatchNorm2d(256), nn.ReLU(), nn.MaxPool2d(2))<br \/>\n        self.layer3 &#061; nn.Sequential(nn.Conv2d(256, 512, 3, 1, 1), nn.BatchNorm2d(512), nn.ReLU(), nn.MaxPool2d(2))<\/p>\n<p>        self.pool2 &#061; nn.MaxPool2d(2)            # \u6700\u7ec8\u7279\u5f81\u56fe&#xff1a;512x7x7<br \/>\n        # \u5168\u8fde\u63a5\u5c42&#xff1a;\u5206\u7c7b<br \/>\n        self.fc1 &#061; nn.Linear(25088, 1000)       # 512*7*7&#061;25088 \u2192 1000\u7ef4\u9690\u85cf\u5c42<br \/>\n        self.relu2 &#061; nn.ReLU()<br \/>\n        self.fc2 &#061; nn.Linear(1000, num_class)   # 1000\u219211\u7c7b&#xff08;\u6700\u7ec8\u8f93\u51fa&#xff09;<\/p>\n<p>    def forward(self, x):<br \/>\n        # \u5377\u79ef\u5c42\u63d0\u53d6\u7279\u5f81<br \/>\n        x &#061; self.conv1(x)<br \/>\n        x &#061; self.bn1(x)<br \/>\n        x &#061; self.relu(x)<br \/>\n        x &#061; self.pool1(x)<br \/>\n        x &#061; self.layer1(x)<br \/>\n        x &#061; self.layer2(x)<br \/>\n        x &#061; self.layer3(x)<br \/>\n        x &#061; self.pool2(x)<br \/>\n        # \u5c55\u5e73&#xff1a;(batch, 512,7,7) \u2192 (batch, 25088)<br \/>\n        x &#061; x.view(x.size()[0], -1)<br \/>\n        # \u5168\u8fde\u63a5\u5c42\u5206\u7c7b<br \/>\n        x &#061; self.fc1(x)<br \/>\n        x &#061; self.relu2(x)<br \/>\n        x &#061; self.fc2(x)<br \/>\n        return x<\/p>\n<h3>Conv2d\u53c2\u6570\u542b\u4e49\u901f\u67e5\u8868&#xff1a;<\/h3>\n<table>\n<tr>\u53c2\u6570\u4f4d\u7f6e\u4ee3\u7801\u4e2d\u7684\u503c\u53c2\u6570\u540d\u542b\u4e49\u7c7b\u6bd4\u7406\u89e3<\/tr>\n<tbody>\n<tr>\n<td>\u7b2c1\u4e2a<\/td>\n<td>3<\/td>\n<td>in_channels<\/td>\n<td>\u8f93\u5165\u901a\u9053\u6570<\/td>\n<td>\u5f69\u8272\u56fe\u7247\u6709RGB 3\u4e2a\u901a\u9053<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c2\u4e2a<\/td>\n<td>64<\/td>\n<td>out_channels<\/td>\n<td>\u8f93\u51fa\u901a\u9053\u6570<\/td>\n<td>\u752864\u4e2a\u4e0d\u540c\u7684\u5377\u79ef\u6838\u63d0\u53d6\u7279\u5f81<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c3\u4e2a<\/td>\n<td>3<\/td>\n<td>kernel_size<\/td>\n<td>\u5377\u79ef\u6838\u5927\u5c0f<\/td>\n<td>3&#215;3\u7684\u8fc7\u6ee4\u5668<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c4\u4e2a<\/td>\n<td>1<\/td>\n<td>stride<\/td>\n<td>\u6b65\u957f<\/td>\n<td>\u6bcf\u6b21\u79fb\u52a81\u4e2a\u50cf\u7d20<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c5\u4e2a<\/td>\n<td>1<\/td>\n<td>padding<\/td>\n<td>\u586b\u5145<\/td>\n<td>\u5468\u56f4\u88651\u57080<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8ba1\u7b97\u516c\u5f0f&#xff1a;\u8f93\u51fa\u9ad8\u5ea6 H_out &#061; (H_in &#043; 2*padding &#8211; kernel_size) \/\/ stride &#043; 1<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8f93\u51fa\u5bbd\u5ea6 W_out &#061; (W_in &#043; 2*padding &#8211; kernel_size) \/\/ stride &#043; 1<\/p>\n<p>\u8f93\u5165: 224&#215;224<br \/>\nconv &#061; nn.Conv2d(3, 64, 3, 1, 1)<\/p>\n<p>H_out &#061; (224 &#043; 2*1 &#8211; 3) \/\/ 1 &#043; 1<br \/>\n      &#061; (224 &#043; 2 &#8211; 3) \/\/ 1 &#043; 1<br \/>\n      &#061; 223 \/\/ 1 &#043; 1<br \/>\n      &#061; 223 &#043; 1<br \/>\n      &#061; 224 \u2705 \u5c3a\u5bf8\u4fdd\u6301\u4e0d\u53d8&#xff01;<\/p>\n<p>\u5173\u952e\u77e5\u8bc6\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5377\u79ef\u5c42\u89c4\u5f8b&#xff1a;\u901a\u9053\u6570\u4ece 3\u219264\u2192128\u2192256\u2192512&#xff08;\u9010\u6b65\u63d0\u53d6\u9ad8\u5c42\u7279\u5f81&#xff09;<\/li>\n<li>\u6c60\u5316\u5c42\u4f5c\u7528&#xff1a;\u6bcf\u6b21\u5c3a\u5bf8\u51cf\u534a&#xff0c;\u6700\u7ec8 224&#215;224\u21927&#215;7<\/li>\n<li>x.view(x.size()[0], -1)&#xff1a;\u5c55\u5e73\u7279\u5f81\u56fe&#xff0c;\u4e3a\u5168\u8fde\u63a5\u5c42\u505a\u51c6\u5907&#xff08;PyTorch \u4e2d-1\u8868\u793a\u81ea\u52a8\u8ba1\u7b97\u7ef4\u5ea6&#xff09;<\/li>\n<\/ul>\n<h5>&#xff08;6&#xff09;\u6838\u5fc3\u8bad\u7ec3\u51fd\u6570 train_val&#xff1a;\u6709\u76d1\u7763 &#043; \u534a\u76d1\u7763\u6df7\u5408\u8bad\u7ec3<\/h5>\n<p>\u8fd9\u662f\u4ee3\u7801\u7684\u6267\u884c\u6838\u5fc3&#xff0c;\u6574\u5408\u4e86\u6709\u76d1\u7763\u8bad\u7ec3\u3001\u534a\u76d1\u7763\u6837\u672c\u7b5b\u9009\u3001\u9a8c\u8bc1\u8bc4\u4f30&#xff1a;<\/p>\n<p>def train_val(model, train_loader, val_loader, no_label_loader, device, epochs, optimizer, loss, thres, save_path):<br \/>\n    model &#061; model.to(device)<br \/>\n    semi_loader &#061; None  # \u534a\u76d1\u7763\u6570\u636e\u52a0\u8f7d\u5668&#xff08;\u521d\u59cb\u4e3a\u7a7a&#xff09;<br \/>\n    # \u8bb0\u5f55\u8bad\u7ec3\/\u9a8c\u8bc1\u7684\u635f\u5931\u548c\u51c6\u786e\u7387<br \/>\n    plt_train_loss &#061; []<br \/>\n    plt_val_loss &#061; []<br \/>\n    plt_train_acc &#061; []<br \/>\n    plt_val_acc &#061; []<br \/>\n    max_acc &#061; 0.0  # \u8bb0\u5f55\u6700\u9ad8\u9a8c\u8bc1\u51c6\u786e\u7387<\/p>\n<p>    for epoch in range(epochs):<br \/>\n        train_loss &#061; 0.0<br \/>\n        val_loss &#061; 0.0<br \/>\n        train_acc &#061; 0.0<br \/>\n        val_acc &#061; 0.0<br \/>\n        semi_loss &#061; 0.0<br \/>\n        semi_acc &#061; 0.0<br \/>\n        start_time &#061; time.time()<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 1. \u6709\u76d1\u7763\u8bad\u7ec3&#xff08;\u8bad\u7ec3\u96c6&#xff09; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        model.train()  # \u8bad\u7ec3\u6a21\u5f0f&#xff08;\u542f\u7528BN\/Dropout&#xff09;<br \/>\n        for batch_x, batch_y in train_loader:<br \/>\n            x, target &#061; batch_x.to(device), batch_y.to(device)<br \/>\n            pred &#061; model(x)                          # \u6a21\u578b\u9884\u6d4b<br \/>\n            train_bat_loss &#061; loss(pred, target)      # \u8ba1\u7b97\u635f\u5931<br \/>\n            train_bat_loss.backward()                # \u53cd\u5411\u4f20\u64ad<br \/>\n            optimizer.step()                         # \u66f4\u65b0\u53c2\u6570<br \/>\n            optimizer.zero_grad()                    # \u68af\u5ea6\u6e05\u96f6&#xff08;\u5fc5\u987b&#xff01;&#xff09;<br \/>\n            train_loss &#043;&#061; train_bat_loss.cpu().item()# \u7d2f\u52a0\u635f\u5931<br \/>\n            # \u8ba1\u7b97\u51c6\u786e\u7387&#xff1a;\u9884\u6d4b\u6807\u7b7e&#061;argmax(pred)&#xff0c;\u548c\u771f\u5b9e\u6807\u7b7e\u6bd4\u8f83<br \/>\n            train_acc &#043;&#061; np.sum(np.argmax(pred.detach().cpu().numpy(), axis&#061;1) &#061;&#061; target.cpu().numpy())<br \/>\n        # \u8bb0\u5f55\u5e73\u5747\u635f\u5931\u548c\u51c6\u786e\u7387<br \/>\n        plt_train_loss.append(train_loss \/ len(train_loader))<br \/>\n        plt_train_acc.append(train_acc \/ len(train_loader.dataset))<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 2. \u534a\u76d1\u7763\u8bad\u7ec3&#xff08;\u53ef\u9009&#xff09; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        if semi_loader !&#061; None:  # \u6709\u534a\u76d1\u7763\u6570\u636e\u624d\u8bad\u7ec3<br \/>\n            for batch_x, batch_y in semi_loader:<br \/>\n                x, target &#061; batch_x.to(device), batch_y.to(device)<br \/>\n                pred &#061; model(x)<br \/>\n                semi_bat_loss &#061; loss(pred, target)<br \/>\n                semi_bat_loss.backward()<br \/>\n                optimizer.step()<br \/>\n                optimizer.zero_grad()<br \/>\n                semi_loss &#043;&#061; train_bat_loss.cpu().item()  # \u6ce8\u610f&#xff1a;\u8fd9\u91cc\u4ee3\u7801\u6709\u7b14\u8bef&#xff0c;\u5e94\u8be5\u662fsemi_bat_loss<br \/>\n                semi_acc &#043;&#061; np.sum(np.argmax(pred.detach().cpu().numpy(), axis&#061;1) &#061;&#061; target.cpu().numpy())<br \/>\n            print(&#034;\u534a\u76d1\u7763\u6570\u636e\u96c6\u7684\u8bad\u7ec3\u51c6\u786e\u7387\u4e3a&#034;, semi_acc \/ len(semi_loader.dataset))  # \u4fee\u6b63&#xff1a;\u7528semi_loader\u7684\u957f\u5ea6<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 3. \u9a8c\u8bc1\u96c6\u8bc4\u4f30 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        model.eval()  # \u8bc4\u4f30\u6a21\u5f0f&#xff08;\u5173\u95edBN\/Dropout&#xff09;<br \/>\n        with torch.no_grad():  # \u7981\u7528\u68af\u5ea6&#xff0c;\u63d0\u901f<br \/>\n            for batch_x, batch_y in val_loader:<br \/>\n                x, target &#061; batch_x.to(device), batch_y.to(device)<br \/>\n                pred &#061; model(x)<br \/>\n                val_bat_loss &#061; loss(pred, target)<br \/>\n                val_loss &#043;&#061; val_bat_loss.cpu().item()<br \/>\n                val_acc &#043;&#061; np.sum(np.argmax(pred.detach().cpu().numpy(), axis&#061;1) &#061;&#061; target.cpu().numpy())<br \/>\n        # \u8bb0\u5f55\u9a8c\u8bc1\u635f\u5931\/\u51c6\u786e\u7387&#xff08;\u6ce8\u610f&#xff1a;\u4ee3\u7801\u539f\u7b14\u8bef\u662fval_loader.dataset.__len__()&#xff0c;\u7edf\u4e00\u7528len(val_loader.dataset)&#xff09;<br \/>\n        plt_val_loss.append(val_loss \/ len(val_loader.dataset))<br \/>\n        plt_val_acc.append(val_acc \/ len(val_loader.dataset))<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 4. \u6bcf3\u8f6e\u7b5b\u9009\u4e00\u6b21\u534a\u76d1\u7763\u6570\u636e &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        if epoch % 3 &#061;&#061; 0 and plt_val_acc[-1] &gt; 0.6:  # \u9a8c\u8bc1\u51c6\u786e\u7387&gt;0.6\u624d\u5f00\u59cb\u534a\u76d1\u7763&#xff08;\u6a21\u578b\u8db3\u591f\u597d&#xff09;<br \/>\n            semi_loader &#061; get_semi_loader(no_label_loader, model, device, thres)<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 5. \u4fdd\u5b58\u6700\u4f18\u6a21\u578b &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        if val_acc &gt; max_acc:  # \u9a8c\u8bc1\u51c6\u786e\u7387\u66f4\u9ad8\u65f6\u4fdd\u5b58<br \/>\n            torch.save(model, save_path)<br \/>\n            max_acc &#061; val_acc  # \u4fee\u6b63&#xff1a;\u539f\u4ee3\u7801\u662fmax_acc &#061; val_loss&#xff0c;\u660e\u663e\u9519\u8bef&#xff01;<\/p>\n<p>        # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 6. \u6253\u5370\u8bad\u7ec3\u65e5\u5fd7 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n        print(&#039;[%03d\/%03d] %2.2f sec(s) TrainLoss : %.6f | valLoss: %.6f Trainacc : %.6f | valacc: %.6f&#039; % \\\\<br \/>\n              (epoch, epochs, time.time() &#8211; start_time, plt_train_loss[-1], plt_val_loss[-1], plt_train_acc[-1], plt_val_acc[-1]))<\/p>\n<p>    # &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 7. \u7ed8\u5236\u8bad\u7ec3\u66f2\u7ebf &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    plt.plot(plt_train_loss)<br \/>\n    plt.plot(plt_val_loss)<br \/>\n    plt.title(&#034;loss&#034;)<br \/>\n    plt.legend([&#034;train&#034;, &#034;val&#034;])<br \/>\n    plt.show()<\/p>\n<p>    plt.plot(plt_train_acc)<br \/>\n    plt.plot(plt_val_acc)<br \/>\n    plt.title(&#034;acc&#034;)<br \/>\n    plt.legend([&#034;train&#034;, &#034;val&#034;])<br \/>\n    plt.show()<\/p>\n<p>&#xff08;7&#xff09;\u4e3b\u7a0b\u5e8f&#xff1a;\u914d\u7f6e\u53c2\u6570 &#043; \u6267\u884c\u8bad\u7ec3<\/p>\n<p># \u6570\u636e\u8def\u5f84&#xff08;\u9002\u914d\u6837\u672c\u96c6&#xff09;<br \/>\ntrain_path &#061; r&#034;E:\\\\fenlei\\\\food_classification\\\\food-11_sample\\\\training\\\\labeled&#034;<br \/>\nval_path &#061; r&#034;E:\\\\fenlei\\\\food_classification\\\\food-11_sample\\\\validation&#034;<br \/>\nno_label_path &#061; r&#034;E:\\\\fenlei\\\\food_classification\\\\food-11_sample\\\\training\\\\unlabeled\\\\00&#034;<\/p>\n<p># \u6784\u5efa\u6570\u636e\u96c6<br \/>\ntrain_set &#061; food_Dataset(train_path, &#034;train&#034;)<br \/>\nval_set &#061; food_Dataset(val_path, &#034;val&#034;)<br \/>\nno_label_set &#061; food_Dataset(no_label_path, &#034;semi&#034;)<\/p>\n<p># \u6784\u5efa\u6570\u636e\u52a0\u8f7d\u5668&#xff08;batch_size&#061;16&#xff0c;\u8bad\u7ec3\u96c6shuffle&#061;True&#xff09;<br \/>\ntrain_loader &#061; DataLoader(train_set, batch_size&#061;16, shuffle&#061;True)<br \/>\nval_loader &#061; DataLoader(val_set, batch_size&#061;16, shuffle&#061;True)<br \/>\nno_label_loader &#061; DataLoader(no_label_set, batch_size&#061;16, shuffle&#061;False)<\/p>\n<p># \u6a21\u578b\u9009\u62e9&#xff1a;\u7528\u9884\u8bad\u7ec3VGG&#xff08;\u800c\u975e\u81ea\u5b9a\u4e49CNN&#xff09;<br \/>\nmodel, _ &#061; initialize_model(&#034;vgg&#034;, 11, use_pretrained&#061;True)<\/p>\n<p># \u8bad\u7ec3\u914d\u7f6e<br \/>\nlr &#061; 0.001<br \/>\nloss &#061; nn.CrossEntropyLoss()  # \u5206\u7c7b\u4efb\u52a1\u6807\u914d\u635f\u5931<br \/>\noptimizer &#061; torch.optim.AdamW(model.parameters(), lr&#061;lr, weight_decay&#061;1e-4)  # AdamW\u5e26\u6743\u91cd\u8870\u51cf&#xff08;L2\u6b63\u5219&#xff09;<br \/>\ndevice &#061; &#034;cuda&#034; if torch.cuda.is_available() else &#034;cpu&#034;  # GPU\u4f18\u5148<br \/>\nsave_path &#061; &#034;model_save\/best_model.pth&#034;<br \/>\nepochs &#061; 15<br \/>\nthres &#061; 0.99<\/p>\n<p># \u542f\u52a8\u8bad\u7ec3<br \/>\ntrain_val(model, train_loader, val_loader, no_label_loader, device, epochs, optimizer, loss, thres, save_path)<\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u77e5\u8bc6\u70b9&#xff1a;<\/p>\n<\/li>\n<li>\u9884\u8bad\u7ec3\u6a21\u578b&#xff1a;initialize_model(&#034;vgg&#034;, 11) \u52a0\u8f7d VGG16\/19 \u9884\u8bad\u7ec3\u6743\u91cd&#xff0c;\u51bb\u7ed3\u5e95\u5c42\u7279\u5f81\u63d0\u53d6\u5c42&#xff08;\u4ee3\u7801\u4e2d\u672a\u663e\u5f0f\u51bb\u7ed3&#xff0c;\u4f46use_pretrained&#061;True\u4f1a\u52a0\u8f7d\u6743\u91cd&#xff09;<\/li>\n<li>\u4f18\u5316\u5668&#xff1a;AdamW \u662f Adam &#043; \u6743\u91cd\u8870\u51cf&#xff0c;\u6bd4 SGD \u6536\u655b\u66f4\u5feb&#xff0c;\u6bd4\u539f\u59cb Adam \u66f4\u7a33\u5b9a<\/li>\n<li>weight_decay&#061;1e-4&#xff1a;L2 \u6b63\u5219&#xff0c;\u9632\u6b62\u8fc7\u62df\u5408<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. \u4ee3\u7801\u6574\u4f53\u529f\u80fd\u6982\u8ff0\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u534a\u76d1\u7763\u5b66\u4e60\u7684\u98df\u54c1\u56fe\u50cf\u5206\u7c7b\u4efb\u52a1&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u5982\u4e0b&#xff1a;\u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u5b9e\u9a8c\u7ed3\u679c\u53ef\u590d\u73b0\u5b9a\u4e49\u56fe\u50cf\u9884\u5904\u7406\u7b56\u7565&#xff08;\u8bad\u7ec3\u96c6\u6570\u636e\u589e\u5f3a\u3001\u9a8c\u8bc1\u96c6\u4ec5\u6807\u51c6\u5316&#xff09;\u81ea\u5b9a\u4e49\u6570\u636e\u96c6\u7c7b&#xff1a;\u652f\u6301\u8bfb\u53d6\u6709\u6807\u7b7e\u6570\u636e&#xff08;\u8bad\u7ec3 \/ \u9a8c\u8bc1&#xff09;\u548c\u65e0\u6807\u7b7e\u6570\u636e&#xff08;\u534a\u76d1\u7763&#xff09;\u5b9e\u73b0\u534a\u76d1\u7763\u903b\u8f91&#xff1a;\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e&#xff0c;\u7b5b\u9009\u7f6e\u4fe1\u5ea6\u9ad8\u7684\u6837\u672c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[152,2395,86],"topic":[],"class_list":["post-75471","post","type-post","status-publish","format-standard","hentry","category-server","tag-pytorch","tag-2395","tag-86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/75471.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1. \u4ee3\u7801\u6574\u4f53\u529f\u80fd\u6982\u8ff0\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u534a\u76d1\u7763\u5b66\u4e60\u7684\u98df\u54c1\u56fe\u50cf\u5206\u7c7b\u4efb\u52a1&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u5982\u4e0b&#xff1a;\u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u5b9e\u9a8c\u7ed3\u679c\u53ef\u590d\u73b0\u5b9a\u4e49\u56fe\u50cf\u9884\u5904\u7406\u7b56\u7565&#xff08;\u8bad\u7ec3\u96c6\u6570\u636e\u589e\u5f3a\u3001\u9a8c\u8bc1\u96c6\u4ec5\u6807\u51c6\u5316&#xff09;\u81ea\u5b9a\u4e49\u6570\u636e\u96c6\u7c7b&#xff1a;\u652f\u6301\u8bfb\u53d6\u6709\u6807\u7b7e\u6570\u636e&#xff08;\u8bad\u7ec3 \/ \u9a8c\u8bc1&#xff09;\u548c\u65e0\u6807\u7b7e\u6570\u636e&#xff08;\u534a\u76d1\u7763&#xff09;\u5b9e\u73b0\u534a\u76d1\u7763\u903b\u8f91&#xff1a;\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e&#xff0c;\u7b5b\u9009\u7f6e\u4fe1\u5ea6\u9ad8\u7684\u6837\u672c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/75471.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-12T04:17:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75471.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/75471.html\",\"name\":\"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-12T04:17:42+00:00\",\"dateModified\":\"2026-02-12T04:17:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/75471.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/75471.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75471.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/75471.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1. \u4ee3\u7801\u6574\u4f53\u529f\u80fd\u6982\u8ff0\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u534a\u76d1\u7763\u5b66\u4e60\u7684\u98df\u54c1\u56fe\u50cf\u5206\u7c7b\u4efb\u52a1&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u5982\u4e0b&#xff1a;\u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u5b9e\u9a8c\u7ed3\u679c\u53ef\u590d\u73b0\u5b9a\u4e49\u56fe\u50cf\u9884\u5904\u7406\u7b56\u7565&#xff08;\u8bad\u7ec3\u96c6\u6570\u636e\u589e\u5f3a\u3001\u9a8c\u8bc1\u96c6\u4ec5\u6807\u51c6\u5316&#xff09;\u81ea\u5b9a\u4e49\u6570\u636e\u96c6\u7c7b&#xff1a;\u652f\u6301\u8bfb\u53d6\u6709\u6807\u7b7e\u6570\u636e&#xff08;\u8bad\u7ec3 \/ \u9a8c\u8bc1&#xff09;\u548c\u65e0\u6807\u7b7e\u6570\u636e&#xff08;\u534a\u76d1\u7763&#xff09;\u5b9e\u73b0\u534a\u76d1\u7763\u903b\u8f91&#xff1a;\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u65e0\u6807\u7b7e\u6570\u636e\u6253\u4f2a\u6807\u7b7e&#xff0c;\u7b5b\u9009\u7f6e\u4fe1\u5ea6\u9ad8\u7684\u6837\u672c","og_url":"https:\/\/www.wsisp.com\/helps\/75471.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-12T04:17:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/75471.html","url":"https:\/\/www.wsisp.com\/helps\/75471.html","name":"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-12T04:17:42+00:00","dateModified":"2026-02-12T04:17:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/75471.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/75471.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/75471.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8e PyTorch \u7684\u534a\u76d1\u7763\u98df\u54c1\u5206\u7c7b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=75471"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75471\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=75471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=75471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=75471"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=75471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}