Skip to content

Commit 1c155df

Browse files
authored
Merge pull request #4 from LdDl/hungarian-matrix
matrix extension
2 parents c4499e5 + ce8bf88 commit 1c155df

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

data/blobs_bytetrack_naive.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
id;track
2-
d91bdf2e-819b-4915-8edb-dc4d44a502d7;222.000000,94.000000|222.990123,100.930811|221.925635,97.223448|221.424915,100.032976|221.101678,97.519032|220.462788,101.505580|220.919574,106.476751|221.266212,108.169195|221.517856,109.206323|221.340953,110.185572|221.213962,110.801645|221.122439,114.956035|221.353821,114.152431|221.535502,113.438609|221.949610,116.040568|222.020740,118.574446|222.074740,120.549566|222.359304,123.542159|222.353471,126.403898|222.107201,126.807446|222.353806,131.160062|222.790519,130.627929|223.161075,129.991568|223.471670,133.348650|223.728024,132.086040|223.711343,133.521686|223.903814,136.217789|224.057157,137.327026|224.175849,138.152231|224.040748,142.757541|224.578334,146.875245|225.037127,150.303113|224.527690,151.980995|224.956099,155.687916|224.425375,158.940989|225.287148,163.119125|225.587092,166.977610|224.938937,172.323355|225.247886,175.379554|225.510246,177.743357|224.611805,176.821524|225.154121,179.068733|225.628555,180.784977|226.036901,182.040514|226.382415,182.902881|226.669397,183.435601|226.902832,183.697295|227.088101,183.741126|227.230741,183.614522|227.336253,183.359122|227.409955,183.010896|227.456875,182.600398|227.481673,182.153113|227.488590,181.689871|227.481427,181.227300|227.463530,180.778293|227.437801,180.352483|227.406717,179.956696|227.372350,179.595386|227.336402,179.271040|227.300240,178.984548|227.264932,178.735534|227.231283,178.522646
3-
202cfb2c-bf43-4681-a0de-6f67c3abb484;307.000000,94.000000|307.990123,100.930811|306.925635,97.223448|306.424915,100.032976|306.101678,97.519032|305.462788,101.505580|305.919574,106.476751|306.266212,108.169195|306.517856,109.206323|306.340953,110.185572|306.213962,110.801645|306.122439,114.956035|306.353821,114.152431|306.535502,113.438609|306.949610,116.040568|307.020740,118.574446|307.074740,120.549566|307.359304,123.542159|307.353471,126.403898|307.107201,126.807446|307.353806,131.160062|307.790519,130.627929|308.161075,129.991568|308.471670,133.348650|308.728024,132.086040|308.711343,133.521686|308.903814,136.217789|309.057157,137.327026|309.175849,138.152231|309.040748,142.757541|309.578334,146.875245|310.037127,150.303113|309.527690,151.980995|309.956099,155.687916|309.425375,158.940989|310.287148,163.119125|310.587092,166.977610|309.938937,172.323355|310.247886,175.379554|310.510246,177.743357|309.611805,176.821524|310.154121,179.068733|310.628555,180.784977|311.036901,182.040514|311.382415,182.902881|311.669397,183.435601|311.902832,183.697295|312.088101,183.741126|312.230741,183.614522|312.336253,183.359122|312.409955,183.010896|312.456875,182.600398|312.481673,182.153113|312.488590,181.689871|312.481427,181.227300|312.463530,180.778293|312.437801,180.352483|312.406717,179.956696|312.372350,179.595386|312.336402,179.271040|312.300240,178.984548|312.264932,178.735534|312.231283,178.522646
4-
fb847f6b-9631-430e-a27a-4ce2366eb1ae;392.000000,94.000000|392.990123,100.930811|391.925635,97.223448|391.424915,100.032976|391.101678,97.519032|390.462788,101.505580|390.919574,106.476751|391.266212,108.169195|391.517856,109.206323|391.340953,110.185572|391.213962,110.801645|391.122439,114.956035|391.353821,114.152431|391.535502,113.438609|391.949610,116.040568|392.020740,118.574446|392.074740,120.549566|392.359304,123.542159|392.353471,126.403898|392.107201,126.807446|392.353806,131.160062|392.790519,130.627929|393.161075,129.991568|393.471670,133.348650|393.728024,132.086040|393.711343,133.521686|393.903814,136.217789|394.057157,137.327026|394.175849,138.152231|394.040748,142.757541|394.578334,146.875245|395.037127,150.303113|394.527690,151.980995|394.956099,155.687916|394.425375,158.940989|395.287148,163.119125|395.587092,166.977610|394.938937,172.323355|395.247886,175.379554|395.510246,177.743357|394.611805,176.821524|395.154121,179.068733|395.628555,180.784977|396.036901,182.040514|396.382415,182.902881|396.669397,183.435601|396.902832,183.697295|397.088101,183.741126|397.230741,183.614522|397.336253,183.359122|397.409955,183.010896|397.456875,182.600398|397.481673,182.153113|397.488590,181.689871|397.481427,181.227300|397.463530,180.778293|397.437801,180.352483|397.406717,179.956696|397.372350,179.595386|397.336402,179.271040|397.300240,178.984548|397.264932,178.735534|397.231283,178.522646
2+
47a3c463-0a9d-4dde-b50c-b7edecbd12e5;307.000000,94.000000|307.990123,100.930811|306.925635,97.223448|306.424915,100.032976|306.101678,97.519032|305.462788,101.505580|305.919574,106.476751|306.266212,108.169195|306.517856,109.206323|306.340953,110.185572|306.213962,110.801645|306.122439,114.956035|306.353821,114.152431|306.535502,113.438609|306.949610,116.040568|307.020740,118.574446|307.074740,120.549566|307.359304,123.542159|307.353471,126.403898|307.107201,126.807446|307.353806,131.160062|307.790519,130.627929|308.161075,129.991568|308.471670,133.348650|308.728024,132.086040|308.711343,133.521686|308.903814,136.217789|309.057157,137.327026|309.175849,138.152231|309.040748,142.757541|309.578334,146.875245|310.037127,150.303113|309.527690,151.980995|309.956099,155.687916|309.425375,158.940989|310.287148,163.119125|310.587092,166.977610|309.938937,172.323355|310.247886,175.379554|310.510246,177.743357|309.611805,176.821524|310.154121,179.068733|310.628555,180.784977|311.036901,182.040514|311.382415,182.902881|311.669397,183.435601|311.902832,183.697295|312.088101,183.741126|312.230741,183.614522|312.336253,183.359122|312.409955,183.010896|312.456875,182.600398|312.481673,182.153113|312.488590,181.689871|312.481427,181.227300|312.463530,180.778293|312.437801,180.352483|312.406717,179.956696|312.372350,179.595386|312.336402,179.271040|312.300240,178.984548|312.264932,178.735534|312.231283,178.522646
3+
ba11410a-5f76-479e-bf37-b80a32043e87;392.000000,94.000000|392.990123,100.930811|391.925635,97.223448|391.424915,100.032976|391.101678,97.519032|390.462788,101.505580|390.919574,106.476751|391.266212,108.169195|391.517856,109.206323|391.340953,110.185572|391.213962,110.801645|391.122439,114.956035|391.353821,114.152431|391.535502,113.438609|391.949610,116.040568|392.020740,118.574446|392.074740,120.549566|392.359304,123.542159|392.353471,126.403898|392.107201,126.807446|392.353806,131.160062|392.790519,130.627929|393.161075,129.991568|393.471670,133.348650|393.728024,132.086040|393.711343,133.521686|393.903814,136.217789|394.057157,137.327026|394.175849,138.152231|394.040748,142.757541|394.578334,146.875245|395.037127,150.303113|394.527690,151.980995|394.956099,155.687916|394.425375,158.940989|395.287148,163.119125|395.587092,166.977610|394.938937,172.323355|395.247886,175.379554|395.510246,177.743357|394.611805,176.821524|395.154121,179.068733|395.628555,180.784977|396.036901,182.040514|396.382415,182.902881|396.669397,183.435601|396.902832,183.697295|397.088101,183.741126|397.230741,183.614522|397.336253,183.359122|397.409955,183.010896|397.456875,182.600398|397.481673,182.153113|397.488590,181.689871|397.481427,181.227300|397.463530,180.778293|397.437801,180.352483|397.406717,179.956696|397.372350,179.595386|397.336402,179.271040|397.300240,178.984548|397.264932,178.735534|397.231283,178.522646
4+
2b1ccc90-7b86-415a-84f5-980b0b6c40d9;222.000000,94.000000|222.990123,100.930811|221.925635,97.223448|221.424915,100.032976|221.101678,97.519032|220.462788,101.505580|220.919574,106.476751|221.266212,108.169195|221.517856,109.206323|221.340953,110.185572|221.213962,110.801645|221.122439,114.956035|221.353821,114.152431|221.535502,113.438609|221.949610,116.040568|222.020740,118.574446|222.074740,120.549566|222.359304,123.542159|222.353471,126.403898|222.107201,126.807446|222.353806,131.160062|222.790519,130.627929|223.161075,129.991568|223.471670,133.348650|223.728024,132.086040|223.711343,133.521686|223.903814,136.217789|224.057157,137.327026|224.175849,138.152231|224.040748,142.757541|224.578334,146.875245|225.037127,150.303113|224.527690,151.980995|224.956099,155.687916|224.425375,158.940989|225.287148,163.119125|225.587092,166.977610|224.938937,172.323355|225.247886,175.379554|225.510246,177.743357|224.611805,176.821524|225.154121,179.068733|225.628555,180.784977|226.036901,182.040514|226.382415,182.902881|226.669397,183.435601|226.902832,183.697295|227.088101,183.741126|227.230741,183.614522|227.336253,183.359122|227.409955,183.010896|227.456875,182.600398|227.481673,182.153113|227.488590,181.689871|227.481427,181.227300|227.463530,180.778293|227.437801,180.352483|227.406717,179.956696|227.372350,179.595386|227.336402,179.271040|227.300240,178.984548|227.264932,178.735534|227.231283,178.522646

data/blobs_bytetrack_spread.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id;track
2-
e5786ee9-a46e-443e-93cb-47b6415e0b91;186.500000,150.000000|181.549434,151.485180|179.912933,150.155802|178.458485,148.391347|176.813962,166.181001|172.823733,178.210710|167.802060,186.130153|137.218642,232.119702|133.400992,254.043957|129.372239,266.540088|126.596580,274.351364|123.999385,280.839323
3-
9672f439-9bdd-49a3-9144-9d044ab6d3e9;772.000000,224.500000|772.990469,224.500124|772.195209,225.578774|775.247668,226.315997|776.449317,241.705677|778.974435,252.766930|781.688886,260.465317|783.219314,266.151348|785.110277,268.627950|785.805579,271.577908|785.377702,272.550347|786.399140,273.779744|786.216920,275.065889
4-
3a20dfbd-de37-48a3-8950-2ead6bd64661;432.500000,29.000000|433.985180,27.019779|433.727432,27.812544|434.062690,28.414910|434.524344,29.492079|435.065588,30.890034|435.200776,32.010961|434.858985,32.708982|434.988828,33.895913|435.355192,40.199483|435.687957,43.560490|435.743248,45.453295|435.781809,47.077214|435.948411,48.097233|435.806217,48.681484
5-
6e2e3b7d-eb3b-42b4-a311-d457fef1d29f;464.500000,268.500000|464.004951,273.450581|464.003043,278.036284|464.230913,286.350038|464.162218,294.010330|465.897375,303.495010|467.308316,314.497749|466.592426,329.463501|465.855493,340.809821|466.565291,349.866184|468.071886,359.731017|468.854037,368.570750|468.825075,379.069889|468.775620,388.647189|468.307459,398.347595|468.560606,408.011484|468.624432,415.762559|469.025979,424.188056|469.702158,432.449920|470.252498,439.876711|471.042259,446.147190|471.804332,451.792390|473.106860,456.014433
2+
8be24575-71af-4813-be9c-b2e68c437905;464.500000,268.500000|464.004951,273.450581|464.003043,278.036284|464.230913,286.350038|464.162218,294.010330|465.897375,303.495010|467.308316,314.497749|466.592426,329.463501|465.855493,340.809821|466.565291,349.866184|468.071886,359.731017|468.854037,368.570750|468.825075,379.069889|468.775620,388.647189|468.307459,398.347595|468.560606,408.011484|468.624432,415.762559|469.025979,424.188056|469.702158,432.449920|470.252498,439.876711|471.042259,446.147190|471.804332,451.792390|473.106860,456.014433
3+
ce8d2daf-cc06-481c-84f7-795fe5015741;186.500000,150.000000|181.549434,151.485180|179.912933,150.155802|178.458485,148.391347|176.813962,166.181001|172.823733,178.210710|167.802060,186.130153|137.218642,232.119702|133.400992,254.043957|129.372239,266.540088|126.596580,274.351364|123.999385,280.839323
4+
df903917-df13-4fc6-95fe-00718dbf6582;772.000000,224.500000|772.990469,224.500124|772.195209,225.578774|775.247668,226.315997|776.449317,241.705677|778.974435,252.766930|781.688886,260.465317|783.219314,266.151348|785.110277,268.627950|785.805579,271.577908|785.377702,272.550347|786.399140,273.779744|786.216920,275.065889
5+
b96a1e1f-56a0-4562-abf8-c55593b83de0;432.500000,29.000000|433.985180,27.019779|433.727432,27.812544|434.062690,28.414910|434.524344,29.492079|435.065588,30.890034|435.200776,32.010961|434.858985,32.708982|434.988828,33.895913|435.355192,40.199483|435.687957,43.560490|435.743248,45.453295|435.781809,47.077214|435.948411,48.097233|435.806217,48.681484
-275 Bytes
Loading
-6 Bytes
Loading

mot/bytetrack.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,37 @@ func (bt *ByteTracker) performMatching(
232232
if len(trackBBoxes) == 0 || len(detectionIndices) == 0 {
233233
return [][2]int{}
234234
}
235-
// Check if rows <= columns requirement is met for Hungarian
236-
if len(trackBBoxes) > len(detectionIndices) {
237-
// Fall back to greedy if we have more tracks than detections
238-
return bt.performGreedyMatching(iouMatrix, trackBBoxes, detectionIndices)
235+
numTracks := len(trackBBoxes)
236+
numDetections := len(detectionIndices)
237+
238+
var paddedMatrix [][]float64
239+
var actualNumTracks, actualNumDetections int
240+
if numTracks == numDetections {
241+
// Square matrix - use as is
242+
paddedMatrix = iouMatrix
243+
actualNumTracks = numTracks
244+
actualNumDetections = numDetections
245+
} else {
246+
// Rectangular matrix - pad to make it square
247+
paddedSize := maxInt(numTracks, numDetections)
248+
paddedMatrix = make([][]float64, paddedSize)
249+
// Initialize with zeros (dummy IoU values)
250+
for i := 0; i < paddedSize; i++ {
251+
paddedMatrix[i] = make([]float64, paddedSize)
252+
}
253+
// Copy original IoU values
254+
for i := 0; i < numTracks; i++ {
255+
for j := 0; j < numDetections; j++ {
256+
paddedMatrix[i][j] = iouMatrix[i][j]
257+
}
258+
}
259+
// Padding is done with 0.0 values (lowest IoU)
260+
// No need to explicitly set them as make() initializes with zero values
261+
actualNumTracks = numTracks
262+
actualNumDetections = numDetections
239263
}
240264
// Apply Hungarian algorithm
241-
assignmentsMap := hungarian.SolveMax(iouMatrix)
265+
assignmentsMap := hungarian.SolveMax(paddedMatrix)
242266
// Convert map[int]map[int]float64 to [][2]int
243267
matches := make([][2]int, 0)
244268
for trackIndex, rowMap := range assignmentsMap {
@@ -250,7 +274,7 @@ func (bt *ByteTracker) performMatching(
250274
break
251275
}
252276
// Ensure trackIndex and detectionIndex are within bounds of the current stage's slices
253-
if trackIndex < len(trackBBoxes) && detectionIndex < len(detectionIndices) {
277+
if trackIndex < actualNumTracks && detectionIndex < actualNumDetections {
254278
// @todo: maybe we should check the original IoU value here?
255279
// originalIoU := rowMap[detectionIndex]
256280
// if originalIoU >= bt.minIoU {

mot/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ func minFloat64(a, b float64) float64 {
3636
}
3737
return b
3838
}
39+
40+
func maxInt(a, b int) int {
41+
if a > b {
42+
return a
43+
}
44+
return b
45+
}

0 commit comments

Comments
 (0)