涂淑琴,黃 磊,梁 云,黃正鑫,李承桀,劉曉龍
基于JDE模型的群養(yǎng)生豬多目標(biāo)跟蹤
涂淑琴,黃 磊,梁 云※,黃正鑫,李承桀,劉曉龍
(華南農(nóng)業(yè)大學(xué)數(shù)學(xué)與信息學(xué)院,廣州 510642)
為實(shí)現(xiàn)群養(yǎng)生豬在不同場景下(白天與黑夜,豬只稀疏與稠密)的豬只個體準(zhǔn)確檢測與實(shí)時跟蹤,該研究提出一種聯(lián)合檢測與跟蹤(Joint Detection and Embedding,JDE)模型。首先利用特征提取模塊對輸入視頻序列提取不同尺度的圖像特征,產(chǎn)生3個預(yù)測頭,預(yù)測頭通過多任務(wù)協(xié)同學(xué)習(xí)輸出3個分支,分別為分類信息、邊界框回歸信息和外觀信息。3種信息在數(shù)據(jù)關(guān)聯(lián)模塊進(jìn)行處理,其中分類信息和邊界框回歸信息輸出檢測框的位置,結(jié)合外觀信息,通過包含卡爾曼濾波和匈牙利算法的數(shù)據(jù)關(guān)聯(lián)算法輸出視頻序列。試驗(yàn)結(jié)果表明,本文JDE模型在公開數(shù)據(jù)集和自建數(shù)據(jù)集的總體檢測平均精度均值(mean Average Precision,mAP)為92.9%,多目標(biāo)跟蹤精度(Multiple Object Tracking Accuracy,MOTA)為83.9%,IDF1得分為79.6%,每秒傳輸幀數(shù)(Frames Per Second,F(xiàn)PS)為73.9幀/s。在公開數(shù)據(jù)集中,對比目標(biāo)檢測和跟蹤模塊分離(Separate Detection and Embedding,SDE)模型,本文JDE模型在MOTA提升0.5個百分點(diǎn)的基礎(chǔ)上,F(xiàn)PS提升340%,解決了采用SDE模型多目標(biāo)跟蹤實(shí)時性不足問題。對比TransTrack模型,本文JDE模型的MOTA和IDF1分別提升10.4個百分點(diǎn)和6.6個百分點(diǎn),F(xiàn)PS提升324%。實(shí)現(xiàn)養(yǎng)殖環(huán)境下的群養(yǎng)生豬多目標(biāo)實(shí)時跟蹤,可為大規(guī)模生豬養(yǎng)殖的精準(zhǔn)管理提供技術(shù)支持。
目標(biāo)檢測;目標(biāo)跟蹤;聯(lián)合檢測與跟蹤;數(shù)據(jù)關(guān)聯(lián);群養(yǎng)生豬
生豬產(chǎn)業(yè)一直是國內(nèi)畜牧業(yè)的支柱產(chǎn)業(yè),其發(fā)展關(guān)系到國家食物安全、社會穩(wěn)定及國民經(jīng)濟(jì)的協(xié)調(diào)發(fā)展。生豬養(yǎng)殖業(yè)正朝著規(guī)?;?、專業(yè)化、智能化和精細(xì)化發(fā)展。目前,在勞動力短缺的情況下,智能與精準(zhǔn)畜牧業(yè)對幫助農(nóng)戶實(shí)現(xiàn)畜牧業(yè)規(guī)?;a(chǎn)具有重要作用[1]。通過視頻攝像頭,采用計(jì)算機(jī)視覺技術(shù)獲取每頭豬每天的體重變化、運(yùn)動軌跡、飲食情況和行為變化等數(shù)據(jù),監(jiān)測豬只行為和健康,預(yù)測豬只個體異常情況,實(shí)現(xiàn)生豬生產(chǎn)過程的精確控制[2],對提高生豬的福利具有重要價值[3]。因此,采用多目標(biāo)跟蹤技術(shù),準(zhǔn)確跟蹤群養(yǎng)生豬中的個體,識別豬只行為變化,對提高農(nóng)場的智能化管理水平和生產(chǎn)力具有重要意義。
目前,國內(nèi)外研究者在禽畜跟蹤的方面進(jìn)行很多研究。有些研究者通過給禽畜穿戴自動跟蹤設(shè)備實(shí)現(xiàn)跟蹤禽畜。如Zambelis等[4]使用耳標(biāo)加速計(jì)對飼養(yǎng)奶牛的喂養(yǎng)和活動行為進(jìn)行觀察。Giovanetti等[5]將三軸加速度計(jì)傳感器安裝在羊的身體上,然后測量羊在牧場的行為。Krista等[6]將運(yùn)動能耗儀安裝在母羊的項(xiàng)圈上,以此評估綿羊行為活動水平。這些方法在某些情況下對于禽畜的觀察是可行的,但是,使用可穿戴自動跟蹤設(shè)備會影響禽畜的行為,嚴(yán)重情況下會影響其自由活動,降低動物福利。另外,大量可穿戴自動跟蹤設(shè)備會增加生產(chǎn)的成本。
近年來,使用計(jì)算機(jī)視覺技術(shù)進(jìn)行豬只日常行為監(jiān)控取得了多方面的研究成果,例如豬的攻擊行為[7-10]、飲食飲水行為[11-15]、母豬行為檢測[16]、攀爬和玩耍行為[17-18],豬只姿態(tài)識別[11,19-22],早期發(fā)現(xiàn)呼吸道疾病[23-24]。
多目標(biāo)跟蹤的性能在很大程度上取決于其檢測目標(biāo)的性能。傳統(tǒng)的目標(biāo)檢測算法,如Zhao等[25]使用背景減法來檢測移動奶牛目標(biāo),Zhang等[26]提出了一種基于光流估計(jì)的運(yùn)動目標(biāo)檢測方法,于欣等[27]提出一種基于光流法與特征統(tǒng)計(jì)的魚群異常行為檢測方法,這些算法在速度和準(zhǔn)確性方面不能滿足實(shí)際場景要求。目前,基于深度學(xué)習(xí)的目標(biāo)檢測算法不斷完善,其準(zhǔn)確性和速度都有顯著提升,能夠滿足實(shí)際應(yīng)用。深度學(xué)習(xí)的目標(biāo)檢測算法主要分為一階段和二階段算法。二階段算法在檢測時首先生成候選區(qū)域,之后對候選區(qū)域進(jìn)行分類和校準(zhǔn),準(zhǔn)確率相對較高,典型的有R-CNN(Region Convolution Neural Network)算法[28],F(xiàn)ast R-CNN算法[29],F(xiàn)aster R-CNN算法[30]。如王浩等[31]利用改進(jìn)的Faster R-CNN算法定位群養(yǎng)生豬的圈內(nèi)位置,識別準(zhǔn)確率可達(dá)96.7%。一階段算法在檢測時無需生成候選區(qū)域,直接對目標(biāo)類別和邊界進(jìn)行回歸,如YOLO系列算法[32-35]。如金耀等[36]利用YOLOv3算法[32]對生豬個體進(jìn)行識別,對母豬的識別精度均值達(dá)95.16%。相較于二階段算法,一階段算法的檢測速度更快。
在多目標(biāo)跟蹤方面,現(xiàn)有多目標(biāo)跟蹤算法的應(yīng)用大多是基于檢測跟蹤(Tracking by Detection,TBD)范式,即SDE(Separate Detection and Embedding)模型,先用檢測器輸出檢測結(jié)果,再用基于卡爾曼濾波和匈牙利算法的后端追蹤優(yōu)化算法進(jìn)行跟蹤,如使用SORT(Simple Online and Realtime Tracking)[37]、DeepSORT[38]算法來提取目標(biāo)的表觀特征進(jìn)行多目標(biāo)重識別進(jìn)行跟蹤,其中DeepSORT算法在SORT算法的基礎(chǔ)上,通過提取深度表觀特征提高了多目標(biāo)的跟蹤效果。如張宏鳴等[39]利用改進(jìn)YOLOv3算法結(jié)合DeepSORT算法進(jìn)行肉牛多目標(biāo)跟蹤,張偉等[40]利用基于CenterNet結(jié)合優(yōu)化DeepSORT算法進(jìn)行斷奶仔豬目標(biāo)跟蹤。上述研究的算法是兩階段過程,先檢測再跟蹤,目標(biāo)檢測和跟蹤模塊分離導(dǎo)致跟蹤速度慢,達(dá)不到實(shí)時跟蹤效果。
本研究將目標(biāo)檢測與跟蹤融合在一個過程中,提出一種實(shí)時、非接觸的群養(yǎng)生豬多目標(biāo)跟蹤JDE(Joint Detection and Embedding)算法,通過一個端對端網(wǎng)絡(luò)同時輸出多目標(biāo)的分類信息、邊界框回歸信息和外觀信息,以減少算法的運(yùn)行時間,達(dá)到實(shí)時跟蹤的效果。在相同的公開試驗(yàn)數(shù)據(jù)集中將JDE算法與SDE算法進(jìn)行對比,以驗(yàn)證本文算法的速度,同時與TransTrack算法[41]對比,進(jìn)一步驗(yàn)證本文算法的準(zhǔn)確性與實(shí)時性。
基于JDE的群養(yǎng)生豬多目標(biāo)跟蹤算法如圖1所示。該算法以群養(yǎng)生豬視頻序列為輸入;采用特征提取模塊提取不同尺度的圖像特征,得到3個不同尺度特征圖的預(yù)測頭,輸入數(shù)據(jù)關(guān)聯(lián)模塊;預(yù)測頭的分類信息和邊界框回歸信息用于得到檢測框的位置結(jié)果,在跟蹤部分,利用外觀信息結(jié)合檢測框,通過包含卡爾曼濾波和匈牙利算法的數(shù)據(jù)關(guān)聯(lián)算法,輸出檢測與跟蹤的視頻序列結(jié)果。
圖1 基于JDE的群養(yǎng)生豬多目標(biāo)跟蹤算法
特征提取模塊由Darknet-53網(wǎng)絡(luò)和多尺度模塊特征金字塔構(gòu)成,如圖2所示。Darknet-53網(wǎng)絡(luò)包括6個卷積層和5個殘差層,其中卷積層和殘差層的大小和數(shù)量見表1。卷積層由卷積層、批量歸一化層和激活函數(shù)層共同構(gòu)成,殘差層由一個1×1大小的卷積層和3×3大小的卷積層構(gòu)成。
特征金字塔采用同一圖像的不同尺度來檢測目標(biāo),有助于檢測小目標(biāo)。本文特征金字塔利用Darknet-53網(wǎng)絡(luò)中的第3、4和5個殘差塊進(jìn)行特征融合,產(chǎn)生3個輸出預(yù)測頭,分別輸出分類信息、邊界框回歸信息和外觀信息。
圖2 特征提取網(wǎng)絡(luò)結(jié)構(gòu)
表1 Darknet-53網(wǎng)絡(luò)結(jié)構(gòu)參數(shù)
本文JDE算法的學(xué)習(xí)目標(biāo)為多任務(wù)協(xié)同學(xué)習(xí),其總體損失L為分類損失、邊界框回歸損失和外觀信息學(xué)習(xí)損失之和,如式(1)所示。
式中ω、ω、ω分別為分類、邊界框回歸和外觀信息學(xué)習(xí)的權(quán)重值,L為分類損失,L為外觀信息學(xué)習(xí)損失,其中損失均為交叉熵?fù)p失,計(jì)算公式如式(2)所示。
式中為類別的數(shù)量,為樣本數(shù),y為符號函數(shù)(0或1),為類別數(shù)。如果樣本的真實(shí)類別等于,則y=1,否則y=0。p為觀測樣本屬于類別的預(yù)測概率。
L為邊界框回歸損失,為smooth-L1損失,計(jì)算公式如式(3)所示。
式中為輸入樣本。
算法采用基于任務(wù)的不確定性計(jì)算加權(quán)系數(shù),最終自動加權(quán)的損失L如式(4)所示。
式中、、為每個個體損失的任務(wù)依賴的不確定性,為可學(xué)習(xí)參數(shù)。
模型通過分類損失和回歸損失學(xué)習(xí)到的分類信息和回歸信息生成檢測框?qū)σ曨l幀中每個豬只進(jìn)行定位,外觀學(xué)習(xí)損失得到的外觀信息包括每個豬只的外觀特征,二者通過數(shù)據(jù)關(guān)聯(lián),對每頭豬分配ID,實(shí)現(xiàn)多目標(biāo)跟蹤。豬只多目標(biāo)跟蹤的具體實(shí)現(xiàn)流程如圖3所示,具體步驟如下:
1)創(chuàng)建初始跟蹤軌跡。對于給定的視頻幀序列,第一幀將根據(jù)視頻幀序列的檢測結(jié)果利用卡爾曼濾波對軌跡進(jìn)行初始化,并維護(hù)一個跟蹤軌跡池,包含所有可能與預(yù)測值相關(guān)聯(lián)的軌跡。
2)數(shù)據(jù)關(guān)聯(lián)。對于下一幀的輸出結(jié)果,利用卡爾曼濾波進(jìn)行軌跡預(yù)測,計(jì)算出預(yù)測值與軌跡池之間的運(yùn)動親和信息和外觀親和信息,其中外觀親和信息采用余弦相似度計(jì)算,運(yùn)動親和信息采用馬氏距離計(jì)算,然后利用匈牙利算法的代價矩陣進(jìn)行軌跡分配。
3)更新軌跡。如果出現(xiàn)在2幀內(nèi)的預(yù)測值沒有被分配給任何一個軌跡池中的軌跡,那么這條軌跡將被初始化為新的軌跡,然后根據(jù)卡爾曼濾波進(jìn)行所有匹配軌跡狀態(tài)的更新,如果某條軌跡在連續(xù)30幀內(nèi)沒有被更新,則終止該軌跡,所有視頻幀處理完畢后,輸出視頻幀序列。
圖3 卡爾曼濾波結(jié)合匈牙利算法的豬只目標(biāo)跟蹤流程
本試驗(yàn)采用的數(shù)據(jù)集包括2部分:一部分為Psota等[42]提供的公開數(shù)據(jù)集,包含不同日齡、大小、數(shù)量和不同環(huán)境的豬只視頻,其中,視頻1、2、4、5為保育豬(3~10周齡),視頻6、7、8、9、10為早期育成豬(11~18周齡),視頻12、15為晚期育成豬(19~26周齡)。根據(jù)時間段的不同將豬只的活動水平分為3類:白天的高活動、白天(或夜晚)的中等活動、白天(或夜晚)的低活動,詳表2。同時,根據(jù)人工觀察,將豬只個數(shù)較多且黏連遮擋情況較為嚴(yán)重的視頻定義為稠密視頻,反之為稀疏視頻,見表2。另外一部分為自建數(shù)據(jù)集[43]。兩部分?jǐn)?shù)據(jù)集均為俯拍視頻片段,由于攝像頭高度及焦距的影響,不可避免拍攝到豬圈外的物品,因此,在試驗(yàn)中采用視頻裁剪方法將視角固定為豬圈內(nèi),以減少外部環(huán)境的影響。
表2 公開數(shù)據(jù)集
首先,利用FFmpeg軟件完成視頻剪輯,從中截取稠密、稀疏、白天、黑夜的視頻,2部分?jǐn)?shù)據(jù)集共21個視頻。然后利用DarkLabel軟件對數(shù)據(jù)進(jìn)行標(biāo)注,其中,公開數(shù)據(jù)集11個視頻,共3 300張圖像,自建數(shù)據(jù)集10個視頻,共1 000張圖像。部分?jǐn)?shù)據(jù)集如圖4所示。為對比不同場景下模型的檢測和跟蹤能力,選取不同的視頻進(jìn)行模型訓(xùn)練和測試,參與訓(xùn)練的視頻不參與測試。本文共設(shè)計(jì)3個試驗(yàn),其中試驗(yàn)1以視頻4、6、12為測試集,這些視頻均為白天稠密,其余視頻為訓(xùn)練集。試驗(yàn)2以視頻2、5、8為測試集,其中視頻5、8分別為夜晚稀疏與夜晚稠密,視頻2為白天稀疏,其余視頻為訓(xùn)練集。試驗(yàn)3以自建數(shù)據(jù)集的7個視頻為測試集(視頻3、11、14、16、18、19、21),另外3個視頻為測試集(視頻13、17、20)。其中豬只活動水平定義如下:根據(jù)視頻的人工觀察結(jié)果,在白天(10:00-12:30)豬只的飲食和玩耍等行為較頻繁,此時間段定義為豬只白天的高活動水平。在白天(12:30-17:00)或夜晚(17:00-20:00)豬只的飲食和玩耍等行為沒有白天(10:00-12:30)高,此時間段定義為白天或夜晚的中等活動水平。在白天(7:00-10:00)或夜晚(20:00-7:00)豬只的飲食和玩耍等行為較少,躺臥行為較多,此時間段定義為白天或夜晚的低活動水平。
圖4 部分?jǐn)?shù)據(jù)集
本文所有試驗(yàn)在同一計(jì)算機(jī)上完成,硬件配置為12th Gen Intel(R) i9-12900KF CPU,NVIDIA GeForce RTX 3090 GPU,32GB內(nèi)存,64位Linux操作系統(tǒng),Pytorch版本1.7.1,Python版本3.8,CUDA版本11.0。
訓(xùn)練過程中設(shè)置圖片尺寸為416×416(像素),批處理大?。˙atchsize)設(shè)置為32,初始學(xué)習(xí)率(Learning Rate)為0.01,動量(Momentum)設(shè)置為0.9,共訓(xùn)練30個時期(Epoch),使用隨機(jī)梯度下降法(Stochastic Gradient Descent, SGD)進(jìn)行優(yōu)化,保存訓(xùn)練過程中精度最高的模型參數(shù)進(jìn)行模型測試。
選擇精確率(Precision,),召回率(Recall,)和平均精度均值(mean Average Precision,mAP)3個指標(biāo)評判模型的檢測性能。精確率衡量模型對豬只目標(biāo)檢測的精確程度,如式(5),其中DTP是檢測正確的目標(biāo)數(shù)量,DFP是檢測錯誤的目標(biāo)數(shù)量。
召回率衡量模型對豬只目標(biāo)檢測的覆蓋能力,如式(6),其中DFN是漏檢的目標(biāo)數(shù)量。
平均精度均值是對檢測的類別對應(yīng)的精度均值取平均,如式(7),其中()是以召回率為自變量,精確率為因變量的函數(shù)。
選擇多目標(biāo)跟蹤精度(Multiple Object Tracking Accuracy,MOTA)和IDF1得分(ID F1 Score)作為多目標(biāo)跟蹤的主要評價指標(biāo)。MOTA衡量跟蹤器檢測目標(biāo)和保持軌跡跟蹤的性能。IDF1為引入跟蹤目標(biāo)標(biāo)號ID的F1值,由于引入了跟蹤目標(biāo)標(biāo)號ID,IDF1更重視目標(biāo)的軌跡跟蹤能力。MOTA計(jì)算公式如式(8)所示。
式中FP為在第幀中目標(biāo)誤報總數(shù)(假陽性);FN為在第幀目標(biāo)丟失總數(shù)(假陰性);IDS為在第幀中跟蹤目標(biāo)標(biāo)號ID發(fā)生切換的次數(shù);g是時刻觀測到的目標(biāo)數(shù)量。
IDF1計(jì)算公式如式(9)所示。
式中IDTP為ID保持不變的情況下正確跟蹤到的目標(biāo)總數(shù),IDFP為ID保持不變的情況下跟蹤錯誤的目標(biāo)總數(shù),IDFN為ID保持不變的情況下跟蹤目標(biāo)丟失總數(shù)。
此外,其他相關(guān)指標(biāo)還有碎片數(shù)(Fragmentation,F(xiàn)M)、主要跟蹤到的目標(biāo)(Mostly Tracked Target,MT)(被跟蹤到的軌跡比例大于80%)、主要丟失目標(biāo)(Mostly Lost Target,ML)(被跟蹤到的軌跡比例小于20%)、部分跟蹤到的目標(biāo)(Partially Tracked Target,PT)(被跟蹤到的軌跡比例不大于80%且不小于20%)、一條跟蹤軌跡改變目標(biāo)標(biāo)號ID的次數(shù)(Identity Switches,IDS)以及平均每秒傳輸幀數(shù)(Frames Per Second,F(xiàn)PS)。
本文對群養(yǎng)生豬目標(biāo)跟蹤模型性能的分析選擇MOTA、IDF1和FPS作為主要評價指標(biāo),輔助以FP、FN、FM、IDS、MT、ML等指標(biāo)進(jìn)行模型的性能評估。其中MOTA、IDF1、MT和FPS數(shù)值越高模型性能越好,F(xiàn)P、FN、FM、IDS和ML數(shù)值越低模型性能越好。
JDE模型的檢測結(jié)果見表3??梢园l(fā)現(xiàn),本文算法在公開數(shù)據(jù)集中的mAP平均值達(dá)到92.5%,測試集2、4、6、8、12視頻的mAP分別為96.2%、95.6%、96.1%、98.0%、92.2%。對于視頻5,其mAP為77.0%,主要原因是該視頻的場景與其他視頻相比差異較大,增加了目標(biāo)檢測的難度;在自建數(shù)據(jù)集中的mAP平均值達(dá)到93.8%,總體平均mAP達(dá)到92.9%,表明本文JDE算法對于不同復(fù)雜場景具有較好的檢測能力。
表3 JDE模型的目標(biāo)檢測試驗(yàn)結(jié)果
JDE模型的跟蹤結(jié)果如表4所示。可以發(fā)現(xiàn),在公開數(shù)據(jù)集中,視頻2、4、5、6、8、12的MOTA分別為91.4%、82.5%、59.2%、90.8%、94.2%、74.4%,平均MOTA為82.1%,在自建數(shù)據(jù)集中,視頻13、17、20的MOTA分別為84.4%、88.1%、90.2%,平均MOTA為87.6%,總體平均MOTA為83.9%。不同視頻的MOTA產(chǎn)生差別的主要原因是每個視頻的環(huán)境不同,如視頻背景、白天、黑夜、稀疏、稠密和豬只的活動狀態(tài),在視頻背景干擾嚴(yán)重、豬只活動較為頻繁(如飲食,玩耍等行為)情況下,MOTA相對較低,在夜晚視頻8中,豬只活動較少且背景對豬只的干擾較小,MOTA最高,為94.2%。在夜晚視頻5中,視頻背景干擾嚴(yán)重,MOTA較低,為59.2%,根據(jù)IDF1和FPS可以看出,本文JDE模型在公開數(shù)據(jù)集中的IDF1平均值為77.7%,F(xiàn)PS平均值為74.26幀/s,在自建數(shù)據(jù)集中的IDF1平均值為83.5%,F(xiàn)PS平均值為73.19幀/s,總體平均IDF1值為79.6%,總體平均FPS值為73.9幀/s??梢园l(fā)現(xiàn),本文JDE模型對豬只目標(biāo)的ID跟蹤精度和FPS均達(dá)到較高水平,能夠?qū)崿F(xiàn)實(shí)際養(yǎng)殖環(huán)境下的群養(yǎng)豬多目標(biāo)快速實(shí)時跟蹤,為實(shí)際群養(yǎng)豬養(yǎng)殖場的精準(zhǔn)管理提供技術(shù)支持。
表4 JDE模型的多目標(biāo)跟蹤試驗(yàn)結(jié)果
豬只白天稀疏和稠密2種分布情況的可視化分析結(jié)果如圖5所示。
注:圖中數(shù)字表示豬只ID號,算法中第一幀圖像的檢測會對每頭豬只分配一個從1遞增的ID號,例如(1、2、3…),對后續(xù)幀進(jìn)行檢測和跟蹤時,由于豬只的移動,可能會對某個豬只的ID識別錯誤,此時把這個豬只識別為新的豬只,則該豬只的ID號就變?yōu)殄e誤的ID號,直至所有視頻幀處理完畢。下同。
對于豬只白天稀疏的視頻2,本文算法可以準(zhǔn)確地檢測和跟蹤每一只豬,如圖5a。但是,對豬只白天稠密且豬只粘連遮擋情況較為嚴(yán)重的視頻4存在漏檢,如圖5b中箭頭標(biāo)識的豬。這說明在豬只白天稠密的環(huán)境下,由于豬只目標(biāo)出現(xiàn)漏檢,從而影響了算法的跟蹤性能。
對豬只白天和夜晚情況下的可視化分析如圖6所示,可以發(fā)現(xiàn),在豬只白天稠密且有遮擋的情況下,本文JDE模型可以很好地跟蹤到每一只豬,如圖6a。在夜晚視頻背景比較黑暗且豬只密集有遮擋的情況下,JDE模型也可以準(zhǔn)確地跟蹤每一只豬,如圖6b。但在豬只夜晚稀疏的視頻5中,由于所有豬只都分布于豬圈的左方,且視頻背景和豬只顏色相似,這使得檢測器和跟蹤器較難檢測和跟蹤這些豬只目標(biāo),出現(xiàn)豬只漏檢的情況,如圖6c所示??傮w上,本文JDE模型對于不同場景下的群養(yǎng)生豬多目標(biāo)跟蹤達(dá)到較好水平。
圖6 豬只白天和夜晚不同分布情況的的可視化分析結(jié)果
為驗(yàn)證本文JDE模型的多目標(biāo)跟蹤性能,與經(jīng)典的SDE模型進(jìn)行對比試驗(yàn)。SDE檢測器與本文JDE模型相同,跟蹤器使用DeepSORT,采用相同的公開數(shù)據(jù)集進(jìn)行訓(xùn)練和測試,試驗(yàn)結(jié)果如表5所示??梢园l(fā)現(xiàn),SDE模型的MOTA和IDF1平均值分別為81.6%和78.2%,對比表4,本文JDE模型的MOTA提升了0.5個百分點(diǎn)。從總體性能指標(biāo)來看,本文JDE模型的MT、PT、ML、FN、MOTA和FPS指標(biāo)均優(yōu)于SDE模型。在速度方面,SDE模型的FPS均值為16.88幀/s,本文JDE模型的FPS均值達(dá)到74.26幀/s??傮w來說,二者在跟蹤準(zhǔn)確度和跟蹤精度接近情況下,本文JDE模型的視頻處理速度比SDE模型提升了340%,這對于實(shí)現(xiàn)養(yǎng)殖場長時間群養(yǎng)生豬視頻的實(shí)時多目標(biāo)跟蹤有重要意義。
表5 SDE模型的多目標(biāo)跟蹤試驗(yàn)結(jié)果
選取部分?jǐn)?shù)據(jù)集進(jìn)行可視化分析,結(jié)果如圖7所示,在豬只夜晚稠密的視頻8中,SDE模型存在錯檢情況,如圖7b左下角第二頭豬出現(xiàn)2個跟蹤框,而本文JDE模型沒有錯檢情況,如圖7a所示。在豬只白天稠密的視頻12中,由于豬只密集躺在一起,檢測器較容易發(fā)生漏檢,如圖7a、7b,JDE模型漏檢2頭豬,SDE模型漏檢3頭豬,JDE比SDE模型具有更好的檢測跟蹤結(jié)果。
圖7 JDE與SDE模型對豬只不同分布情況的可視化結(jié)果對比
此外,文獻(xiàn)[40]采用基于SDE模型對豬只目標(biāo)檢測的平均精度均值達(dá)99.0%,多目標(biāo)跟蹤精度MOTA為96.8%,但文獻(xiàn)[40]的數(shù)據(jù)場景單一,無法應(yīng)對其他場景。盡管包括白天和黑夜(光照變化),但訓(xùn)練和測試場景相同。本文數(shù)據(jù)集包含不同情況下的場景,共有11個視頻場景,各個場景環(huán)境不同,豬只大小也不同,訓(xùn)練和測試場景完全不相同。
為進(jìn)一步驗(yàn)證本文算法在群養(yǎng)豬多目標(biāo)跟蹤方面的性能,與TransTrack模型在相同的公開數(shù)據(jù)集上進(jìn)行對比試驗(yàn),試驗(yàn)結(jié)果如表6所示。TransTrack模型的平均MOTA、IDF1和FPS分別為71.7%、71.1%和17.53幀/s,與表4結(jié)果比較發(fā)現(xiàn),本文JDE模型比TransTrack模型的MOTA和IDF1分別提升10.4和6.6個百分點(diǎn),同時FPS提升324%。從性能指標(biāo)MT、PT、ML、FP、FN、IDS、FM、MOTA、IDF1和FPS的數(shù)值對比可以發(fā)現(xiàn),本文JDE模型性能均優(yōu)于TransTrack模型。
表6 TransTrack模型的試驗(yàn)結(jié)果
對2種模型的跟蹤結(jié)果選取部分?jǐn)?shù)據(jù)進(jìn)行可視化分析,結(jié)果如圖8所示。對比發(fā)現(xiàn),相較于TransTrack模型,JDE模型對豬只嚴(yán)重遮擋情況有更好的檢測和跟蹤能力,如圖8a。而TransTrack模型在豬只嚴(yán)重遮擋情況下,會出現(xiàn)豬只的漏檢或者是豬只追蹤的缺失,如圖8b??梢钥闯觯疚乃惴ㄔ诓煌瑘鼍爸?,檢測框更加貼合豬只目標(biāo),對于嚴(yán)重遮擋的豬只目標(biāo)具有更強(qiáng)的檢測跟蹤能力。
圖8 JDE與TransTrack模型的可視化結(jié)果對比
1)本文JDE模型在二階段目標(biāo)檢測和跟蹤分離框架的基礎(chǔ)上進(jìn)行改進(jìn),在輸出檢測框的同時,給網(wǎng)絡(luò)增加目標(biāo)外觀信息學(xué)習(xí)損失對應(yīng)的輸出分支,實(shí)現(xiàn)檢測和跟蹤的多任務(wù)協(xié)同學(xué)習(xí),實(shí)現(xiàn)聯(lián)合目標(biāo)檢測和跟蹤。
2)本文制作了2個數(shù)據(jù)集,分別為公開數(shù)據(jù)集和自建數(shù)據(jù)集。其數(shù)據(jù)場景復(fù)雜多樣,各個場景的豬只大小、數(shù)量、日齡和光照條件都不同,并在公開數(shù)據(jù)集中與SDE模型和TransTrack模型進(jìn)行了對比。
3)試驗(yàn)結(jié)果表明,本文JDE模型在2個數(shù)據(jù)集的總體平均精度均值mAP為92.9%,平均多目標(biāo)跟蹤精度MOTA為83.9%,平均IDF1得分為79.6%,平均每秒檢測幀數(shù)FPS為73.9。在公開數(shù)據(jù)集中與TransTrack模型進(jìn)行對比,本文JDE模型的MOTA和IDF1分別提升10.4和6.6個百分點(diǎn),F(xiàn)PS提升324%。在公開數(shù)據(jù)集中與SDE模型進(jìn)行對比,本文JDE模型在MOTA和IDF1的數(shù)值接近下,F(xiàn)PS提升340%,解決了SDE模型目標(biāo)檢測和跟蹤模塊分離導(dǎo)致目標(biāo)跟蹤速度慢的問題,這對于養(yǎng)殖場群養(yǎng)生豬長時間視頻的實(shí)時多目標(biāo)跟蹤具有重要意義。
[1] Rowe E, Dawkins M S, Gebhardt-Henrich S G A. Systematic review of precision livestock farming in the poultry sector: Is Technology focussed on improving bird welfare?[J]. Animals (Basel), 2019, 9(9): 614.
[2] Cowton J, Kyriazakis I, Plotz T , et al. A combined deep learning GRU-autoencoder for the early detection of respiratory disease in pigs using multiple environmental sensors[J]. Sensors (Basel), 2018, 18(8): 2521.
[3] Sébastien F, Alain N R, Benoit L. Rethinking environment control strategy of confined animal housing systems through precision livestock farming[J]. Biosystems Engineering, 2017, 155: 96-123.
[4] Zambelis A, Wolfe T, Vasseur E. Technical note: Validation of an ear-tag accelerometer to identify feeding and activity behaviors of tiestall-housed dairy cattle[J]. Journal of Dairy Science, 2019, 102(5): 4536-4540.
[5] Giovanetti V, Decandia M, Molle G, et al. Automatic classification system for grazing, ruminating and resting behaviour of dairy sheep using a tri-axial accelerometer[J]. Livestock Science, 2017, 196: 42-48.
[6] Krista M M, Elizabeth A S, Carlos J B R, et al. Technical note: Validation of an automatic recording system to assess behavioural activity level in sheep (Ovis aries)[J]. Small Ruminant Research, 2015, 127: 92-96.
[7] Chen C, Zhu W X, Ma C H, et al. Image motion feature extraction for recognition of aggressive behaviors among group-housed pigs[J]. Computers and Electronics in Agriculture, 2017, 142: 380-387.
[8] Chen C, Zhu W X, Guo Y Z, et al. A kinetic energy model based on machine vision for recognition of aggressive behaviours among group-housed pigs[J]. Livestock Science, 2018, 218: 70-78.
[9] Chen C, Zhu W X, Liu D, et al. Detection of aggressive behaviours in pigs using a RealSence depth sensor[J]. Computers and Electronics in Agriculture, 2019, 166: 105003.
[10] Chen C, Zhu W X, Steibel J, et al. Recognition of aggressive episodes of pigs based on convolutional neural network and long short-term memory[J]. Computers and Electronics in Agriculture, 2020, 169: 105166.
[11] Alameer A, Kyriazakis I, Bacardit J. Automated recognition of postures and drinking behaviour for the detection of compromised health in pigs[J]. Scientific Reports, 2020, 10(1): 13665.
[12] Lao F, Brown B, Stinn J P, et al. Automatic recognition of lactating sow behaviors through depth image processing[J]. Computers and Electronics in Agriculture, 2016, 125: 56-62.
[13] Zhu W X, Guo Y Z, Jiao P P, et al. Recognition and drinking behaviour analysis of individual pigs based on machine vision[J]. Livestock Science, 2017, 205: 129-136.
[14] Leonard S M, Xin H, Brown-Brandl T M, et al. Development and application of an image acquisition system for characterizing sow behaviors in farrowing stalls[J]. Computers and Electronics in Agriculture, 2019, 163: 104866.
[15] Yang A Q, Huang H S, Zheng B, et al. An automatic recognition framework for sow daily behaviours based on motion and image analyses[J]. Biosystems Engineering, 2020, 192: 56-71.
[16] Zhang Y Q, Cai J H, Xiao D Q, et al. Real-time sow behavior detection based on deep learning[J]. Computers and Electronics in Agriculture, 2019, 163: 104884.
[17] Nasirahmadi A, Hensel O, Edwards S, et al. Automatic detection of mounting behaviours among pigs using image analysis[J]. Computers and Electronics in Agriculture, 2016, 124: 295-302.
[18] Li D, Chen Y F, Zhang K F, et al. Mounting beaviour recognition for pigs based on deep learning[J]. Sensors (Basel), 2019, 19(22): 4924.
[19] Nasirahmadi A, Sturm B, Olsson A, et al. Automatic scoring of lateral and sternal lying posture in grouped pigs using image processing and support vector machine[J]. Computers and Electronics in Agriculture, 2019, 156: 475-481.
[20] Zheng C, Zhu X M, Yang X F, et al. Automatic recognition of lactating sow postures from depth images by deep learning detector[J]. Computers and Electronics in Agriculture, 2018, 147: 51-63.
[21] Zhu X M, Chen C X, Zheng B, et al. Automatic recognition of lactating sow postures by refined two-stream RGB-D faster R-CNN[J]. Biosystems Engineering, 2020, 189: 116-132.
[22] Zheng C, Yang X F, Zhu X M, et al. Automatic posture change analysis of lactating sows by action localisation and tube optimisation from untrimmed depth videos[J]. Biosystems Engineering, 2020, 194: 227-250.
[23] Jorquera-Chavez M, Fuentes S, Dunshea F R, et al. Remotely sensed imagery for early detection of respiratory disease in pigs: A pilot study[J]. Animals (Basel), 2020, 10(3): 451.
[24] Jorquera-Chavez M, Fuentes S, Dunshea F R, et al. Using imagery and computer vision as remote monitoring methods for early detection of respiratory disease in pigs[J]. Computers and Electronics in Agriculture, 2021, 187: 106283.
[25] Zhao K X, He D J. Target detection method for moving cows based on background subtraction[J]. International Journal of Agricultural and Biological Engineering, 2015, 8(1): 42-49.
[26] Zhang Y G, Zheng J, Zhang C, et al. An effective motion object detection method using optical flow estimation under a moving camera[J]. Journal of Visual Communication and Image Representation, 2018, 55: 215-228.
[27] 于欣,侯曉嬌,盧煥達(dá),等. 基于光流法與特征統(tǒng)計(jì)的魚群異常行為檢測[J]. 農(nóng)業(yè)工程學(xué)報,2014,30(2):162-168.
Yu Xin, Hou Xiaojiao, Lu Huanda, et al. Anomaly detection of fish school behavior based on features statistical and optical flow methods[J]. Transactions of the Chinese Society of Agricultural Engineering (Transactions of the CSAE), 2014, 30(2): 162-168. (in Chinese with English abstract)
[28] Girshick R, Donahue J, Darrell T, et al. Rich feature hierarchies for accurate object detection and semantic segmentation[C]//Columbus, OH, USA, IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2014: 580-587.
[29] Girshick R. Fast R-CNN[C]// Santiago, Chile, IEEE International Conference on Computer Vision (ICCV), 2015: 1440-1448.
[30] Ren S Q, He K M, Girshick R, et al. Faster R-CNN: Towards real-time object detection with region proposal networks [J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017, 39(6): 1137-1149.
[31] 王浩,曾雅瓊,裴宏亮,等. 改進(jìn) Faster R-CNN 的群養(yǎng)豬只圈內(nèi)位置識別與應(yīng)用[J]. 農(nóng)業(yè)工程學(xué)報,2020,36(21):201-209.
Wang Hao, Zeng Yaqiong , Pei Hongliang, et al. Recognition and application of pigs’position in group pens based on improved Faster R-CNN[J]. Transactions of the Chinese Society of Agricultural Engineering (Transactions of the CSAE), 2020, 36(21): 201-209. (in Chinese with English abstract)
[32] Redmon J, Farhadia A. YOLOv3: An incremental improvement [EB/OL]. 2018-04-08, https://pjreddie.com/media/files/papers/ YOLOv3.pdf.
[33] Redmon J, Divvala S, Girshick R, et al. You only look once: Unified, real-time object detection[C]//Las Vegas, NV, USA, Conference on Computer Vision and Pattern Recognition (CVPR), 2016: 779-788.
[34] Redmon J, Farhadi A. YOLO9000: Better,faster,stronger[C]//Honolulu, HI, USA, IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017: 7263-7271.
[35] Bochkovskiy A, Wang C Y, Liao H Y M. YOLOv4: Optimal speed and accuracy of object detection[EB/OL]. 2020-04-23, https://arxiv.org/pdf/2004.10934.pdf.
[36] 金耀,何秀文,萬世主,等. 基于YOLO v3的生豬個體識別方法[J]. 中國農(nóng)機(jī)化學(xué)報,2021,42(2):178-183.
Jin Yao, He Xiuwen, Wan Shizhu, et al.Individual pig identification method based on YOLOv3[J]. Journal of Chinese Agricultural Mechanization, 2021, 42(2): 178-183. (in Chinese with English abstract)
[37] Bewley A, Ge Z Y, Ott L, et al. Simple online and realtime tracking[C]//Phoenix, Arizona, USA. IEEE International Conference on Image Processing (ICIP), 2016: 3464-3468.
[38] Wojke N, Bewley A, Paulus D. Simple online and realtime tracking with a deep association metric[C]//Beijing, China. IEEE International Conference on Image Processing (ICIP), 2017: 3645-3649.
[39] 張宏鳴,汪潤,董佩杰,等. 基于DeepSORT算法的肉牛多目標(biāo)跟蹤方法[J]. 農(nóng)業(yè)機(jī)械學(xué)報,2021,52(4):249-256.
Zhang Hongming, Wang Run, Dong Peijie, et al. Multi-object tracking method for beef cattle based on DeepSORT algorithm[J]. Transactions of the Chinese Society for Agricultural Machinery, 2021, 52(4): 249-256. (in Chinese with English abstract)
[40] 張偉,沈明霞,劉龍申,等. 基于CenterNet搭配優(yōu)化DeepSORT算法的斷奶仔豬目標(biāo)跟蹤方法研究[J]. 南京農(nóng)業(yè)大學(xué)學(xué)報,2021,44(5):973-981.
Zhang Wei, Shen Mingxia, Liu Longshen, et al. Research on weaned piglet target tracking method based on CenterNet collocation optimized DeepSORT algorithm[J]. Journal of Nanjing Agricultural University, 2021, 44(5): 973-981. (in Chinese with English abstract)
[41] Sun P Z, Cao J K, Jiang Y, et al. TransTrack: Multiple object tracking with transformer[EB/OL]. 2021-05-04, https://arxiv.org/abs/2012.15460v1.
[42] Psota E T, Schmidt T, Mote B, et al. Long-term tracking of group-housed livestock using keypoint detection and MAP estimation for individual animal identification[J]. Sensors (Basel), 2020, 20(13): 3670.
[43] Tu S Q,Yuan W J,Liang Y,et al. Automatic detection and segmentation for group-housed pigs based on PigMS R-CNN[J]. Sensors (Basel), 2021, 21(9): 3251.
Multiple object tracking of group-housed pigs based on JDE model
Tu Shuqin, Huang Lei, Liang Yun※, Huang Zhengxin, Li Chengjie, Liu Xiaolong
(,,510642,)
Pig production has been always the pillar of the industrial livestock industry in China. Therefore, the pig industry is closely related to food safety, social stability, and the coordinated development of the national economy. An intelligent video surveillance can greatly contribute to the large-scale production of animal husbandry under labor shortage at present. It is very necessary to accurately track and identify the abnormal behavior of group-housed pigs in the breeding scene. Much effort has been focused on Multiple Object Tracking (MOT) for pig detection and tracking. Among them, two parts are included in the Tracking By Detection (TBD) paradigm, e.g., the Separate Detection and Embedding (SDE) model. Previously, the detector has been developed to detect pig objects. And then the tracking models have been selected for the pig tracking using Kalman filter and Hungarian (Sort or DeepSORT). The detection and association steps have been designed to increase the running and training time of the model in the dominant MOT strategy. Thus, real-time tracking cannot fully meet the requirement of the group-housed pigs. In this study, a Joint Detection and Embedding (JDE) model was proposed to automatically detect the pig objects and then track each one in the complex scenes (day or night, sparse or dense). The core of JDE model was to integrate the detector and the embedding model into a single network for the real-time MOT system. Specifically, the JDE model incorporated the appearance model into a single-shot detector. As such, the simultaneous output was performed on the corresponding appearance to improve the runtime and operational efficiency of the model. An overall loss of one multiple task learning loss was utilized in the JDE model. Three loss functions were included classification, box regression and appearance. Three merits were achieved after operations. Firstly, the multiple tasks learning loss was used to realize the object detection and appearance to be learned in a shared model, in order to reduce the amount of occupied memory. Secondly, the forward operation was computed using the multiple tasks loss at one time. The overall inference time was reduced to improve the efficiency of the MOT system. Thirdly, the performance of each prediction head was promoted to share the same set of low-level features and feature pyramid network architecture. Finally, the data association module was utilized to process the outputs of the detection and appearance head from the JDE, in order to produce the position prediction and ID tracking of multiple objects. The JDE model was validated on the special dataset under a variety of settings. The special dataset was also built with a total of 21 video segments and 4 300 images using the dark label video annotation software. Two types of datasets were obtained, where the public dataset contained 11 video sequences and 3 300 images, and the private dataset contained 10 video segments and 1 000 images. The experimental results show that the mean Average Precision (mAP), Multiple Object Tracking Accuracies (MOTA), IDF1 score, and FPS of the JDE on all test videos were 92.9%, 83.9%, 79.6%, and 73.9 frames/s, respectively. A comparison was also made with the SDE model and TransTrack method on the public dataset. The JDE model improved the FPS by 340%, and the MOTA by 0.5 percentage points in the same test dataset, compared with the SDE model. It infers the sufficient real-time performance of MOT using the JDE model. The MOTA, IDF1 metrics, and FPS of the JDE model was improved by 10.4 and 6.6 percentage points, and 324%, respectively, compared with the TransTrack model. The visual tracking demonstrated that the JDE model performed the best detection and tracking ability with the SDE and TransTrack models under the four scenarios, including the dense day, sparse day, dense night, and sparse night. The finding can also provide an effective and accurate detection for the rapid tracking of group-housed pigs in complex farming scenes.
object detection; object tracking; joint detection and tracking; data association; group-housed pigs
10.11975/j.issn.1002-6819.2022.17.020
TP391.4
A
1002-6819(2022)-17-0186-10
涂淑琴,黃磊,梁云,等. 基于JDE模型的群養(yǎng)生豬多目標(biāo)跟蹤[J]. 農(nóng)業(yè)工程學(xué)報,2022,38(17):186-195.doi:10.11975/j.issn.1002-6819.2022.17.020 http://www.tcsae.org
Tu Shuqin, Huang Lei, Liang Yun, et al. Multiple object tracking of group-housed pigs based on JDE model[J]. Transactions of the Chinese Society of Agricultural Engineering (Transactions of the CSAE), 2022, 38(17): 186-195. (in Chinese with English abstract) doi:10.11975/j.issn.1002-6819.2022.17.020 http://www.tcsae.org
2022-04-19
2022-08-16
廣東省省級科技計(jì)劃項(xiàng)目(2019A050510034);廣州市重點(diǎn)科技計(jì)劃項(xiàng)目(202206010091);大學(xué)生創(chuàng)新創(chuàng)業(yè)大賽項(xiàng)目(202110564025)
涂淑琴,博士,講師,研究方向?yàn)閳D像處理與計(jì)算機(jī)視覺。Email:tushuqin@163.com
梁云,博士,教授,研究方向?yàn)閳D像處理與計(jì)算機(jī)視覺。Email:yliang@scau.edu.cn