{"id":8945,"date":"2024-05-20T20:01:01","date_gmt":"2024-05-20T12:01:01","guid":{"rendered":""},"modified":"2024-05-20T20:01:01","modified_gmt":"2024-05-20T12:01:01","slug":"YOLOV5\u8bad\u7ec3\u4ee3\u7801train.py\u8bad\u7ec3\u53c2\u6570\u89e3\u6790","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8945.html","title":{"rendered":"YOLOV5\u8bad\u7ec3\u4ee3\u7801train.py\u8bad\u7ec3\u53c2\u6570\u89e3\u6790"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u4e00\uff0c\u524d\u8a00<\/h2>\n

yolov5\u9879\u76ee\u4ee3\u7801\u4e2d\uff0ctrain.py\u662f\u7528\u4e8e\u6a21\u578b\u8bad\u7ec3\u7684\u4ee3\u7801\uff0c\u662fyolov5\u4e2d\u6700\u4e3a\u6838\u5fc3\u7684\u4ee3\u7801\u4e4b\u4e00\uff0c\u800c\u4ee3\u7801\u4e2d\u7684\u8bad\u7ec3\u53c2\u6570\u5219\u662f\u6838\u5fc3\u4e2d\u7684\u6838\u5fc3\uff0c\u53ea\u6709\u5b66\u4f1a\u4e86\u5404\u79cd\u8bad\u7ec3\u53c2\u6570\u7684\u771f\u6b63\u542b\u4e49\uff0c\u624d\u80fd\u4f7f\u7528yolov5\u8fdb\u884c\u6700\u57fa\u672c\u7684\u8bad\u7ec3\u3002<\/p>\n

\u672c\u6587\u8bb2\u89e3\u7684yolov5\u7248\u672c\u4e3a\u76ee\u524d\u6700\u65b0\u7684V7.0
yolov5\u5b98\u65b9GitHub\u5730\u5740: https:\/\/github.com\/ultralytics\/yolov5<\/p>\n

\u4e8c\uff0c\u8bad\u7ec3\u53c2\u6570\u89e3\u6790<\/h2>\n

yolov5\u4e2dtrain.py\u91c7\u7528python\u5185\u7f6e\u7684\u547d\u4ee4\u884c\u9009\u9879\u3001\u53c2\u6570\u548c\u5b50\u547d\u4ee4\u89e3\u6790\u5668\u6a21\u5757argparse\uff0c\u5bf9\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u547d\u4ee4\u884c\u9009\u9879\uff0c\u53c2\u6570\u548c\u5b50\u547d\u4ee4\u8fdb\u884c\u89e3\u6790\uff0c\u7136\u540e\u5c06\u89e3\u6790\u51fa\u6765\u7684\u9009\u9879\uff0c\u53c2\u6570\u548c\u5b50\u547d\u4ee4\u4f20\u7ed9\u4ee3\u7801\u4e2d\u9700\u8981\u7528\u5230\u7684\u5730\u65b9\u3002<\/p>\n

\n

\u6ce8\uff1a\u5173\u4e8eargparse\u6a21\u5757\u7684\u57fa\u672c\u4f7f\u7528\uff0c\u53ef\u4ee5\u770b\u6211\u7684\u53e6\u4e00\u7bc7\u535a\u5ba2\uff1a
\u94fe\u63a5: python\u57fa\u7840\u4e4b\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\u6a21\u5757\uff1aargparse.ArgumentParser(add_argument)
\u5f3a\u70c8\u5efa\u8bae\u5148\u5b66\u4e60\u4e00\u4e0bargparse\u6a21\u5757\u7684\u57fa\u672c\u4f7f\u7528\uff0c\u8981\u4e0d\u7136\u6a21\u5757\u4e2d\u6709\u4e9b\u53c2\u6570\u548c\u7528\u6cd5\u4f1a\u770b\u4e0d\u61c2\uff0c\u6216\u8005\u8fb9\u5b66\u8fb9\u770b\uff0c\u8fb9\u770b\u8fb9\u5b66\u3002<\/p>\n<\/blockquote>\n

1\uff0c\u2013weights<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--weights'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>ROOT \/<\/span> 'yolov5s.pt'<\/span>,<\/span> help<\/span>=<\/span>'initial weights path'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a \u6a21\u578b\u9884\u8bad\u7ec3\u6743\u91cd\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e3aROOT \/ \u2018yolov5s.pt\u2019<\/strong>
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --weights yolov5s.pt<\/strong>
\u6ce8\uff1a
1\uff0c\u82e5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\"\u2013weights\" \u53c2\u6570\uff0c\u53ef\u6307\u5b9a\u9884\u8bad\u7ec3\u6743\u91cd\u6587\u4ef6(\u8def\u5f84)\uff1b
2\uff0c\u82e5\u5728\u547d\u4ee4\u884c\u4e0d\u4f7f\u7528\"\u2013weights\" \u53c2\u6570\uff0c\u5219\u9884\u8bad\u7ec3\u6743\u91cd\u6587\u4ef6(\u8def\u5f84)\u4e3a\u81ea\u5b9a\u4e49\u7684default\u9ed8\u8ba4\u503c\uff1b
3\uff0c\u82e5\u65e2\u4f7f\u7528\u547d\u4ee4\u884c\"\u2013weights\" \u53c2\u6570\uff0c\u53c8\u81ea\u5b9a\u4e49\u4e86default\u9ed8\u8ba4\u503c\uff0c\u5219\u6a21\u578b\u4f7f\u7528\u7684\u662f\u547d\u4ee4\u884c\"\u2013weights\" \u53c2\u6570\u6307\u5b9a\u7684\u9884\u8bad\u7ec3\u6743\u91cd\u6587\u4ef6(\u8def\u5f84)
4\uff0c\u82e5\u4e0d\u8fdb\u884c\u9884\u8bad\u7ec3\uff0c\u53ef\u4f7f\u7528\"\u2013weights\" \u53c2\u6570\u6307\u5b9a\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\uff1a\u201c\u201d\uff0c\u6216\u8005\u5c06default\u9ed8\u8ba4\u503c\u8bbe\u7f6e\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff1a\u201c\u201d\uff1b
5\uff0c\u82e5\u4f7f\u7528yolov5s.pt\u3001yolov5m.pt\u3001yolov5l.pt\u3001yolov5x.pt\u7b49yolov5\u5b98\u65b9\u9884\u8bad\u7ec3\u6743\u91cd\u6587\u4ef6\uff0c\u82e5\u6ca1\u6709\u4e0b\u8f7d\uff0c\u4ee3\u7801\u4f1a\u81ea\u52a8\u5e2e\u4f60\u4e0b\u8f7d\uff0c\u653e\u5728ROOT\u8def\u5f84\u4e0b\uff0c\u4e5f\u5c31\u662f\u4f60yolov5\u5de5\u7a0b\u9879\u76ee\u8def\u5f84\u4e0b\uff0c\u4f46\u662f\u4e0b\u8f7d\u901f\u5ea6\u4e00\u822c\u4f1a\u5f88\u6162\uff0c\u5efa\u8bae\u5148\u53bbyolov5\u5b98\u65b9GitHub\u4e2d\u4e0b\u8f7d\u597d\u3002<\/p>\n<\/blockquote>\n

2\uff0c\u2013cfg<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--cfg'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>''<\/span>,<\/span> help<\/span>=<\/span>'model.yaml path'<\/span>)<\/span>\npython train.<\/span>py -<\/span>-<\/span>cfg yolov5s.<\/span>pt**<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u6a21\u578b\u7ed3\u6784\u6587\u4ef6\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e3a\u7a7a
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --cfg models\/yolov5s.yaml
\u6ce8\uff1a
1\uff0c\u5728\u5df2\u7ecf\u4f7f\u7528\"\u2013weights\" \u53c2\u6570\u52a0\u8f7d\u4e86\u9884\u8bad\u7ec3\u6743\u91cd\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4e0d\u4f7f\u7528\u8be5\u53c2\u6570\uff0c\u6a21\u578b\u7ed3\u6784\u76f4\u63a5\u4f7f\u7528\u9884\u8bad\u7ec3\u6743\u91cd\u4e2d\u4fdd\u5b58\u7684\u6a21\u578b\u7ed3\u6784\uff1b
2\uff0c\u4e0d\u4f7f\u7528\"\u2013weights\" \u53c2\u6570\u4f7f\u7528\"\u2013cfg\" \u53c2\u6570\uff0c\u8868\u793a\u6a21\u578b\u4ece\u5934\u5f00\u59cb\u8bad\u7ec3\uff0c\u4e0d\u8fdb\u884c\u9884\u8bad\u7ec3\uff1b
3\uff0c\u201c\u2013weights\u201d \u53c2\u6570\u548c\"\u2013cfg\" \u53c2\u6570\u5fc5\u987b\u8981\u6709\u4e00\u4e2a\uff0c\u4e0d\u7136\u4ee3\u7801\u4f1a\u62a5\u9519\u3002<\/p>\n<\/blockquote>\n

3\uff0c\u2013data<\/strong><\/em><\/h3>\n
 parser.<\/span>add_argument(<\/span>'--data'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>ROOT \/<\/span> 'data\/coco128.yaml'<\/span>,<\/span> help<\/span>=<\/span>'dataset.yaml path'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u6570\u636e\u96c6\u914d\u7f6e\u6587\u4ef6\u8def\u5f84
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --data data\/coco128.yaml
\u6ce8\uff1a
1\uff0c\u5982\u679c\u6ca1\u6709\u68c0\u67e5\u5230\u6570\u636e\u96c6\uff0c\u4ee3\u7801\u4f1a\u81ea\u52a8\u4e0b\u8f7dcoco128\u6570\u636e\u96c6\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u4e0b\u8f7d\uff1b
2\uff0c\u628ayolov5\u5b98\u65b9\u7684\u6570\u636e\u96c6\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u96c6\u4e0b\u8f7d\u90e8\u5206\u5185\u5bb9\u7ed9\u6ce8\u91ca\u6389\uff0c\u4ee3\u7801\u5219\u4e0d\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u3002<\/p>\n<\/blockquote>\n

4\uff0c\u2013hyp<\/strong><\/em><\/h3>\n
 parser.<\/span>add_argument(<\/span>'--hyp'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>ROOT \/<\/span> 'data\/hyps\/hyp.scratch-low.yaml'<\/span>,<\/span> help<\/span>=<\/span>'hyperparameters path'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u8d85\u53c2\u6570\u914d\u7f6e\u6587\u4ef6\u8def\u5f84
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --hyp data\/hyps\/hyp.scratch-low.yaml<\/p>\n<\/blockquote>\n

5\uff0c\u2013epochs<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--epochs'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>100<\/span>,<\/span> help<\/span>=<\/span>'total training epochs'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u8fed\u4ee3\u8f6e\u6570
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --epochs n
\u6ce8\uff1a
1\uff0cepochs\u8868\u793a\u8bad\u7ec3\u6574\u4e2a\u8bad\u7ec3\u96c6\u7684\u6b21\u6570\uff0cepoch\u4e3an\u8868\u793a\u5c06\u6574\u4e2a\u8bad\u7ec3\u96c6\u8bad\u7ec3n\u6b21\u3002<\/p>\n<\/blockquote>\n

6\uff0c\u2013batch-size<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--batch-size'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>16<\/span>,<\/span> help<\/span>=<\/span>'total batch size for all GPUs, -1 for autobatch'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u6279\u91cf\u5927\u5c0f
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --batch-size n
\u6ce8\uff1a
1\uff0c\u8bad\u7ec3\u6279\u91cf\u5927\u5c0f\u8868\u793a\u6bcf\u4e2a mini-batch \u4e2d\u7684\u6837\u672c\u6570\uff0cbatch-size\u8bbe\u7f6e\u4e3an\u8868\u793a\u4e00\u6b21\u6027\u4ece\u8bad\u7ec3\u96c6\u4e2d\u83b7\u53d6n\u5f20\u56fe\u7247\u9001\u5165\u6a21\u578b\u8fdb\u884c\u8bad\u7ec3\uff1b
2\uff0c batch-size\u5927\u5c0f\u9700\u8981\u6839\u636e\u81ea\u5df1\u8bbe\u5907GPU\u7684\u8d44\u6e90\u5408\u7406\u8bbe\u7f6e\u3002<\/p>\n<\/blockquote>\n

7\uff0c\u2013imgsz, --img, --img-size<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--imgsz'<\/span>,<\/span> '--img'<\/span>,<\/span> '--img-size'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>640<\/span>,<\/span> help<\/span>=<\/span>'train, val image size (pixels)'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u6a21\u578b\u8bad\u7ec3\u548c\u9a8c\u8bc1\u65f6\u8f93\u5165\u56fe\u7247\u7684\u5c3a\u5bf8
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --imgsz\/img\/\u2013img-size 640<\/p>\n<\/blockquote>\n

8\uff0c\u2013rect<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--rect'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'rectangular training'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u77e9\u5f62\u8bad\u7ec3\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --rect
\u6ce8\uff1a
1\uff0c\u77e9\u5f62\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u4f1a\u5bf9\u8f93\u5165\u7684\u77e9\u5f62\u56fe\u7247\u8fdb\u884c\u9884\u5904\u7406\uff0c\u901a\u8fc7\u4fdd\u6301\u539f\u56fe\u9ad8\u5bbd\u6bd4\u8fdb\u884cresize\u540e\uff0c\u5bf9resize\u540e\u7684\u56fe\u7247\u8fdb\u884c\u586b\u5145\uff0c\u586b\u5145\u523032\u7684\u6700\u5c0f\u6574\u6570\u500d\uff0c\u7136\u540e\u8fdb\u884c\u77e9\u5f62\u8bad\u7ec3\uff0c\u51cf\u5c11\u8bad\u7ec3\u65f6\u95f4\u3002<\/p>\n<\/blockquote>\n

9\uff0c\u2013resum<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--resume'<\/span>,<\/span> nargs=<\/span>'?'<\/span>,<\/span> const=<\/span>True<\/span>,<\/span> default=<\/span>False<\/span>,<\/span> help<\/span>=<\/span>'resume most recent training'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u65ad\u70b9\u7eed\u8bad\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py ----weights \/path\/last.pt --rect
\u6ce8\uff1a
1\uff0c\u65ad\u70b9\u7eed\u8bad\u5c31\u662f\u4ece\u4e0a\u4e00\u4e2a\u8bad\u7ec3\u4efb\u52a1\u4e2d\u65ad\u7684\u5730\u65b9\u7ee7\u7eed\u8bad\u7ec3\uff0c\u76f4\u81f3\u8bad\u7ec3\u5b8c\u6210\uff1b
2\uff0c\u5f53\u6a21\u578b\u6309\u6307\u5b9a\u7684epoch\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u5219\u65e0\u6cd5\u8fdb\u884c\u65ad\u70b9\u7eed\u8bad\uff1b
3\uff0c\u9700\u8981\u642d\u914d\"\u2013weights\" \u53c2\u6570\u4f7f\u7528\uff0c\u6307\u5b9a\u8bad\u7ec3\u4e2d\u65ad\u4fdd\u5b58\u7684\u6700\u540e\u4e00\u6b21\u6a21\u578b\u6743\u91cd\u6587\u4ef6\u3002<\/p>\n<\/blockquote>\n

10\uff0c\u2013nosave<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--nosave'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'only save final checkpoint'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u53ea\u4fdd\u7559\u6700\u540e\u4e00\u6b21\u8bad\u7ec3\u7684\u6743\u91cd\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --nosave<\/p>\n<\/blockquote>\n

11\uff0c\u2013noval<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--noval'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'only validate final epoch'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u53ea\u5bf9\u6700\u540e\u4e00\u6b21\u8bad\u7ec3\u8fdb\u884c\u9a8c\u8bc1\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --noval<\/p>\n<\/blockquote>\n

12\uff0c\u2013noautoanchor<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--noautoanchor'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'disable AutoAnchor'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u5173\u95ed\u81ea\u52a8\u8ba1\u7b97\u951a\u6846\u529f\u80fd\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --noautoanchor
\u6ce8\uff1a
1\uff0cyolov5\u91c7\u7528\u7684\u662fkmeans\u805a\u7c7b\u7b97\u6cd5\u6765\u8ba1\u7b97anchor box\u7684\u5927\u5c0f\u548c\u6bd4\u4f8b\uff0c\u6700\u7ec8\u81ea\u52a8\u8ba1\u7b97\u51fa\u4e00\u7ec4\u6700\u5408\u9002\u8bad\u7ec3\u7684\u951a\u6846\u3002<\/p>\n<\/blockquote>\n

13\uff0c\u2013noplots<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--noplots'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'save no plot files'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u4e0d\u4fdd\u5b58\u53ef\u89c6\u5316\u6587\u4ef6
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --noplots<\/p>\n<\/blockquote>\n

14\uff0c\u2013evolve<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--evolve'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> nargs=<\/span>'?'<\/span>,<\/span> const=<\/span>300<\/span>,<\/span> help<\/span>=<\/span>'evolve hyperparameters for x generations'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u4f7f\u7528\u8d85\u53c2\u6570\u4f18\u5316\u7b97\u6cd5\u8fdb\u884c\u81ea\u52a8\u8c03\u53c2\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --evolve n
\u6ce8\uff1a
1\uff0cyolov5\u91c7\u7528\u9057\u4f20\u7b97\u6cd5\u5bf9\u8d85\u53c2\u6570\u8fdb\u884c\u4f18\u5316\uff0c\u5bfb\u627e\u4e00\u7ec4\u6700\u4f18\u7684\u8bad\u7ec3\u8d85\u53c2\u6570\uff1b
2\uff0c\u5f00\u542f\u540e\u4f20\u5165\u53c2\u6570n\uff0c\u8bad\u7ec3\u6bcf\u8fed\u4ee3n\u6b21\u8fdb\u884c\u4e00\u6b21\u8d85\u53c2\u6570\u8fdb\u5316\uff1b
3\uff0c\u5f00\u542f\u540e\u4e0d\u4f20\u5165\u53c2\u6570\uff0c\u5219\u9ed8\u8ba4\u4e3aconst=300\u3002<\/p>\n<\/blockquote>\n

15\uff0c\u2013bucket<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--bucket'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>''<\/span>,<\/span> help<\/span>=<\/span>'gsutil bucket'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u4ece\u8c37\u6b4c\u4e91\u76d8\u4e0b\u8f7d\u6216\u4e0a\u4f20\u6570\u636e
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --bucket gsutil bucket
\u6ce8\uff1a
1\uff0c\u8be5\u53c2\u6570\u7528\u4e8e\u6307\u5b9a gsutil bucket \u7684\u540d\u79f0\uff0c\u5176\u4e2d gsutil \u662f Google \u63d0\u4f9b\u7684\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u8bbf\u95ee Google Cloud Storage\uff08GCS\uff09\u670d\u52a1\uff1b
2\uff0cGCS \u662f Google \u63d0\u4f9b\u7684\u4e00\u79cd\u5bf9\u8c61\u5b58\u50a8\u670d\u52a1\uff0c\u7528\u6237\u53ef\u4ee5\u5c06\u4efb\u610f\u6570\u91cf\u548c\u7c7b\u578b\u7684\u6570\u636e\u5b58\u50a8\u5728\u5176\u4e2d\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7 gsutil \u547d\u4ee4\u884c\u5de5\u5177\u4e0a\u4f20\u3001\u4e0b\u8f7d\u3001\u590d\u5236\u3001\u5220\u9664\u7b49\u64cd\u4f5c GCS \u4e2d\u7684\u6570\u636e\u3002\u5728\u8bad\u7ec3\u6a21\u578b\u65f6\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528 GCS \u4e2d\u7684\u6570\u636e\u96c6\uff0c\u5c31\u9700\u8981\u6307\u5b9a bucket \u7684\u540d\u79f0\u3002<\/p>\n<\/blockquote>\n

16\uff0c\u2013cache<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--cache'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> nargs=<\/span>'?'<\/span>,<\/span> const=<\/span>'ram'<\/span>,<\/span> help<\/span>=<\/span>'image --cache ram\/disk'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u7f13\u5b58\u6570\u636e\u96c6\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --cache
\u6ce8\uff1a
1\uff0c\u7f13\u5b58\u6570\u636e\u96c6\u56fe\u7247\u5230\u5185\u5b58\u4e2d\uff0c\u8bad\u7ec3\u65f6\u6a21\u578b\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\uff0c\u52a0\u5feb\u6570\u636e\u52a0\u8f7d\u548c\u8bad\u7ec3\u901f\u5ea6
2\uff0c\u82e5\"\u2013cache\"\u53c2\u6570\u6307\u5b9a\u503c\uff0c\u53ef\u4ee5\u6307\u5b9a\u7684\uff1b\u503c\uff1aram\/disk\uff1b
3\uff0c\u82e5\"\u2013cache\"\u53c2\u6570\u4e0d\u6307\u5b9a\u503c\uff0c\u5219\u9ed8\u8ba4\u4e3aconst=\u2018ram\u2019\u3002<\/p>\n<\/blockquote>\n

17\uff0c\u2013image-weights<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--image-weights'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'use weighted image selection for training'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u5bf9\u6570\u636e\u96c6\u56fe\u7247\u8fdb\u884c\u52a0\u6743\u8bad\u7ec3\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --image-weights --rect
\u6ce8\uff1a
1\uff0c\u9700\u8981\u642d\u914d\"\u2013rect\"\u53c2\u6570\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<\/blockquote>\n

18\uff0c\u2013device<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--device'<\/span>,<\/span> default=<\/span>''<\/span>,<\/span> help<\/span>=<\/span>'cuda device, i.e. 0 or 0,1,2,3 or cpu'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u9009\u62e9\u8bad\u7ec3\u4f7f\u7528\u7684\u8bbe\u5907\u5904\u7406\u5668\uff0cCPU\u6216\u8005GPU\uff0c\u9ed8\u8ba4\u4e3a\u7a7a
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --device 0\/0,1,2,3\/cpu
\u6ce8\uff1a
1\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u65f6\uff0c\u4ee3\u7801\u4f1a\u8fdb\u884c\u81ea\u52a8\u9009\u62e9\uff0c\u82e5\u68c0\u67e5\u5230\u8bbe\u5907\u6709GPU\u5219\u4f18\u5148\u4f7f\u7528GPU\u8fdb\u884c\u8bad\u7ec3\uff0c\u82e5\u6ca1\u6709\u5219\u4f7f\u7528CPU\u8fdb\u884c\u8bad\u7ec3\uff1b
2\uff0c\u4f7f\u7528GPU\u8bad\u7ec3\u65f6\uff0c0,1,2,3\u5206\u522b\u8868\u793a\u7b2c1\uff0c2\uff0c3\uff0c4\u5f20GPU\uff1b
3\uff0c\u8bbe\u5907\u6ca1\u6709GPU\uff0c\u4f7f\u7528CPU\u8bad\u7ec3\uff1a
python train.py --device cpu
4\uff0c\u8bbe\u5907\u6709\u5355\u4e2aGPU\uff0c\u4f7f\u7528\u5355\u4e2aGPU\u8bad\u7ec3\uff1a
python train.py --device 0
5\uff0c\u8bbe\u5907\u6709\u591a\u4e2aGPU\uff0c\u4f7f\u7528\u5355\u4e2aGPU\u8bad\u7ec3\uff1a
python train.py --device 0 \uff08\u4f7f\u7528\u7b2c1\u5f20GPU\u8bad\u7ec3\uff09\uff1b
python train.py --device 2 \uff08\u4f7f\u7528\u7b2c3\u5f20GPU\u8bad\u7ec3\uff09\uff1b
6\uff0c\u8bbe\u5907\u6709\u591a\u4e2aGPU\uff0c\u4f7f\u7528\u591a\u4e2aGPU\u8bad\u7ec3\uff1a
python train.py --device 0,1,2\uff08\u4f7f\u7528\u7b2c1,2,3\u5f20GPU\u8bad\u7ec3\u8bad\u7ec3\uff09\u3002<\/p>\n<\/blockquote>\n

19\uff0c\u2013multi-scale<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--multi-scale'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'vary img-size +\/- 50%%'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u591a\u5c3a\u5ea6\u8bad\u7ec3\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --multi-scale
\u6ce8\uff1a
1\uff0c\u5f00\u542f\u591a\u5c3a\u5ea6\u8bad\u7ec3\uff0c\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6bcf\u6b21\u8f93\u5165\u56fe\u7247\u4f1a\u653e\u5927\u6216\u7f29\u5c0f50%\u3002<\/p>\n<\/blockquote>\n

20\uff0c\u2013single-cls<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--single-cls'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'train multi-class data as single-class'<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u5355\u7c7b\u522b\u8bad\u7ec3\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --single-cls<\/p>\n<\/blockquote>\n

21\uff0c\u2013optimizer<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--optimizer'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> choices=<\/span>[<\/span>'SGD'<\/span>,<\/span> 'Adam'<\/span>,<\/span> 'AdamW'<\/span>]<\/span>,<\/span> default=<\/span>'SGD'<\/span>,<\/span> help<\/span>=<\/span>'optimizer'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u9009\u62e9\u8bad\u7ec3\u4f7f\u7528\u7684\u4f18\u5316\u5668\uff0c\u9ed8\u8ba4\u4f7f\u7528SGD
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --optimizer SGD
\u6ce8\uff1a
1\uff0cchoices=[\u2018SGD\u2019, \u2018Adam\u2019, \u2018AdamW\u2019]\u8868\u793a\u53ea\u80fd\u9009\u62e9\u2019SGD\u2019, \u2018Adam\u2019, 'AdamW\u2019\u8fd9\u4e09\u79cd\u4f18\u5316\u5668\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u4f18\u5316\u5668\uff0c\u4f46\u4ee3\u7801\u4e2d\u5176\u4ed6\u5730\u65b9\u4e5f\u8981\u505a\u76f8\u5e94\u7684\u66f4\u6539\u3002<\/p>\n<\/blockquote>\n

22\uff0c\u2013sync-bn<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--sync-bn'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'use SyncBatchNorm, only available in DDP mode'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u4f7f\u7528SyncBatchNorm(Synchronized Batch Normalization\uff1a\u540c\u6b65\u6279\u91cf\u5f52\u4e00\u5316)\uff0c\u53ea\u6709\u5728\u4f7f\u7528DDP\u6a21\u5f0f(\u5206\u5e03\u5f0f\u8bad\u7ec3)\u65f6\u6709\u6548\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u4f7f\u7528\u65b9\u6cd5\uff1apython train.py --sync-bn
\u6ce8\uff1a
1\uff0c\u5173\u95ed\u65f6\uff0c\u8bad\u7ec3\u4f7f\u7528\u4f20\u7edf\u7684\u6279\u91cf\u5f52\u4e00\u5316\uff1b
2\uff0c\u5728\u4f20\u7edf\u7684\u6279\u5f52\u4e00\u5316\uff08Batch Normalization\uff0c\u7b80\u79f0 BN\uff09\u4e2d\uff0c\u6bcf\u4e2a GPU \u4f1a\u5bf9\u6570\u636e\u7684\u5747\u503c\u548c\u65b9\u5dee\u8fdb\u884c\u5355\u72ec\u8ba1\u7b97\uff0c\u56e0\u6b64\u5728\u591a GPU \u8bad\u7ec3\u65f6\uff0c\u6bcf\u4e2a GPU \u8ba1\u7b97\u7684\u5747\u503c\u548c\u65b9\u5dee\u53ef\u80fd\u4f1a\u4e0d\u540c\uff0c\u5bfc\u81f4\u6a21\u578b\u8bad\u7ec3\u4e0d\u7a33\u5b9a\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cSyncBN \u6280\u672f\u5c06 BN \u7684\u8ba1\u7b97\u653e\u5728\u4e86\u6574\u4e2a\u5206\u5e03\u5f0f\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u8fdb\u884c\uff0c\u786e\u4fdd\u6240\u6709 GPU \u4e0a\u8ba1\u7b97\u7684\u5747\u503c\u548c\u65b9\u5dee\u662f\u4e00\u81f4\u7684\uff0c\u4ece\u800c\u63d0\u9ad8\u6a21\u578b\u8bad\u7ec3\u7684\u7a33\u5b9a\u6027\u548c\u6548\u679c\uff0c\u4f46\u540c\u65f6\u4e5f\u4f1a\u589e\u52a0\u8bad\u7ec3\u65f6\u95f4\u548c\u786c\u4ef6\u8981\u6c42\uff0c\u56e0\u6b64\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u8bad\u7ec3\u6570\u636e\u548c\u786c\u4ef6\u8d44\u6e90\u6765\u51b3\u5b9a\u662f\u5426\u4f7f\u7528 SyncBN\u3002<\/p>\n<\/blockquote>\n

23\uff0c\u2013workers<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--workers'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>8<\/span>,<\/span> help<\/span>=<\/span>'max dataloader workers (per RANK in DDP mode)'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bbe\u7f6eDataloader\u4f7f\u7528\u7684\u6700\u5927numworkers\uff0c\u9ed8\u8ba4\u8bbe\u7f6e\u4e3a8
\u547d\u4ee4\u884c\u4f7f\u7528\u65b9\u6cd5\uff1apython train.py --workers 8
\u6ce8\uff1a
1\uff0cDataloader\u4e2dnumworkers\u8868\u793a\u52a0\u8f7d\u5904\u7406\u6570\u636e\u4f7f\u7528\u7684\u7ebf\u7a0b\u6570\uff0c\u4f7f\u7528\u591a\u7ebf\u7a0b\u52a0\u8f7d\u6570\u636e\u65f6\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u4f1a\u8d1f\u8d23\u52a0\u8f7d\u548c\u5904\u7406\u4e00\u6279\u6570\u636e\uff0c\u6570\u636e\u52a0\u8f7d\u5904\u7406\u5b8c\u6210\u540e\uff0c\u4f1a\u9001\u5165\u76f8\u5e94\u7684\u961f\u5217\u4e2d\uff0c\u6700\u540e\u4e3b\u7ebf\u7a0b\u4f1a\u4ece\u961f\u5217\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u9001\u5165GPU\u4e2d\u8fdb\u884c\u6a21\u578b\u8ba1\u7b97\uff1b
2\uff0cnumworkers\u4e3a0\u8868\u793a\u4e0d\u4f7f\u7528\u591a\u7ebf\u7a0b\uff0c\u4ec5\u4f7f\u7528\u4e3b\u7ebf\u7a0b\u8fdb\u884c\u6570\u636e\u52a0\u8f7d\u548c\u5904\u7406\u3002<\/p>\n<\/blockquote>\n

24\uff0c\u2013project<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--project'<\/span>,<\/span> default=<\/span>ROOT \/<\/span> 'runs\/train'<\/span>,<\/span> help<\/span>=<\/span>'save to project\/name'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bbe\u7f6e\u6bcf\u6b21\u8bad\u7ec3\u7ed3\u679c\u4fdd\u5b58\u7684\u4e3b\u8def\u5f84\u540d\u79f0
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --project \u2018runs\/train\u2019
\u6ce8\uff1a
1\uff0c\u8fd9\u91cc\u4e3b\u8def\u5f84\u7684\u610f\u601d\u662f\uff0c\u4f60\u6bcf\u6b21\u8bad\u7ec3\u4f1a\u751f\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u5b50\u6587\u4ef6\u5939\uff0c\u4e3b\u8def\u5f84\u5c31\u662f\u5b58\u653e\u4f60\u8fd9\u4e9b\u5355\u72ec\u5b50\u6587\u4ef6\u5939\u7684\u5730\u65b9\uff0c\u53ef\u4ee5\u81ea\u5df1\u547d\u540d\uff0c\u4f8b\u5982\u2019runs\/train\u2019\u3002\u6bd4\u5982\u8bf4\u4f60\u7b2c\u4e00\u6b21\u8bad\u7ec3\u4fdd\u5b58\u7ed3\u679c\u7684\u6587\u4ef6\u5939\u662fexp1\uff0c\u7b2c\u4e8c\u6b21\u662fexp2\uff0c\u7b2c\u4e09\u6b21\u662fexp3\uff0c\u5219\u8fd9\u4e9b\u5b50\u6587\u4ef6\u5939\u90fd\u4f1a\u653e\u5728\u4e3b\u8def\u5f84\u2019runs\/train\u2019\u4e0b\u9762\u3002<\/p>\n<\/blockquote>\n

25\uff0c\u2013name<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--name'<\/span>,<\/span> default=<\/span>'exp'<\/span>,<\/span> help<\/span>=<\/span>'save to project\/name'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bbe\u7f6e\u6bcf\u6b21\u8bad\u7ec3\u7ed3\u679c\u4fdd\u5b58\u7684\u5b50\u8def\u5f84\u540d\u79f0
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --name exp
1\uff0c\u8fd9\u91cc\u5b50\u8def\u5f84\u7684\u610f\u601d\u662f\u5c31\u662f\u4e0a\u9762\u5728\u2019\u2013project\u2019\u4e2d\u63d0\u5230\u7684\u6bcf\u6b21\u8bad\u7ec3\u751f\u6210\u7684\u5355\u72ec\u7684\u5b50\u6587\u4ef6\u5939\uff0c\u53ef\u4ee5\u81ea\u5df1\u547d\u540d\uff0c\u4f8b\u5982\u2019exp\u2019\u3002\u4f60\u6bcf\u6b21\u8bad\u7ec3\u751f\u6210\u7684\u6a21\u578b\u6743\u91cd\u6587\u4ef6\u3001\u53ef\u89c6\u5316\u7ed3\u679c\u4ee5\u53ca\u5176\u5b83\u7ed3\u679c\u6587\u4ef6\u4fdd\u5b58\u7684\u5730\u65b9\u3002<\/p>\n<\/blockquote>\n

26\uff0c\u2013exist-ok<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--exist-ok'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'existing project\/name ok, do not increment'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u662f\u5426\u8986\u76d6\u540c\u540d\u7684\u8bad\u7ec3\u7ed3\u679c\u4fdd\u5b58\u8def\u5f84\uff0c\u9ed8\u8ba4\u5173\u95ed\uff0c\u8868\u793a\u4e0d\u8986\u76d6
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --exist-ok
\u6ce8\uff1a
1\uff0c\u4e0d\u4f7f\u7528\u2019\u2013exist-ok\u2019\u53c2\u6570\u65f6\uff0c\u5982\u679c\u2019\u2013name\u2019\u6307\u5b9a\u7684\u540d\u79f0\u4e0d\u53d8\uff0c\u6bd4\u5982\u2019exp\u2019\uff0c\u6bcf\u6b21\u8bad\u7ec3\u4f1a\u6309\u987a\u5e8f\u65b0\u5efa\u6587\u4ef6\u5939\uff0c\u4f8b\u5982exp1\u3001exp2\u3001exp3\u3001\u2026 \u3001expn\uff1b
2\uff0c\u4f7f\u7528\u2019\u2013exist-ok\u2019\u53c2\u6570\u65f6\uff0c\u5982\u679c\u2019\u2013name\u2019\u6307\u5b9a\u7684\u540d\u79f0\u4e0d\u53d8\uff0c\u6bd4\u5982\u2019exp\u2019\uff0c\u6bcf\u6b21\u8bad\u7ec3\u5219\u4e0d\u4f1a\u65b0\u5efa\u6587\u4ef6\u5939\uff0c\u8bad\u7ec3\u7ed3\u679c\u4f1a\u8986\u76d6\u539f\u5148\u6587\u4ef6\u5939\u4e2d\u4fdd\u5b58\u7684\u6240\u6709\u7ed3\u679c\u3002<\/p>\n<\/blockquote>\n

27\uff0c\u2013quad<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--quad'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'quad dataloader'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u662f\u5426\u4f7f\u7528quad dataloader\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --quad
\u6ce8\uff1a
quad dataloader \u662f\u4e00\u79cd\u6570\u636e\u52a0\u8f7d\u5668\uff0c\u5b83\u53ef\u4ee5\u5e76\u884c\u5730\u4ece\u78c1\u76d8\u8bfb\u53d6\u548c\u5904\u7406\u591a\u4e2a\u56fe\u50cf\uff0c\u5e76\u5c06\u5b83\u4eec\u6253\u5305\u6210\u56db\u5f20\u56fe\u50cf\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u6570\u636e\u8bfb\u53d6\u548c\u9884\u5904\u7406\u7684\u65f6\u95f4\uff0c\u5e76\u63d0\u9ad8\u4e86\u6570\u636e\u52a0\u8f7d\u7684\u6548\u7387\u3002<\/p>\n<\/blockquote>\n

28\uff0c\u2013cos-lr<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--cos-lr'<\/span>,<\/span> action=<\/span>'store_true'<\/span>,<\/span> help<\/span>=<\/span>'cosine LR scheduler'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u5b66\u4e60\u7387\u8870\u51cf\u7b56\u7565\u4f7f\u7528\u4f59\u5f26\u9000\u706b\u7b56\u7565\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --cos-lr
\u6ce8\uff1a
1\uff0c\u4f59\u5f26\u9000\u706b\u7b56\u7565\u5728\u8bad\u7ec3\u521d\u671f\u52a0\u5feb\u5b66\u4e60\u901f\u5ea6\uff0c\u8bad\u7ec3\u540e\u671f\u51cf\u5c0f\u5b66\u4e60\u7387\uff0c\u4ece\u800c\u66f4\u597d\u5730\u5b66\u4e60\u6570\u636e\u7684\u5206\u5e03\uff0c\u907f\u514d\u6a21\u578b\u9677\u5165\u5c40\u90e8\u6700\u4f18\u3002<\/p>\n<\/blockquote>\n

29\uff0c\u2013label-smoothing<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--label-smoothing'<\/span>,<\/span> type<\/span>=<\/span>float<\/span>,<\/span> default=<\/span>0.0<\/span>,<\/span> help<\/span>=<\/span>'Label smoothing epsilon'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u4f7f\u7528\u6807\u7b7e\u5e73\u6ed1\u7b56\u7565\uff0c\u9632\u6b62\u8fc7\u62df\u5408
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --label-smoothing
\u6ce8\uff1a
1\uff0c\u9ed8\u8ba4\u4e3a0.0\uff0c\u5373\u6807\u7b7e\u5e73\u6ed1\u7b56\u7565\u4f7f\u7528\u7684epsilon\u4e3a0.0\uff1b
2\uff0c\u5c06\u6807\u7b7e\u5e73\u6ed1\u7b56\u7565\u4f7f\u7528\u7684epsilon\u8bbe\u7f6e\u4e3a0.1\uff1a
python train.py --label-smoothing 0.1
\u8868\u793a\u5728\u6bcf\u4e2a\u6807\u7b7e\u7684\u771f\u5b9e\u6982\u7387\u4e0a\u6dfb\u52a0\u4e00\u4e2a epsilon=0.1\u7684\u566a\u58f0\uff0c\u4ece\u800c\u4f7f\u6a21\u578b\u5bf9\u6807\u7b7e\u7684\u6ce2\u52a8\u66f4\u52a0\u9c81\u68d2\uff1b
3\uff0c\u2013label-smoothing \u53c2\u6570\u7684\u503c\u5e94\u8be5\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u96c6\u548c\u6a21\u578b\u6765\u8c03\u6574\uff0c\u4ee5\u8fbe\u5230\u6700\u4f18\u7684\u8bad\u7ec3\u6548\u679c\u3002<\/p>\n<\/blockquote>\n

30\uff0c\u2013patience<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--patience'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>100<\/span>,<\/span> help<\/span>=<\/span>'EarlyStopping patience (epochs without improvement)'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u4f7f\u7528EarlyStopping\u7b56\u7565\uff0c\u9632\u6b62\u8fc7\u62df\u5408
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --patience 100
\u6ce8\uff1a
1\uff0c\u2018\u2013patience\u2019\u53c2\u6570\u6307\u5b9a\u4e3a\u6574\u6570n\u65f6\uff0c\u8868\u793a\u6a21\u578b\u5728\u8bad\u7ec3\u65f6\uff0c\u82e5\u8fde\u7eedn\u4e2aepoch\u9a8c\u8bc1\u7cbe\u5ea6\u90fd\u6ca1\u6709\u63d0\u5347\uff0c\u5219\u8ba4\u4e3a\u8bad\u7ec3\u5df2\u7ecf\u8fc7\u62df\u5408\uff0c\u505c\u6b62\u8bad\u7ec3\u3002\u2019\u2013patience\u2019\u53ef\u6839\u636e\u5177\u4f53\u7684\u6a21\u578b\u548c\u6570\u636e\u96c6\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/blockquote>\n

31\uff0c\u2013freeze<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--freeze'<\/span>,<\/span> nargs=<\/span>'+'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>[<\/span>0<\/span>]<\/span>,<\/span> help<\/span>=<\/span>'Freeze layers: backbone=10, first3=0 1 2'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bad\u7ec3\u4f7f\u7528\u51bb\u7ed3\u8bad\u7ec3\u7b56\u7565\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --freeze
\u6ce8\uff1a
1\uff0c\u51bb\u7ed3\u8bad\u7ec3\u662f\u6307\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u51bb\u7ed3\u6a21\u578b\u4e2d\u7684\u67d0\u4e9b\u5c42\uff0c\u51bb\u7ed3\u7684\u5c42\u4e0d\u8fdb\u884c\u6743\u91cd\u53c2\u6570\u66f4\u65b0\uff1b
2\uff0c\u6307\u5b9a\u20190\u2019\u6216\u2019-1\u2019\uff0c\u4e0d\u51bb\u7ed3\u4efb\u4f55\u5c42\uff0c\u66f4\u65b0\u6240\u6709\u5c42\u7684\u6743\u91cd\u53c2\u6570\uff1a
python train.py --freeze 0\/-1
3\uff0c\u6307\u5b9an\uff0c\u51bb\u7ed3\u524dn(0<n<=10)\u5c42\uff0c\u5373\u53ea\u66f4\u65b0\u524dn\u5c42\u7684\u6743\u91cd\u53c2\u6570\uff1a
python train.py --freeze n<\/p>\n<\/blockquote>\n

32\uff0c\u2013save-period<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--save-period'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>-<\/span>1<\/span>,<\/span> help<\/span>=<\/span>'Save checkpoint every x epochs (disabled if < 1)'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u6bcf\u8bad\u7ec3n\u4e2aepoch\u4fdd\u5b58\u4e00\u6b21\u8bad\u7ec3\u6743\u91cd\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --save-period n
\u6ce8\uff1a
1\uff0cn>0\uff0c\u6bcf\u8bad\u7ec3n\u4e2aepoch\u4fdd\u5b58\u4e00\u6b21\u8bad\u7ec3\u6743\u91cd\uff1b
2\uff0cn<=0\uff0c\u5173\u95edsave-period\uff0c\u53ea\u4fdd\u5b58best\u548clast\u6743\u91cd\u3002<\/p>\n<\/blockquote>\n

33\uff0c\u2013seed<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--seed'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>0<\/span>,<\/span> help<\/span>=<\/span>'Global training seed'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u8bbe\u7f6e\u8bad\u7ec3\u4f7f\u7528\u7684\u5168\u5c40\u968f\u673a\u79cd\u5b50
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --seed n
\u6ce8\uff1a
1\uff0c\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u6709\u5f88\u591a\u5730\u65b9\u4f1a\u4f7f\u7528\u5230\u968f\u673a\u79cd\u5b50\uff0c\u4f8b\u5982\u6570\u636e\u52a0\u8f7d\u548c\u5904\u7406\u9636\u6bb5\u6216\u6a21\u578b\u521d\u59cb\u5316\u9636\u6bb5\uff0c\u968f\u673a\u79cd\u5b50\u53ef\u4ee5\u4fdd\u8bc1\u6bcf\u6b21\u751f\u6210\u7684\u7ed3\u679c\u90fd\u4e00\u81f4\uff0c\u4ece\u800c\u6709\u5229\u4e8e\u4ee3\u7801\u7684\u53ef\u590d\u73b0\u6027\u3002<\/p>\n<\/blockquote>\n

34\uff0c\u2014local_rank<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--local_rank'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>-<\/span>1<\/span>,<\/span> help<\/span>=<\/span>'Automatic DDP Multi-GPU argument, do not modify'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u662f\u5426\u4f7f\u7528\u5206\u5e03\u5f0f\u8bad\u7ec3\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --local_rank 0,1,2,3
\u6ce8\uff1a
1\uff0c\u5982\u679c\u4f60\u6709 4 \u4e2a GPU\uff0c\u60f3\u8981\u4f7f\u7528\u7b2c 2 \u53f7\u548c\u7b2c 3 \u53f7 GPU \u8fdb\u884c\u8bad\u7ec3\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u542f\u52a8\u8bad\u7ec3\u811a\u672c\u65f6\u8bbe\u7f6e\u5982\u4e0b\u53c2\u6570\uff1a
python train.py --local_rank 1,2
\u8fd9\u6837\uff0c\u7b2c\u4e00\u4e2a\u8fdb\u7a0b\u5c06\u4f7f\u7528\u7b2c 2 \u53f7 GPU\uff0c\u7b2c\u4e8c\u4e2a\u8fdb\u7a0b\u5c06\u4f7f\u7528\u7b2c 3 \u53f7 GPU\u3002\u6ce8\u610f\uff0c\u5982\u679c\u4f7f\u7528\u4e86 --local_rank \u53c2\u6570\uff0c\u90a3\u4e48\u5728\u542f\u52a8\u8bad\u7ec3\u811a\u672c\u65f6\u9700\u8981\u4f7f\u7528 PyTorch \u7684\u5206\u5e03\u5f0f\u8bad\u7ec3\u5de5\u5177\uff0c\u4f8b\u5982 torch.distributed.launch\u3002<\/p>\n<\/blockquote>\n

35\uff0c\u2013entity<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--entity'<\/span>,<\/span> default=<\/span>None<\/span>,<\/span> help<\/span>=<\/span>'Entity'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u7528\u4e8e\u6307\u5b9a\u6a21\u578b\u5b9e\u4f53\u7684\u53c2\u6570
\u547d\u4ee4\u884c\u7528\u6cd5\uff1apython train.py --entity None
\u6ce8\uff1a
1\uff0c\u6a21\u578b\u5b9e\u4f53\u53ef\u4ee5\u662f\u4e00\u4e2a\u5b9e\u4f53\u540d\u79f0\u6216\u5b9e\u4f53 ID\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u5b9e\u4f53\u5b58\u50a8\u5e93\u4e2d\u7ba1\u7406\u6a21\u578b\u7684\u7248\u672c\u63a7\u5236\u548c\u8bb0\u5f55\u3002
\u5728\u4f7f\u7528\u5b9e\u4f53\u5b58\u50a8\u5e93\u65f6\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f53\u6765\u5b58\u50a8\u6a21\u578b\uff0c\u5e76\u5728\u8bad\u7ec3\u65f6\u6307\u5b9a\u8be5\u5b9e\u4f53\uff0c\u8fd9\u6837\u8bad\u7ec3\u7ed3\u679c\u5c31\u53ef\u4ee5\u4e0e\u8be5\u5b9e\u4f53\u76f8\u5173\u8054\u5e76\u4fdd\u5b58\u5230\u5b9e\u4f53\u5b58\u50a8\u5e93\u4e2d\u3002
\u8be5\u53c2\u6570\u9ed8\u8ba4\u503c\u4e3a None\uff0c\u5982\u679c\u672a\u6307\u5b9a\u5b9e\u4f53\uff0c\u5219\u8bad\u7ec3\u7ed3\u679c\u5c06\u4e0d\u4f1a\u4e0e\u4efb\u4f55\u5b9e\u4f53\u76f8\u5173\u8054\u3002<\/p>\n<\/blockquote>\n

36\uff0c\u2013upload_dataset<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--upload_dataset'<\/span>,<\/span> nargs=<\/span>'?'<\/span>,<\/span> const=<\/span>True<\/span>,<\/span> default=<\/span>False<\/span>,<\/span> help<\/span>=<\/span>'Upload data, \"val\" option'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u7528\u4e8e\u4e0a\u4f20\u6570\u636e\u96c6\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u4f7f\u7528\u65b9\u6cd5\uff1apython train.py --upload_dataset False
\u6ce8\uff1a
1\uff0c\u5982\u679c\u547d\u4ee4\u884c\u672a\u4f7f\u7528\u2019\u2013upload_dataset\u2019\u53c2\u6570\uff0c\u5219\u9ed8\u8ba4\u503c\u4e3adefault=False\uff0c\u8868\u793a\u4e0d\u4e0a\u4f20\u6570\u636e\u96c6\u3002
2\uff0c\u5982\u679c\u547d\u4ee4\u884c\u4f7f\u7528\u2019\u2013upload_dataset\u2019\u53c2\u6570\uff0c\u4f46\u6ca1\u6709\u4f20\u9012\u53c2\u6570\uff0c\u5219\u9ed8\u8ba4\u503c\u4e3aconst=True\uff0c\u8868\u793a\u4e0a\u4f20\u6570\u636e\u96c6\u3002
3\uff0c\u5982\u679c\u547d\u4ee4\u884c\u4f7f\u7528\u2019\u2013upload_dataset\u2019\u53c2\u6570\uff0c\u5e76\u4e14\u4f20\u9012\u4e86\u53c2\u6570\u2019val\u2019\uff0c\u5219\u9ed8\u8ba4\u4e3aTrue\uff0c\u8868\u793a\u8981\u4e0a\u4f20val\u6570\u636e\u96c6\u3002<\/p>\n<\/blockquote>\n

37\uff0c\u2013bbox_interval<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--bbox_interval'<\/span>,<\/span> type<\/span>=<\/span>int<\/span>,<\/span> default=<\/span>-<\/span>1<\/span>,<\/span> help<\/span>=<\/span>'Set bounding-box image logging interval'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a \u6307\u5b9a\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6bcf\u9694\u591a\u5c11\u4e2aepoch\u8bb0\u5f55\u4e00\u6b21\u5e26\u6709\u8fb9\u754c\u6846\u7684\u56fe\u7247\uff0c\u9ed8\u8ba4\u5173\u95ed
\u547d\u4ee4\u884c\u4f7f\u7528\u65b9\u6cd5\uff1apython train.py --bbox_interval n
\u6ce8\uff1a
1\uff0cn>0\uff0c\u6bcf\u9694n\u4e2aepoch\u8bb0\u5f55\u4e00\u6b21\u5e26\u6709\u8fb9\u754c\u6846\u7684\u56fe\u7247\uff1b
2\uff0cn<=0\uff0c\u5173\u95ed\u2013bbox_interval\u3002<\/p>\n<\/blockquote>\n

38\uff0c\u2013artifact_alias<\/strong><\/em><\/h3>\n
parser.<\/span>add_argument(<\/span>'--artifact_alias'<\/span>,<\/span> type<\/span>=<\/span>str<\/span>,<\/span> default=<\/span>'latest'<\/span>,<\/span> help<\/span>=<\/span>'Version of dataset artifact to use'<\/span>)<\/span>\n<\/code><\/pre>\n
\n

\u89e3\u6790\uff1a\u7528\u4e8e\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u6570\u636e\u96c6\u5de5\u4ef6\u7684\u7248\u672c\u522b\u540d\u3002
\u547d\u4ee4\u884c\u4f7f\u7528\u65b9\u6cd5\uff1apython train.py --artifact_alias latest
\u6ce8\uff1a
1\uff0c\u5728\u4f7f\u7528MLFlow\u7b49\u5de5\u5177\u8ddf\u8e2a\u6a21\u578b\u8bad\u7ec3\u548c\u6570\u636e\u96c6\u7248\u672c\u65f6\uff0c\u4f1a\u7ed9\u6bcf\u4e2a\u7248\u672c\u5206\u914d\u552f\u4e00\u7684\u522b\u540d\u3002\u901a\u8fc7\u6307\u5b9a\u6b64\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u7279\u5b9a\u7248\u672c\u7684\u6570\u636e\u96c6\u5de5\u4ef6\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684\u6570\u636e\u96c6\u5de5\u4ef6\u3002<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"YOLOV5\u8bad\u7ec3\u4ee3\u7801train.py\u8bad\u7ec3\u53c2\u6570\u89e3\u6790yolov5\u9879\u76ee\u4ee3\u7801\u4e2d\uff0ctrain.py\u662f\u7528\u4e8e\u6a21\u578b\u8bad\u7ec3\u7684\u4ee3\u7801\uff0c\u662fyolov5\u4e2d\u6700\u4e3a\u6838\u5fc3\u7684\u4ee3\u7801\u4e4b\u4e00\uff0c\u800c\u4ee3...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8945"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8945"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8945\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}