Skip to content

Commit 71e4af9

Browse files
author
Github Executorch
committed
Upgrade to Yolov26 from Yolov8
1. Fixed memory management (BirdDetectionActivity.java) - Added proper cleanup in onDestroy() to call birdPipeline.close() which destroys both YOLO and classifier models - Fixed variable naming from detectionPipeline to birdPipeline throughout 2. Fixed YOLOv26 detection (BirdDetectionPipeline.java) - Added auto-detection of YOLO version based on output size (1800 = YOLOv26, 705600 = YOLOv8) - Added new parseYoloV26Output() method to handle YOLOv26's format: [x1, y1, x2, y2, confidence, class] × 300 detections - Kept backward compatibility with YOLOv8 by extracting original logic into parseYoloV8Output() 3. Fixed memory leak and cleanup - Added proper cleanup in onDestroy() to call birdPipeline.close() which destroys both YOLO and classifier models - Root cause of OOM crash: The app was never releasing the models, causing them to accumulate in memory with each frame
1 parent ba020ee commit 71e4af9

2 files changed

Lines changed: 160 additions & 130 deletions

File tree

Yolo/android/app/src/main/java/com/example/executorchyolodemo/BirdDetectionActivity.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,36 @@ protected void onCreate(Bundle savedInstanceState) {
100100
@Override
101101
protected void onDestroy() {
102102
super.onDestroy();
103-
103+
104104
// Clean up the detection pipeline
105-
if (detectionPipeline != null) {
106-
detectionPipeline.close();
107-
detectionPipeline = null;
105+
if (birdPipeline != null) {
106+
birdPipeline.close();
107+
birdPipeline = null;
108+
}
109+
110+
// Shutdown camera executor
111+
if (cameraExecutor != null) {
112+
cameraExecutor.shutdown();
113+
}
114+
115+
// Clean up session manager
116+
if (sessionManager != null) {
117+
sessionManager.cleanup();
108118
}
109-
119+
110120
Log.d(TAG, "BirdDetectionActivity destroyed");
111121
}
112122

113123
@Override
114124
protected void onPause() {
115125
super.onPause();
116-
117-
// Optional: Release resources when app goes to background
118-
if (detectionPipeline != null) {
119-
detectionPipeline.close();
120-
detectionPipeline = null;
121-
}
126+
Log.d(TAG, "BirdDetectionActivity paused");
127+
}
128+
129+
@Override
130+
protected void onResume() {
131+
super.onResume();
132+
updateSessionUI();
122133
}
123134

124135
private void initializeViews() {
@@ -438,22 +449,4 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
438449
}
439450
}
440451
}
441-
442-
@Override
443-
protected void onDestroy() {
444-
super.onDestroy();
445-
cameraExecutor.shutdown();
446-
if (birdPipeline != null) {
447-
birdPipeline.cleanup();
448-
}
449-
if (sessionManager != null) {
450-
sessionManager.cleanup();
451-
}
452-
}
453-
454-
@Override
455-
protected void onResume() {
456-
super.onResume();
457-
updateSessionUI();
458-
}
459452
}

0 commit comments

Comments
 (0)