Skip to content

Commit

Permalink
Merge pull request #229 from st-tuanmai/update/ios_object_detecter
Browse files Browse the repository at this point in the history
Update ios object detection to add inference time and update pod to 0.10.5
  • Loading branch information
khanhlvg authored Sep 21, 2023
2 parents 510664c + 84019f5 commit 54d2a65
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import UIKit

protocol InferenceViewControllerDelegate: AnyObject {
protocol BottomSheetViewControllerDelegate: AnyObject {
/**
This method is called when the user opens or closes the bottom sheet.
**/
Expand All @@ -36,7 +36,7 @@ class BottomSheetViewController: UIViewController {
}

// MARK: Delegates
weak var delegate: InferenceViewControllerDelegate?
weak var delegate: BottomSheetViewControllerDelegate?

// MARK: Storyboards Connections
@IBOutlet weak var choseModelButton: UIButton!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MediaLibraryViewController: UIViewController {
}
// MARK: Object Detector Service
weak var interfaceUpdatesDelegate: InterfaceUpdatesDelegate?
weak var inferenceResultDeliveryDelegate: InferenceResultDeliveryDelegate?

// MARK: Controllers that manage functionality
private lazy var pickerController = UIImagePickerController()
Expand Down Expand Up @@ -235,7 +236,9 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat
inferenceIntervalInMilliseconds: Constants.inferenceTimeIntervalInMilliseconds)

hideProgressView()

DispatchQueue.main.async {
self.inferenceResultDeliveryDelegate?.didPerformInference(result: resultBundle)
}
playVideo(
mediaURL: mediaURL,
videoDuration: videoDuration,
Expand All @@ -257,10 +260,11 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat

DispatchQueue.global(qos: .userInteractive).async { [weak self] in
guard let weakSelf = self,
let objectDetectorResult = weakSelf
let resultBundle = weakSelf
.objectDetectorService?
.detect(image: image)?
.objectDetectorResults.first as? ObjectDetectorResult else {
.detect(image: image),
let objectDetectorResult =
resultBundle.objectDetectorResults.first as? ObjectDetectorResult else {
DispatchQueue.main.async {
self?.hideProgressView()
}
Expand All @@ -269,6 +273,7 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat

DispatchQueue.main.async {
weakSelf.hideProgressView()
weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: resultBundle)
weakSelf.overlayView.draw(
objectOverlays:OverlayView.objectOverlays(
fromDetections: objectDetectorResult.detections,
Expand Down Expand Up @@ -362,6 +367,7 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat
}
}

// MARK: ObjectDetectorServiceVideoDelegate
extension MediaLibraryViewController: ObjectDetectorServiceVideoDelegate {

func objectDetectorService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class RootViewController: UIViewController {
}

viewController.interfaceUpdatesDelegate = self
viewController.inferenceResultDeliveryDelegate = self
mediaLibraryViewController = viewController
}

Expand Down Expand Up @@ -227,8 +228,8 @@ extension RootViewController: InterfaceUpdatesDelegate {
}
}

// MARK: InferenceViewControllerDelegate Methods
extension RootViewController: InferenceViewControllerDelegate {
// MARK: BottomSheetViewControllerDelegate Methods
extension RootViewController: BottomSheetViewControllerDelegate {
func viewController(
_ viewController: BottomSheetViewController,
didSwitchBottomSheetViewState isOpen: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ final class ObjectDetectorTests: XCTestCase {

static let efficientnetLite0Results: [Detection] = [
Detection(
categories: [ResultCategory(index: -1, score: 0.94170237, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 214.0, y: 12.0, width: 120.0, height: 261.0),
categories: [ResultCategory(index: -1, score: 0.9396609, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 214.0, y: 11.0, width: 120.0, height: 262.0),
keypoints: nil),
Detection(
categories: [ResultCategory(index: -1, score: 0.7796736, categoryName: "dog", displayName: nil)],
boundingBox: CGRect(x: 66.0, y: 254.0, width: 56.0, height: 76.0),
categories: [ResultCategory(index: -1, score: 0.77432173, categoryName: "dog", displayName: nil)],
boundingBox: CGRect(x: 66.0, y: 254.0, width: 57.0, height: 77.0),
keypoints: nil),
Detection(
categories: [ResultCategory(index: -1, score: 0.6708669, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 144.0, y: 18.0, width: 82.0, height: 242.0),
categories: [ResultCategory(index: -1, score: 0.6645179, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 144.0, y: 18.0, width: 82.0, height: 243.0),
keypoints: nil)
]

Expand All @@ -45,8 +45,8 @@ final class ObjectDetectorTests: XCTestCase {
boundingBox: CGRect(x: 71.0, y: 254.0, width: 53.0, height: 74.0),
keypoints: nil),
Detection(
categories: [ResultCategory(index: -1, score: 0.90384406, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 207.0, y: 8.0, width: 126.0, height: 264.0),
categories: [ResultCategory(index: -1, score: 0.90494984, categoryName: "person", displayName: nil)],
boundingBox: CGRect(x: 207.0, y: 8.0, width: 126.0, height: 263.0),
keypoints: nil),
Detection(
categories: [ResultCategory(index: -1, score: 0.810646474, categoryName: "person", displayName: nil)],
Expand Down
2 changes: 1 addition & 1 deletion examples/object_detection/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ platform :ios, '15.0'
target 'ObjectDetector' do

use_frameworks!
pod 'MediaPipeTasksVision', '0.10.3'
pod 'MediaPipeTasksVision', '0.10.5'

# Pods for ObjectDetector
end
Expand Down
14 changes: 7 additions & 7 deletions examples/object_detection/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
PODS:
- MediaPipeTasksCommon (0.10.3)
- MediaPipeTasksVision (0.10.3):
- MediaPipeTasksCommon (= 0.10.3)
- MediaPipeTasksCommon (0.10.5)
- MediaPipeTasksVision (0.10.5):
- MediaPipeTasksCommon (= 0.10.5)

DEPENDENCIES:
- MediaPipeTasksVision (= 0.10.3)
- MediaPipeTasksVision (= 0.10.5)

SPEC REPOS:
trunk:
- MediaPipeTasksCommon
- MediaPipeTasksVision

SPEC CHECKSUMS:
MediaPipeTasksCommon: 8377139fdc9b3e88898789197f2dba15457c2879
MediaPipeTasksVision: c0e0e8ea10966486cb4ce0d67e159165fb9d48e6
MediaPipeTasksCommon: 235e81afa9f7bd5b5b39f00a858bfb2539d1a52f
MediaPipeTasksVision: d58f3a82c9fbda8c3be1bf2a1bf4d73e56a457e3

PODFILE CHECKSUM: c69ac5ea605672a2497ed4d4f1ed09b61c33c95a
PODFILE CHECKSUM: 2e1cd95933b8c68f98c3d3290332c555b26ed4e5

COCOAPODS: 1.12.1

0 comments on commit 54d2a65

Please sign in to comment.