Paddle记录

SOLOV2-Paddle版本

  • 前言
  • 一、solov2
  • 二、执行步骤
    • 1.构建数据集
    • 2.编写配置文件
    • 3.train
    • 4. export model
    • 4. deploy
  • 总结

前言

运行 PaddleDetection 版本的 solov2

一、solov2

深度学习示例分割模型,据说是很牛的存在:
Paddle记录_第1张图片

二、执行步骤

1.构建数据集

本人对标注工具并没有太多考究,目前使用的是商汤的 labelBee,在使用中感觉挺轻便的,所以就一直用着了,至于输出标注文件格式比较少,也是可以接受的,大不了在用 py 写一系列的脚本即可;
个人新建的项目如下图所示:
在这里插入图片描述
标注完需要把标注信息输出出来,选择 export 后弹出此窗口,选择比较通用的 coco即可;
Paddle记录_第2张图片
保存的 json 文件内容如下:

{
	"images": [{
		"id": 1,
		"file_name": "Image_20220901173946580.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 2,
		"file_name": "Image_20220901173949223.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 3,
		"file_name": "Image_20220901173951791.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 4,
		"file_name": "Image_20220901173954161.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 5,
		"file_name": "Image_20220901173956628.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 6,
		"file_name": "Image_20220901173959288.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 7,
		"file_name": "Image_20220901174002199.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}, {
		"id": 8,
		"file_name": "Image_20220901174005226.jpg",
		"width": 1280,
		"height": 1024,
		"valid": true,
		"rotate": 0
	}],
	"annotations": [{
		"image_id": 1,
		"id": 1,
		"iscrowd": 0,
		"segmentation": [
			[775.1696145306619, 363.8866676565172, 773.6952904225192, 375.0260053624842, 778.1182627469473, 385.51008790927676, 792.0424348794061, 396.6494256152438, 808.0961862791821, 375.8450743114524, 807.6047449098012, 373.06023988496065, 800.560751948675, 366.0162469238344, 788.6023452937397, 360.77420565043815, 781.5583523326136, 361.2656470198191]
		],
		"area": 791.2958159616683,
		"bbox": [773.6952904225192, 360.77420565043815, 34.40089585666294, 35.87521996480564],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 1,
		"id": 2,
		"iscrowd": 0,
		"segmentation": [
			[669.6773496982897, 250.4618896877355, 664.1925495459341, 255.45915204877056, 662.3642828284823, 259.3594543793345, 663.4612428589534, 264.72237008385997, 669.5554652504595, 269.96340134055527, 671.871269759232, 272.88862808847824, 675.0402654028152, 267.5257123839528, 682.718985616113, 263.9910633968792, 689.1788613511095, 262.8941033664081, 720.0156266521307, 265.5755612186708, 722.9408534000537, 265.0880234273503, 720.6250488912814, 262.2846811272575, 698.0764260427085, 254.72784536178983, 692.4697414425228, 254.97161425745006, 690.3977058294107, 255.94668984009107, 687.1068257379974, 254.84972980961993, 684.791021229225, 252.53392530084759, 672.9682297897031, 249.24304520943426]
		],
		"area": 596.0822943327657,
		"bbox": [662.3642828284823, 249.24304520943426, 60.57657057157144, 23.645582879043985],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 1,
		"id": 3,
		"iscrowd": 0,
		"segmentation": [
			[503.93492630565015, 326.4228631458599, 496.5372035581461, 321.64140819930236, 489.9514259902461, 319.927301709027, 484.44824199515165, 319.927301709027, 476.6896547233791, 318.5740597430202, 484.719599864196, 312.8676979939832, 486.67533197890083, 309.8452029076212, 480.98592946339596, 302.55565593463064, 474.2297639762339, 300.95551147714485, 465.5178663743671, 302.55565593463064, 463.02875277383373, 307.8894707929164, 464.62889723131946, 314.1122547942499, 467.1180108318528, 319.0904819953166, 470.1405059182148, 321.7573894244596, 461.2508144877384, 327.2689981113549, 463.7399280882718, 328.86914256884063, 494.6760542663295, 331.8916376552026, 497.876343181301, 330.2914931977169]
		],
		"area": 683.0974664611858,
		"bbox": [461.2508144877384, 300.95551147714485, 42.68411181791174, 30.936126178057748],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 1,
		"id": 4,
		"iscrowd": 0,
		"segmentation": [
			[585.2602140537407, 737.8277126521664, 598.3476755179211, 736.5057468477038, 610.6419574994239, 739.0174818761828, 616.3264104586134, 745.2307211571574, 622.2752565786953, 750.1219946336693, 624.5225984462819, 758.0537894604453, 626.7699403138685, 766.7787637698988, 631.6612137903803, 770.7446611832868, 638.932025714925, 771.2734475050719, 640.1217949389413, 775.6359346597987, 629.4138719227938, 775.3715414989061, 624.6547950267282, 773.6529859531047, 616.0620172977208, 773.1241996313196, 595.5715473285495, 773.9173791139972, 577.3284192269647, 769.9514817006092, 567.6780688543872, 768.1007295743615, 568.2068551761723, 760.1689347475855, 573.7591115549155, 754.3522852079498, 580.5011371576751, 749.064421990099, 581.2943166403527, 744.1731485135872, 582.2196927034765, 739.0174818761828]
		],
		"area": 1710.2824650611728,
		"bbox": [567.6780688543872, 736.5057468477038, 72.4437260845541, 39.13018781209496],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 2,
		"id": 5,
		"iscrowd": 0,
		"segmentation": [
			[790.1649127414297, 397.27847011251515, 791.4571821212638, 391.9658071065306, 809.4053679522929, 376.171403575225, 806.6772437059765, 373.73045030220504, 801.0774097266955, 366.69476145644165, 795.7647467207108, 361.95644039705, 792.4622805278015, 359.0847306640853, 784.0711559775343, 359.9357158631965, 776.1353525690278, 360.8375117050722, 772.8888875382752, 366.0679275879515, 774.6924792220267, 374.0037309964579, 777.5782259160289, 377.97163270071115, 778.2996625895296, 385.36635860409217, 777.5782259160289, 390.5967744869714, 782.447923462158, 394.7450353595998, 784.2515151459095, 400.8772470843548]
		],
		"area": 861.9439427285688,
		"bbox": [772.8888875382752, 359.0847306640853, 36.51648041401768, 41.792516420269465],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 2,
		"id": 6,
		"iscrowd": 0,
		"segmentation": [
			[669.9009736171545, 249.1985627344673, 663.4291259963011, 253.85020321195566, 662.4178998055428, 261.1310317854157, 666.8672950448795, 265.17593654844904, 669.6987283790029, 269.4230865496341, 673.7436331420362, 267.4006341681174, 681.6311974299513, 262.54674845247735, 688.507535527108, 261.53552226171905, 698.4175521965398, 262.9512389287807, 707.7208331515164, 262.54674845247735, 718.8443212498581, 264.3669555958424, 720.8667736313748, 263.1534841669324, 719.2488117261615, 260.92878654726405, 700.2377593399048, 254.0524484501073, 690.327742670473, 254.25469368825898, 685.6761021929847, 251.42326035413564, 674.3503688564912, 248.5918270200123]
		],
		"area": 571.4781695842248,
		"bbox": [662.4178998055428, 248.5918270200123, 58.44887382583204, 20.831259529621803],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 2,
		"id": 7,
		"iscrowd": 0,
		"segmentation": [
			[461.5600886941825, 306.8152242483181, 459.3314662759241, 311.4581876196899, 462.86011843816664, 317.029743665336, 469.9174227626517, 318.88692901388475, 504.6467887805126, 326.87282601264417, 505.9468185244967, 324.6442035943857, 503.7181961062382, 322.41558117612726, 500.56098101370543, 316.84402513048116, 496.846610316608, 312.2010617591094, 477.7176012265563, 303.47229062093044, 470.84601543692605, 302.5436979466561, 468.43167448381274, 298.27217164499405, 463.788711112441, 301.6151052723817]
		],
		"area": 635.6760262965981,
		"bbox": [459.3314662759241, 298.27217164499405, 46.615352248572606, 28.600654367650122],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 2,
		"id": 8,
		"iscrowd": 0,
		"segmentation": [
			[464.60074438758323, 323.2467903399151, 462.57612764536805, 325.48452463394244, 462.7892451971802, 327.61570015206365, 472.59265258053784, 328.0419352556879, 481.54358975664707, 330.4927871015273, 486.55185222423194, 330.8124634292455, 491.66667346772294, 331.55837486058795, 493.79784898584415, 330.5993458774334, 492.3060261231593, 328.8944054629364, 486.23217589651375, 325.69764218575455, 480.37144322168035, 324.6320544266939, 471.7401823732894, 322.3943201326666, 467.90406644067116, 322.3943201326666]
		],
		"area": 148.4806855070783,
		"bbox": [462.57612764536805, 322.3943201326666, 31.22172134047611, 9.164054727921325],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 2,
		"id": 9,
		"iscrowd": 0,
		"segmentation": [
			[573.997912995301, 764.605798627305, 582.4047161569741, 768.6924390531184, 592.5629366439958, 771.0276621535832, 605.6401860065986, 771.4947067736761, 614.3972726333415, 770.7941398435366, 627.1242385308743, 772.5455571688852, 636.8154143978031, 776.3986752846521, 639.0338763432446, 774.2969744942337, 632.0282070418504, 769.1594836732113, 622.2202700198984, 761.686769751724, 622.3370311749217, 756.1989954656318, 621.2861807797125, 749.3100873192608, 602.6043959759944, 746.1575361336334, 589.7606689234382, 753.5134889000974, 582.2879550019509, 760.5191582014917]
		],
		"area": 956.632534426346,
		"bbox": [573.997912995301, 746.1575361336334, 65.0359633479436, 30.24113915101873],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 3,
		"id": 10,
		"iscrowd": 0,
		"segmentation": [
			[466.14483191859074, 299.4632778923709, 463.52381128189256, 307.4901535922589, 458.93702516767087, 308.9644777004016, 461.88567338395626, 316.4999120309087, 466.8000870777652, 321.74195330430496, 485.1472315346521, 325.3458566797649, 504.14963115071356, 328.45831868584395, 505.46014146906265, 327.14780836749486, 503.1667484119518, 323.3800912022413, 491.69978312639745, 311.913125916687, 480.5604454204304, 306.34345706370345, 474.66314898785964, 303.5586226372117, 471.71450077157425, 302.24811231886264]
		],
		"area": 659.7642706650367,
		"bbox": [458.93702516767087, 299.4632778923709, 46.52311630139178, 28.995040793473038],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 3,
		"id": 11,
		"iscrowd": 0,
		"segmentation": [
			[463.63704198108957, 324.38868558555873, 462.9836390535382, 327.2636584667849, 464.3557852013961, 328.1784225653568, 472.52332179578855, 328.3091031508671, 480.9522195612016, 331.4454372031138, 484.67661624824456, 331.3147566176035, 489.1197561555941, 333.7976877422988, 492.77881254988193, 336.6073203307699, 496.56854952968, 335.95391740321844, 494.6083407470258, 331.3147566176035, 491.34132610926883, 327.91706139433626, 483.8925327351829, 326.74093612474377, 474.81023204221844, 324.45402587831387, 469.2563071580316, 324.45402587831387]
		],
		"area": 159.71866247954313,
		"bbox": [462.9836390535382, 324.38868558555873, 33.58491047614183, 12.218634745211148],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 3,
		"id": 12,
		"iscrowd": 0,
		"segmentation": [
			[668.489214045119, 250.58743469796508, 663.3756256982001, 255.11099362023947, 662.9822727484371, 261.79799376621025, 665.1457139721335, 270.64843513587755, 668.489214045119, 275.17199405815194, 674.7828612413268, 273.99193520886297, 675.9629200906157, 266.71490563824767, 686.1900967844534, 263.56808204014374, 704.1665138702165, 262.89672694928583, 708.9230374898773, 264.6901702812891, 720.6194070464204, 265.0800492665072, 720.1515522641587, 263.5205333256348, 718.2021573380682, 261.7270899936315, 699.72189343873, 254.63129246266203, 693.0159748929786, 254.8652198537929, 690.67670098167, 256.26878420057807, 684.0487582329623, 251.43428478387358, 670.948824329634, 248.62715609030323]
		],
		"area": 652.6866639086657,
		"bbox": [662.9822727484371, 248.62715609030323, 57.637134297983266, 26.544837967848707],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 3,
		"id": 13,
		"iscrowd": 0,
		"segmentation": [
			[790.2604354740879, 397.569985406125, 808.4547332051553, 377.6310289885168, 809.0778255932056, 373.64323770499516, 803.9684680111935, 366.2907475260021, 795.7436484889301, 358.31516495895886, 788.0782119901663, 351.49941943161787, 779.3820189668326, 357.25605424988106, 776.0750159861282, 362.7677258843883, 773.9928289242032, 371.7088820914779, 779.0145741911988, 380.65003829856744, 776.9323871292738, 384.6919308305395, 786.1185065201192, 391.55089997570406]
		],
		"area": 950.3856605187466,
		"bbox": [773.9928289242032, 351.49941943161787, 35.08499666900241, 46.07056597450713],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 3,
		"id": 14,
		"iscrowd": 0,
		"segmentation": [
			[575.8633709490001, 765.1815133967672, 583.9380724518356, 760.3030479054706, 590.162321526938, 753.9105758823927, 599.7510295615551, 749.8732251309749, 604.4612721048758, 749.5367792350233, 608.4986228562935, 741.7985236281394, 597.0594623939432, 739.1069564605276, 602.4425967291669, 735.0696057091099, 612.8724195036627, 742.639638368018, 617.4144390990077, 753.4059070384654, 621.6200127984011, 759.1254872696405, 623.3022422781586, 762.8263921251067, 637.2647469601449, 774.0973296394812, 633.7320650526543, 777.6300115469718, 628.3489307174307, 776.9571197550689, 624.311579966013, 772.4151001597239, 615.3957637232988, 774.7702214313842, 600.423921353458, 774.7702214313842, 584.7791871917143, 771.2375395238937]
		],
		"area": 1077.9498434353154,
		"bbox": [575.8633709490001, 735.0696057091099, 61.40137601114475, 42.560405837861936],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 4,
		"id": 15,
		"iscrowd": 0,
		"segmentation": [
			[789.7751460855326, 397.4110535037531, 808.3357433813499, 375.888658767114, 805.373945940528, 370.75487653635605, 795.8961941298978, 362.6592968647762, 788.1955207837609, 360.09240574939724, 784.4439106920531, 362.0669373766118, 782.0744727393957, 365.6210943055981, 775.1636120441445, 367.20071960736976, 772.9916272542085, 371.5446891872419, 776.1508778577519, 381.02244099787197, 776.7432373459162, 386.5511295540729, 782.0744727393957, 391.2900054593879]
		],
		"area": 787.4356164135097,
		"bbox": [772.9916272542085, 360.09240574939724, 35.34411612714132, 37.31864775435588],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 4,
		"id": 16,
		"iscrowd": 0,
		"segmentation": [
			[669.3287658659709, 249.9778299046531, 664.5580535669442, 255.10634562610687, 662.4112330323821, 259.39998669523095, 664.0809823370414, 264.5285024166847, 667.0626775239332, 269.41848252318715, 668.2553555986899, 270.84969621289514, 676.9619055444136, 267.0331263736737, 688.0538116396509, 263.81289557183067, 694.852076665764, 262.3816818821227, 707.3985176349237, 263.2536374080494, 712.4912937508335, 264.7515127362582, 720.093011041493, 264.8638533858739, 719.4938609102095, 262.13023091189285, 715.8615132393032, 260.2578867516319, 698.7064932996018, 255.0281037258912, 692.5411258977205, 254.22073418516865, 690.3392089684771, 255.54188434271467, 687.1097308055869, 254.7345148019921, 684.1738415665957, 250.84446156032885, 671.4396438362388, 248.24546699512078]
		],
		"area": 600.3810261968756,
		"bbox": [662.4112330323821, 248.24546699512078, 57.68177800911087, 22.60422921777436],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 4,
		"id": 17,
		"iscrowd": 0,
		"segmentation": [
			[481.197241956005, 317.17237098146103, 487.42149103110734, 311.11634485433444, 483.8888091236168, 306.57432525898946, 481.8701337479079, 299.84540733995993, 470.9356421294849, 300.1818532359114, 462.18804883474644, 304.55564988328064, 457.30958334345, 310.10700716648, 458.8235898752317, 315.3219185537279, 464.87961600235826, 317.5088168774125, 476.31877646470855, 324.91062658834505, 502.0568875049966, 329.9573150276172, 505.25312351653565, 332.8171051432048, 505.08490056855993, 328.1068625998841, 500.71110392119067, 323.9012889004906, 490.4495040946706, 321.3779446808545, 482.37480259183513, 318.51815456526697]
		],
		"area": 628.109571688401,
		"bbox": [457.30958334345, 299.84540733995993, 47.94354017308564, 32.971697803244865],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 4,
		"id": 18,
		"iscrowd": 0,
		"segmentation": [
			[462.3715476512173, 323.8596338277956, 459.0784074771016, 326.28106042641014, 460.82183462810406, 327.63705932163424, 470.507541022562, 328.89620115291376, 479.12781971362955, 330.44591417602703, 484.0675299748031, 331.3176277515283, 488.716669044143, 333.0610549025307, 492.10666628220326, 331.8987701351957, 491.62238096248035, 328.89620115291376, 482.13038869591156, 326.4747745542993, 473.2195388130102, 325.4093468509089, 466.82697259266797, 324.24706208357395]
		],
		"area": 131.74146720944555,
		"bbox": [459.0784074771016, 323.8596338277956, 33.02825880510164, 9.201421074735094],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 4,
		"id": 19,
		"iscrowd": 0,
		"segmentation": [
			[616.2918493316163, 774.965148669586, 624.7861493339864, 773.3471867643727, 633.8871850508115, 775.7741296221927, 639.7522969572098, 776.5831105747994, 632.4714683837498, 769.9090177157943, 629.4377898114748, 764.4483962856993, 627.6175826681097, 755.549605807026, 624.988394572138, 752.7181724729026, 622.561451714318, 748.2687772335659, 613.460415997493, 739.5722319930442, 609.0110207581563, 735.3250819918592, 602.9436636136062, 733.3026296103425, 585.7528183707144, 740.9879486601059, 573.820349319766, 753.9316439018125, 573.4158588434626, 758.7855296174527, 574.427085034221, 766.0663581909126, 574.8315755105243, 774.1561677169794, 580.6966874169227, 774.965148669586, 583.1236302747427, 770.5157534302493, 589.7977231337478, 771.931470097311, 607.9997945673979, 774.358412955131, 607.9997945673979, 774.358412955131]
		],
		"area": 1773.0691547176102,
		"bbox": [573.4158588434626, 733.3026296103425, 66.33643811374714, 43.280480964456956],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 5,
		"id": 20,
		"iscrowd": 0,
		"segmentation": [
			[670.6178454403985, 249.25630871532084, 664.671824164791, 256.86721594809825, 662.7690973565967, 263.52675977677853, 667.2880735260583, 272.32687126467744, 674.6611399078115, 267.8078950952158, 683.9369330977589, 264.0024414788271, 696.662353355745, 262.26978759464316, 704.5795643061196, 262.9861066806294, 717.8920654450909, 263.51271725604, 719.2005381970177, 263.1278723290027, 718.3923638502393, 261.43455465003854, 716.006325302608, 260.97274073759377, 700.1827291531637, 254.37797299243707, 697.0422911581575, 254.83595353337546, 693.7055757884634, 254.4433987839997, 690.3034346272068, 255.22850828275122, 688.7986414212663, 256.2753209477533, 684.4151133865702, 251.30296078899352]
		],
		"area": 566.2127751247899,
		"bbox": [662.7690973565967, 249.25630871532084, 56.43144084042103, 23.070562549356595],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 5,
		"id": 21,
		"iscrowd": 0,
		"segmentation": [
			[461.70042044452293, 307.1201342519874, 463.10010004911345, 312.85882063080845, 468.6988184674755, 316.91789148412096, 475.557248529969, 318.3175710887115, 481.99577471108535, 320.2771225351382, 486.7546853666931, 321.9567380606468, 494.4529231919409, 321.9567380606468, 501.59128917535253, 326.2957448348774, 505.3704241077469, 325.7358729930412, 502.57106489856585, 317.05785944458, 495.8526027965314, 312.29894878897227, 487.3145572085293, 308.65978181703696, 483.67539023659396, 304.1808070823473, 477.2368640554776, 300.1217362290348, 470.6583699139022, 302.5011915568387, 467.43910682334405, 305.58048668693783]
		],
		"area": 539.1941219383152,
		"bbox": [461.70042044452293, 300.1217362290348, 43.67000366322395, 26.174008605842573],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 5,
		"id": 22,
		"iscrowd": 0,
		"segmentation": [
			[464.6228936557412, 323.00431409931747, 465.78517842307616, 327.266024912879, 471.79031638764013, 327.6534531686573, 481.3791657181535, 329.20316619177055, 489.80573028133193, 331.3340215985513, 496.7794388853416, 334.2397335168887, 498.7165801642332, 334.3365905808333, 497.65115246084287, 329.00945206388144, 495.81086824589585, 325.91002601765484, 491.54915743233437, 324.94145537820907, 483.6068781888788, 323.3917423550958, 475.4708848175341, 322.8105999714283, 469.07831859719187, 321.64831520409336]
		],
		"area": 202.73438561063085,
		"bbox": [464.6228936557412, 321.64831520409336, 34.093686508492, 12.68827537673991],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 5,
		"id": 23,
		"iscrowd": 0,
		"segmentation": [
			[790.340436829957, 397.34001182817764, 793.4197319600561, 392.0212293307337, 808.6762396500927, 374.2452983524342, 807.9763998477974, 372.2857469060075, 804.057296954944, 367.80677217131785, 794.9593795251056, 361.78814987157864, 788.3808853835303, 360.10853434607003, 784.4617824906768, 360.3884702669881, 782.362263083791, 362.767925594792, 779.8428397955281, 366.96696440856357, 778.3031922304785, 368.36664401315403, 775.5038330212975, 372.42571486646654, 775.2238971003794, 378.44433716620574, 777.0434805863471, 382.6433759799773, 778.8630640723148, 385.1627992682402, 780.5426795978234, 387.6822225565031, 783.3420388070044, 390.6215497261432, 785.5815261743493, 392.861037093488]
		],
		"area": 744.3905696877046,
		"bbox": [775.2238971003794, 360.10853434607003, 33.45234254971331, 37.23147748210761],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 5,
		"id": 24,
		"iscrowd": 0,
		"segmentation": [
			[605.1834801843455, 746.4703080961092, 589.3013017795765, 752.2247205616052, 582.3960068209814, 758.8998390215805, 577.3321238513449, 762.582662999498, 576.8717708541052, 771.7897229442916, 580.094241834783, 774.5518409277297, 585.3883013030393, 770.6388404511924, 593.6746552533535, 773.6311349332503, 607.7154216691638, 773.6311349332503, 616.6923051153375, 773.4009584346305, 624.2881295697922, 772.9406054373908, 629.5821890380486, 777.5441354097876, 641.7815434649001, 779.3855473987463, 641.7815434649001, 774.5518409277297, 632.8046600187263, 770.1784874539527, 629.121836040809, 767.8767224677543, 627.51060055047, 758.6696625229607, 621.9863645835939, 749.0022495809275, 615.5414226222383, 741.8667781237124, 609.7870101567423, 736.8028951540759, 606.5645391760646, 737.7236011485553]
		],
		"area": 1316.4773674036842,
		"bbox": [576.8717708541052, 736.8028951540759, 64.9097726107949, 42.582652244670385],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 5,
		"id": 25,
		"iscrowd": 0,
		"segmentation": [
			[630.4103120447119, 781.0709277506859, 629.8016921082484, 794.5366438449387, 643.495640678675, 794.232333876707, 647.9081352180348, 788.5265219723626, 646.3105078848183, 786.9288946391462, 640.528618488416, 781.6795476871492, 634.0620316634922, 780.842695274512]
		],
		"area": 193.5608869935968,
		"bbox": [629.8016921082484, 780.842695274512, 18.10644310978637, 13.693948570426642],
		"category_id": 0,
		"order": 6
	}, {
		"image_id": 6,
		"id": 26,
		"iscrowd": 0,
		"segmentation": [
			[579.0405900366162, 741.6445476299557, 589.0296454732091, 736.7718376608859, 599.5059719067091, 736.7718376608859, 608.7641208479415, 737.2591086577929, 622.1640732628832, 749.6845190789207, 628.0113252257669, 766.4953684722112, 633.614941690197, 772.0989849366414, 637.5131096654528, 774.7789754196297, 618.509540786081, 773.3171624289088, 592.4405424515579, 772.5862559335484, 573.436973572186, 766.7390039706647, 567.5897216093024, 761.6226585031415, 582.2078515165116, 747.0045285959324]
		],
		"area": 1638.1394729040621,
		"bbox": [567.5897216093024, 736.7718376608859, 69.92338805615043, 38.00713775874374],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 6,
		"id": 27,
		"iscrowd": 0,
		"segmentation": [
			[468.23507475293, 300.62819426004523, 462.84923724213877, 306.19975030569134, 459.692022149606, 311.39986928162773, 464.70642259068745, 319.01432921067743, 470.83513424089824, 319.20004774553234, 471.3922898454628, 323.1001369774846, 504.264470514775, 328.4859744882759, 505.00734465419447, 326.4430706048723, 502.59300370108116, 323.65729258204925, 498.04576586421837, 321.46909596855556, 484.5525520020495, 316.5011399556661, 486.25306050688306, 310.36057868900707, 474.5206181453151, 302.9804939776982]
		],
		"area": 541.2336829393753,
		"bbox": [459.692022149606, 300.62819426004523, 45.315322504588494, 27.857780228230638],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 6,
		"id": 28,
		"iscrowd": 0,
		"segmentation": [
			[466.26167687461884, 323.33407447616526, 462.11332066848195, 324.9144006499317, 463.8911876139692, 327.4824306823021, 469.8174107655933, 329.0627568560686, 475.3485523737758, 329.75414955709135, 480.6821532102375, 330.93939418741616, 485.8182132749784, 331.4332461167182, 489.5714879376737, 332.61849074704304, 493.32476260036896, 332.61849074704304, 494.31246645897295, 331.03816457327656, 491.74443642660253, 328.86521608434776, 483.64526478604955, 326.7910379812793, 473.96576697173015, 324.32177833476925]
		],
		"area": 139.56345799380506,
		"bbox": [462.11332066848195, 323.33407447616526, 32.199145790491, 9.284416270877784],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 6,
		"id": 29,
		"iscrowd": 0,
		"segmentation": [
			[667.0543832739733, 252.29454844604328, 663.6494706921862, 255.15028157915492, 662.6609476845707, 259.98306072749773, 664.3084860305967, 264.3764963169003, 666.3953679355628, 267.5617371192171, 667.7133986123836, 270.0879625831236, 669.0314292892043, 272.2846803778249, 673.534700768342, 272.0650085983547, 678.2576440269497, 265.8043628834561, 690.5592636772768, 263.3879733092847, 702.2018679891936, 263.27813741954964, 718.1620450335928, 265.2050309745591, 720.1721283775852, 264.3296720989495, 719.2967695019756, 262.6437957459235, 717.481210352563, 261.3469677820574, 699.6068766302599, 254.69501868711046, 692.0153278356878, 254.6674130551302, 690.6074406046945, 256.15811718206436, 686.770257759438, 254.69501868711046, 684.7826522568591, 251.85163859314346, 671.7068760092877, 248.7980773942445]
		],
		"area": 612.8000221246766,
		"bbox": [662.6609476845707, 248.7980773942445, 57.51118069301447, 23.486602983580383],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 6,
		"id": 30,
		"iscrowd": 0,
		"segmentation": [
			[790.3199653556578, 397.8128096081342, 791.9508131325811, 393.6192010389028, 809.8901386787377, 375.9128537465925, 810.0066278056607, 373.69956033505366, 800.1050520171977, 364.4969193081292, 792.5332587671966, 360.6527781196671, 782.6316829787336, 358.5559738350514, 775.6423353633479, 361.11873462735946, 769.9343681441163, 364.263941054283, 768.420009494116, 373.1171147004382, 769.2354333825778, 379.4075275542853, 772.6136180633474, 382.2032666004395, 782.1657264710411, 394.08515754659516]
		],
		"area": 1016.7245928126504,
		"bbox": [768.420009494116, 358.5559738350514, 41.586618311544726, 39.2568357730828],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 7,
		"id": 31,
		"iscrowd": 0,
		"segmentation": [
			[637.2115604899315, 772.5076811162917, 628.5548564682897, 768.4071371060404, 620.9612564493058, 759.9023050847783, 615.8327037958683, 741.3573932593747, 606.4529234512712, 737.605481121536, 600.3560662272832, 736.9019975956911, 592.1487584257608, 742.9988548196792, 581.5965055380892, 748.8612175350523, 570.5752636331877, 758.0065033710343, 566.8233514953489, 764.8068441208673, 577.1411098744056, 768.558756258706, 596.6041540894444, 773.7176354482344, 610.9083191149548, 771.3726903620851, 629.6678798041488, 776.0625805343836]
		],
		"area": 1467.51385434845,
		"bbox": [566.8233514953489, 736.9019975956911, 70.38820899458256, 39.16058293869253],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 7,
		"id": 32,
		"iscrowd": 0,
		"segmentation": [
			[630.1765174303047, 780.9849174340773, 630.1765174303047, 794.6235788740433, 646.1399507066286, 794.0811321122266, 647.9222757811697, 788.9666340722392, 641.1804374557319, 782.379780535892]
		],
		"area": 192.89189494776656,
		"bbox": [630.1765174303047, 780.9849174340773, 17.745758350865003, 13.638661439966086],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 7,
		"id": 33,
		"iscrowd": 0,
		"segmentation": [
			[790.1506794439033, 396.89875121798843, 809.3639770683118, 375.0562654976083, 806.5325437341884, 372.4270774016366, 797.4315080173634, 365.75298454263157, 789.7461889676, 361.91032501774987, 780.4429080126232, 360.6968535888399, 774.5777961062249, 362.51706073220487, 772.3530984865565, 369.1911535912099, 772.9598342010115, 374.85402025945666, 775.7912675351349, 382.1348488329167, 777.0047389640449, 387.99996073931504]
		],
		"area": 830.1087007570895,
		"bbox": [772.3530984865565, 360.6968535888399, 37.010878581755264, 36.20189762914856],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 7,
		"id": 34,
		"iscrowd": 0,
		"segmentation": [
			[667.1685859177426, 271.8626535294822, 663.2005741377076, 262.31462518377305, 664.1925770827163, 255.12260383245967, 665.8045818683555, 252.39459573368563, 668.4085895990034, 249.4185868986594, 670.392595489021, 248.79858505802895, 683.4370843199869, 250.7133908785806, 685.4148842879249, 252.64174584732015, 687.7387992502521, 255.80622579602098, 690.6066092037622, 256.0040057928148, 692.683299170097, 254.6689908144566, 699.6924505800665, 254.78371064662727, 720.8514561722538, 262.575963763418, 721.7219408165225, 264.27548140222837, 720.1882297766205, 265.1874176962242, 702.8614401906998, 263.61225500659503, 684.3740044124208, 263.28064180877834, 679.716542596566, 265.3249834050235]
		],
		"area": 606.6848691470659,
		"bbox": [663.2005741377076, 248.79858505802895, 58.52136667881496, 23.064068471453254],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 7,
		"id": 35,
		"iscrowd": 0,
		"segmentation": [
			[464.7590273929216, 305.7194027827721, 471.0222241974999, 301.0900834054751, 476.8769516452578, 300.6816140486548, 479.1916113339063, 303.8132124509439, 482.187053283922, 306.67249794868616, 486.13559039985176, 310.6210350646159, 487.08868556576584, 313.2080076578113, 481.3701145702813, 318.38195284420203, 497.3004194862739, 322.60280286467867, 501.7935824112974, 324.5089931965069, 504.6528679090396, 328.86599966925695, 500.1597049840161, 330.7721900010851, 489.9479710635081, 331.58912871472575, 485.04633878166425, 332.26991097609294, 462.0358983474528, 328.3213738601632, 462.71668060882, 325.5982448146944, 469.2521903179451, 321.51355124649115, 464.3505580361013, 316.8842318691942]
		],
		"area": 712.0112226908968,
		"bbox": [462.0358983474528, 300.6816140486548, 42.616969561586814, 31.588296927438137],
		"category_id": 0,
		"order": 5
	}, {
		"image_id": 8,
		"id": 36,
		"iscrowd": 0,
		"segmentation": [
			[793.3457312260513, 396.80649213373374, 794.1389780045928, 390.2338759686746, 807.284210334711, 377.3152855752827, 807.8508151765265, 372.8957678091223, 804.5645070939969, 368.24960810623566, 792.2125215424204, 362.6968806564444, 782.8068811682841, 360.43046128918263, 776.3475859715882, 367.2297193909679, 774.6477714461417, 373.4623726509377, 776.9141908134036, 383.3212968985263, 779.1806101806653, 388.7607033799545, 781.9003134213793, 392.1603324308471]
		],
		"area": 766.5111824440246,
		"bbox": [774.6477714461417, 360.43046128918263, 33.20304373038471, 36.37603084455111],
		"category_id": 0,
		"order": 1
	}, {
		"image_id": 8,
		"id": 37,
		"iscrowd": 0,
		"segmentation": [
			[472.56789591088324, 301.9538622884602, 479.6571110994213, 304.82330653143987, 486.74632628795933, 309.8870316661099, 493.8355414764974, 311.57494004433323, 501.09354750285775, 315.1195476386023, 503.2878283945481, 321.7023903136733, 491.8100514226294, 322.71513534060733, 478.8131569103096, 320.52085444891696, 463.7907723441219, 313.4316392603789, 462.1028639658985, 305.66726072055155]
		],
		"area": 477.62642115434573,
		"bbox": [462.1028639658985, 301.9538622884602, 41.18496442864961, 20.761273052147146],
		"category_id": 0,
		"order": 2
	}, {
		"image_id": 8,
		"id": 38,
		"iscrowd": 0,
		"segmentation": [
			[665.7601771115822, 269.53170795345187, 680.5967809202416, 264.6328293373851, 691.2343459151294, 263.5130856537127, 713.5330235768897, 264.2182323939071, 717.2308951964027, 265.67911994729496, 721.2026832321759, 265.4052035310347, 720.1983230392218, 263.8073577695168, 710.2460265817671, 260.7029717185676, 703.945949007782, 257.6442384036618, 697.5171594824766, 254.26763108506208, 693.2967028060517, 255.10024269403067, 689.4749864563443, 255.8770143098249, 686.7407503687488, 256.529502467092, 684.690073303052, 252.4592192003304, 682.6692159737936, 250.65167351749346, 664.9189145810122, 247.67420360644627, 662.9721073314814, 249.44923374572443, 662.8003302212287, 259.52682421388414, 663.5446976989905, 266.97049899150215]
		],
		"area": 593.736997365937,
		"bbox": [662.8003302212287, 247.67420360644627, 58.402353010947195, 21.8575043470056],
		"category_id": 0,
		"order": 3
	}, {
		"image_id": 8,
		"id": 39,
		"iscrowd": 0,
		"segmentation": [
			[639.6359848037292, 774.5020180770084, 635.1590007180087, 771.4770288299, 628.9880226539073, 768.5730391526757, 625.6000346971456, 765.7900490453359, 623.6640415789961, 749.9391053904872, 616.4040673859357, 743.0421299070797, 607.3250150933964, 737.9142049701919, 600.1496603547893, 737.273548297102, 592.9743056161822, 738.6829929778999, 584.1332435275414, 739.8361749894617, 580.4174348236198, 743.6801150280012, 580.1611721543838, 748.8053684127206, 576.3172321158444, 752.3930457820242, 574.5233934311926, 759.1840065167772, 575.0359187696645, 764.8217852399686, 573.6264740888666, 768.793856613126, 580.6736974928558, 771.4846146401037, 592.2055176084743, 773.0221906555195, 607.7094090972503, 772.3815339824296, 622.0601185744645, 774.0472413324633, 632.3106253439032, 777.250524697913]
		],
		"area": 1619.7162347433623,
		"bbox": [573.6264740888666, 737.273548297102, 66.00951071486259, 39.97697640081094],
		"category_id": 0,
		"order": 4
	}, {
		"image_id": 8,
		"id": 40,
		"iscrowd": 0,
		"segmentation": [
			[630.0817640932652, 781.5082893196262, 629.8793962845028, 794.1225493991504, 645.7315413042257, 793.7852697178797, 647.4179397105793, 788.1864270087862, 639.3543323321237, 781.6107714105622]
		],
		"area": 184.18309333355865,
		"bbox": [629.8793962845028, 781.5082893196262, 17.538543426076444, 12.614260079524229],
		"category_id": 0,
		"order": 5
	}],
	"categories": [{
		"id": 0,
		"name": "",
		"supercategory": ""
	}]
}

2.编写配置文件

配置文件比较多,好在逻辑足够清晰,鉴于是自己修改,所以先把源文件 copy 一份,下面简单解析下会用到的几个文件,以solov2_r50_fpn_3x_coco为例:
主文件:定义了学习率,训练模型保存路径,epochbs
其中,traindataset 相关的设置都在 test_coco_instance.yml文件中

【test_solov2_r50_fpn_3x_coco.yml】
_BASE_: [
  '../datasets/test_coco_instance.yml',
  '../runtime.yml',
  '_base_/solov2_r50_fpn.yml',
  '_base_/optimizer_1x.yml',
  '_base_/solov2_reader.yml',
]
weights: output/test_solov2_r50_fpn_3x_coco/model_final
epoch: 36

LearningRate:
  base_lr: 0.01
  schedulers:
  - !PiecewiseDecay
    gamma: 0.1
    milestones: [24, 33]
  - !LinearWarmup
    start_factor: 0.
    steps: 1000

TrainReader:
  sample_transforms:
  - Decode: {}
  - Poly2Mask: {}
  - RandomResize: {interp: 1,
                     target_size: [[640, 1333], [672, 1333], [704, 1333], [736, 1333], [768, 1333], [800, 1333]],
                     keep_ratio: True}
  - RandomFlip: {}
  - NormalizeImage: {is_scale: true, mean: [0.485,0.456,0.406], std: [0.229, 0.224,0.225]}
  - Permute: {}
  batch_transforms:
  - PadBatch: {pad_to_stride: 32}
  - Gt2Solov2Target: {num_grids: [40, 36, 24, 16, 12],
                        scale_ranges: [[1, 96], [48, 192], [96, 384], [192, 768], [384, 2048]],
                        coord_sigma: 0.2}
  batch_size: 1
  shuffle: true
  drop_last: true

数据配置文件,主要包含, train/test 相关数据路径问题,若只改变数据源,就该这个文件就好

[test_coco_instance.yml]
metric: COCO
num_classes: 80

TrainDataset:
  !COCODataSet
    image_dir: images
    anno_path: instances_train_battery.json # annotations/instances_train2017.json
    dataset_dir: dataset/coco/battery/train
    data_fields: ['image', 'gt_bbox', 'gt_class', 'gt_poly', 'is_crowd']

EvalDataset:
  !COCODataSet
    image_dir: images
    anno_path: instances_test_battery.json
    dataset_dir: dataset/coco/battery/test

TestDataset:
  !ImageFolder
    anno_path: instances_test_battery.json # also support txt (like VOC's label_list.txt)
    dataset_dir: dataset/coco/battery/test # if set, anno_path will be 'dataset_dir/anno_path'

# copy from coco_instance.yml

还有一个鸡肋文件:定义 is_use_gpu 等信息

【runtime.yml】
use_gpu: True
use_xpu: false
log_iter: 20
save_dir: output
snapshot_epoch: 1
print_flops: false

# Exporting the model
export:
  post_process: True  # Whether post-processing is included in the network when export model.
  nms: True           # Whether NMS is included in the network when export model.
  benchmark: False    # It is used to testing model performance, if set `True`, post-process and NMS will not be exported.
  fuse_conv_bn: False

3.train

设置好参数,就是最耗时间且最不需要动脑子的 train 了,一句话就好:

python tools/train.py -c ./configs/solov2/test_solov2_r50_fpn_3x_coco.yml

漫长的过程,在 train 之初,可能会遇到 GPU显存等问题,见招拆招就好
比如,我出现的bug:

Out of memory error on GPU 0. Cannot allocate 264.375000MB memory on GPU 0, 3.999695GB memory has been allocated and available memory is only 0.000000B.

Please check whether there is any other process using GPU 0.
1. If yes, please stop them, or start PaddlePaddle on another GPU.
2. If no, please decrease the batch size of your model.
If the above ways do not solve the out of memory problem, you can try to use CUDA managed memory. The command is `export FLAGS_use_cuda_managed_memory=false`.
 (at /paddle/paddle/fluid/memory/allocation/cuda_allocator.cc:87)
 (at /paddle/paddle/fluid/imperative/basic_engine.cc:586)

解决方案就是找到 batch_size,将此值降低就好,奈何我的 1650有点 low,很残酷,只能把 batch_size 设为 1 才行;
正常运行时:

[09/07 06:23:19] ppdet.engine INFO: Epoch: [0] [ 0/60] learning_rate: 0.000000 loss_ins: 2.997996 loss_cate: 1.103366 loss: 4.101363 eta: 0:47:52 batch_cost: 1.3299 data_cost: 0.0003 ips: 0.7520 images/s
[09/07 06:23:29] ppdet.engine INFO: Epoch: [0] [20/60] learning_rate: 0.000200 loss_ins: 2.995760 loss_cate: 0.649032 loss: 3.645120 eta: 0:19:30 batch_cost: 0.5079 data_cost: 0.0002 ips: 1.9688 images/s
[09/07 06:23:39] ppdet.engine INFO: Epoch: [0] [40/60] learning_rate: 0.000400 loss_ins: 2.998715 loss_cate: 1.043475 loss: 3.999994 eta: 0:18:34 batch_cost: 0.5033 data_cost: 0.0002 ips: 1.9870 images/s
[09/07 06:23:52] ppdet.utils.checkpoint INFO: Save checkpoint: output/test_solov2_r50_fpn_3x_coco
[09/07 06:23:53] ppdet.engine INFO: Epoch: [1] [ 0/60] learning_rate: 0.000600 loss_ins: 2.996527 loss_cate: 0.800405 loss: 3.752607 eta: 0:18:11 batch_cost: 0.5073 data_cost: 0.0002 ips: 1.9713 images/s
[09/07 06:24:03] ppdet.engine INFO: Epoch: [1] [20/60] learning_rate: 0.000800 loss_ins: 2.996997 loss_cate: 0.415354 loss: 3.412265 eta: 0:17:49 batch_cost: 0.4970 data_cost: 0.0002 ips: 2.0123 images/s

4. export model

train结束后会在目标目录下生成一系列的 pd 文件,如下图所示:Paddle记录_第3张图片
这些文件都是中间变量,因此,要将其中有效的模型文件*.pdparams生成可以 部署的 pdiparams 文件,例如:

python tools/export_model.py -c configs/solov2/test_solov2_r50_fpn_3x_coco.yml --output_dir=./inference_model-0907 -o weights=output/test_solov2_r50_fpn_3x_coco/model_final

4. deploy

测试下 model 的检测结果如何:需要指定 model_dirimage_file:

python deploy/python/infer.py --model_dir=./inference_model-0907/test_solov2_r50_fpn_3x_coco --image_file=./dataset/coco/battery/test/images/Image_20220901173956628.jpg --device gpu

总结

至此,基于 PaddleDetectionSOLOv2 从训练部署的过程已形成闭环,可以进行下一步的优化及功能修改了。

你可能感兴趣的:(编程工具,DeepLearning,点云,人工智能,深度学习,python)