├── .gitignore ├── README.md ├── benchmark.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── xcshareddata │ └── xcschemes │ │ └── benchmark.xcscheme └── xcuserdata │ └── eliotandres.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── benchmark ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── DeepLab.mlmodel ├── Info.plist ├── UIImage+CVPixelBuffer.swift ├── ViewController.swift ├── benchmark_iphone_11.jpg └── cat.jpg └── benchmark_iphone_11.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Core ML Benchmark 2 | ![demo](benchmark_iphone_11.jpg) 3 | Benchmarking Deeplab's performance using Core ML on the iPhone 11 and previous devices 4 | 5 | ## Running it 6 | 7 | Most of the important code is in `benchmark/ViewController.swift`. 8 | 9 | We simply load the model and the input data on initialization. 10 | When the button is pressed, we run inference several time. When the process is done, we display the number of images per seconds. 11 | 12 | -------------------------------------------------------------------------------- /benchmark.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F1E1D6362334CB910067DAFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E1D6352334CB910067DAFC /* AppDelegate.swift */; }; 11 | F1E1D63A2334CB910067DAFC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E1D6392334CB910067DAFC /* ViewController.swift */; }; 12 | F1E1D63D2334CB910067DAFC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1E1D63B2334CB910067DAFC /* Main.storyboard */; }; 13 | F1E1D63F2334CB930067DAFC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F1E1D63E2334CB930067DAFC /* Assets.xcassets */; }; 14 | F1E1D6422334CB930067DAFC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1E1D6402334CB930067DAFC /* LaunchScreen.storyboard */; }; 15 | F1E1D65223355AFE0067DAFC /* DeepLab.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = F1E1D64F23355AFE0067DAFC /* DeepLab.mlmodel */; }; 16 | F1E1D65323355AFE0067DAFC /* UIImage+CVPixelBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E1D65023355AFE0067DAFC /* UIImage+CVPixelBuffer.swift */; }; 17 | F1E1D65423355AFE0067DAFC /* cat.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F1E1D65123355AFE0067DAFC /* cat.jpg */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | F1E1D6322334CB910067DAFC /* benchmark.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = benchmark.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | F1E1D6352334CB910067DAFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | F1E1D6392334CB910067DAFC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | F1E1D63C2334CB910067DAFC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | F1E1D63E2334CB930067DAFC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | F1E1D6412334CB930067DAFC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | F1E1D6432334CB930067DAFC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | F1E1D64F23355AFE0067DAFC /* DeepLab.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = DeepLab.mlmodel; sourceTree = ""; }; 29 | F1E1D65023355AFE0067DAFC /* UIImage+CVPixelBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+CVPixelBuffer.swift"; sourceTree = ""; }; 30 | F1E1D65123355AFE0067DAFC /* cat.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = cat.jpg; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | F1E1D62F2334CB910067DAFC /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | F1E1D6292334CB910067DAFC = { 45 | isa = PBXGroup; 46 | children = ( 47 | F1E1D6342334CB910067DAFC /* benchmark */, 48 | F1E1D6332334CB910067DAFC /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | F1E1D6332334CB910067DAFC /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | F1E1D6322334CB910067DAFC /* benchmark.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | F1E1D6342334CB910067DAFC /* benchmark */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | F1E1D6352334CB910067DAFC /* AppDelegate.swift */, 64 | F1E1D6392334CB910067DAFC /* ViewController.swift */, 65 | F1E1D63B2334CB910067DAFC /* Main.storyboard */, 66 | F1E1D63E2334CB930067DAFC /* Assets.xcassets */, 67 | F1E1D6402334CB930067DAFC /* LaunchScreen.storyboard */, 68 | F1E1D6432334CB930067DAFC /* Info.plist */, 69 | F1E1D65123355AFE0067DAFC /* cat.jpg */, 70 | F1E1D64F23355AFE0067DAFC /* DeepLab.mlmodel */, 71 | F1E1D65023355AFE0067DAFC /* UIImage+CVPixelBuffer.swift */, 72 | ); 73 | path = benchmark; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | F1E1D6312334CB910067DAFC /* benchmark */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = F1E1D6462334CB930067DAFC /* Build configuration list for PBXNativeTarget "benchmark" */; 82 | buildPhases = ( 83 | F1E1D62E2334CB910067DAFC /* Sources */, 84 | F1E1D62F2334CB910067DAFC /* Frameworks */, 85 | F1E1D6302334CB910067DAFC /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = benchmark; 92 | productName = benchmark; 93 | productReference = F1E1D6322334CB910067DAFC /* benchmark.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | F1E1D62A2334CB910067DAFC /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | LastSwiftUpdateCheck = 1100; 103 | LastUpgradeCheck = 1100; 104 | ORGANIZATIONNAME = "Eliot Andres"; 105 | TargetAttributes = { 106 | F1E1D6312334CB910067DAFC = { 107 | CreatedOnToolsVersion = 11.0; 108 | }; 109 | }; 110 | }; 111 | buildConfigurationList = F1E1D62D2334CB910067DAFC /* Build configuration list for PBXProject "benchmark" */; 112 | compatibilityVersion = "Xcode 9.3"; 113 | developmentRegion = en; 114 | hasScannedForEncodings = 0; 115 | knownRegions = ( 116 | en, 117 | Base, 118 | ); 119 | mainGroup = F1E1D6292334CB910067DAFC; 120 | productRefGroup = F1E1D6332334CB910067DAFC /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | F1E1D6312334CB910067DAFC /* benchmark */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | F1E1D6302334CB910067DAFC /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | F1E1D6422334CB930067DAFC /* LaunchScreen.storyboard in Resources */, 135 | F1E1D63F2334CB930067DAFC /* Assets.xcassets in Resources */, 136 | F1E1D65423355AFE0067DAFC /* cat.jpg in Resources */, 137 | F1E1D63D2334CB910067DAFC /* Main.storyboard in Resources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXResourcesBuildPhase section */ 142 | 143 | /* Begin PBXSourcesBuildPhase section */ 144 | F1E1D62E2334CB910067DAFC /* Sources */ = { 145 | isa = PBXSourcesBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | F1E1D65223355AFE0067DAFC /* DeepLab.mlmodel in Sources */, 149 | F1E1D63A2334CB910067DAFC /* ViewController.swift in Sources */, 150 | F1E1D6362334CB910067DAFC /* AppDelegate.swift in Sources */, 151 | F1E1D65323355AFE0067DAFC /* UIImage+CVPixelBuffer.swift in Sources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXSourcesBuildPhase section */ 156 | 157 | /* Begin PBXVariantGroup section */ 158 | F1E1D63B2334CB910067DAFC /* Main.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | F1E1D63C2334CB910067DAFC /* Base */, 162 | ); 163 | name = Main.storyboard; 164 | sourceTree = ""; 165 | }; 166 | F1E1D6402334CB930067DAFC /* LaunchScreen.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | F1E1D6412334CB930067DAFC /* Base */, 170 | ); 171 | name = LaunchScreen.storyboard; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXVariantGroup section */ 175 | 176 | /* Begin XCBuildConfiguration section */ 177 | F1E1D6442334CB930067DAFC /* Debug */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_ANALYZER_NONNULL = YES; 182 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_ENABLE_OBJC_WEAK = YES; 188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_COMMA = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 194 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 195 | CLANG_WARN_EMPTY_BODY = YES; 196 | CLANG_WARN_ENUM_CONVERSION = YES; 197 | CLANG_WARN_INFINITE_RECURSION = YES; 198 | CLANG_WARN_INT_CONVERSION = YES; 199 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 200 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 201 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 204 | CLANG_WARN_STRICT_PROTOTYPES = YES; 205 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 206 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 207 | CLANG_WARN_UNREACHABLE_CODE = YES; 208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 209 | COPY_PHASE_STRIP = NO; 210 | DEBUG_INFORMATION_FORMAT = dwarf; 211 | ENABLE_STRICT_OBJC_MSGSEND = YES; 212 | ENABLE_TESTABILITY = YES; 213 | GCC_C_LANGUAGE_STANDARD = gnu11; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_NO_COMMON_BLOCKS = YES; 216 | GCC_OPTIMIZATION_LEVEL = 0; 217 | GCC_PREPROCESSOR_DEFINITIONS = ( 218 | "DEBUG=1", 219 | "$(inherited)", 220 | ); 221 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 223 | GCC_WARN_UNDECLARED_SELECTOR = YES; 224 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 225 | GCC_WARN_UNUSED_FUNCTION = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 228 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 229 | MTL_FAST_MATH = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 233 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 234 | }; 235 | name = Debug; 236 | }; 237 | F1E1D6452334CB930067DAFC /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_ENABLE_OBJC_WEAK = YES; 248 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 249 | CLANG_WARN_BOOL_CONVERSION = YES; 250 | CLANG_WARN_COMMA = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 254 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 255 | CLANG_WARN_EMPTY_BODY = YES; 256 | CLANG_WARN_ENUM_CONVERSION = YES; 257 | CLANG_WARN_INFINITE_RECURSION = YES; 258 | CLANG_WARN_INT_CONVERSION = YES; 259 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 260 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 261 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 264 | CLANG_WARN_STRICT_PROTOTYPES = YES; 265 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | MTL_FAST_MATH = YES; 284 | SDKROOT = iphoneos; 285 | SWIFT_COMPILATION_MODE = wholemodule; 286 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 287 | VALIDATE_PRODUCT = YES; 288 | }; 289 | name = Release; 290 | }; 291 | F1E1D6472334CB930067DAFC /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_STYLE = Automatic; 296 | INFOPLIST_FILE = benchmark/Info.plist; 297 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 298 | LD_RUNPATH_SEARCH_PATHS = ( 299 | "$(inherited)", 300 | "@executable_path/Frameworks", 301 | ); 302 | PRODUCT_BUNDLE_IDENTIFIER = ai.artizans.benchmark; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_VERSION = 5.0; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | }; 307 | name = Debug; 308 | }; 309 | F1E1D6482334CB930067DAFC /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 313 | CODE_SIGN_STYLE = Automatic; 314 | INFOPLIST_FILE = benchmark/Info.plist; 315 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 316 | LD_RUNPATH_SEARCH_PATHS = ( 317 | "$(inherited)", 318 | "@executable_path/Frameworks", 319 | ); 320 | PRODUCT_BUNDLE_IDENTIFIER = ai.artizans.benchmark; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | SWIFT_VERSION = 5.0; 323 | TARGETED_DEVICE_FAMILY = "1,2"; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | F1E1D62D2334CB910067DAFC /* Build configuration list for PBXProject "benchmark" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | F1E1D6442334CB930067DAFC /* Debug */, 334 | F1E1D6452334CB930067DAFC /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | F1E1D6462334CB930067DAFC /* Build configuration list for PBXNativeTarget "benchmark" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | F1E1D6472334CB930067DAFC /* Debug */, 343 | F1E1D6482334CB930067DAFC /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | }; 350 | rootObject = F1E1D62A2334CB910067DAFC /* Project object */; 351 | } 352 | -------------------------------------------------------------------------------- /benchmark.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /benchmark.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /benchmark.xcodeproj/xcshareddata/xcschemes/benchmark.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /benchmark.xcodeproj/xcuserdata/eliotandres.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | benchmark.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /benchmark/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // benchmark 4 | // 5 | // Created by Eliot Andres on 9/20/19. 6 | // Copyright © 2019 Eliot Andres. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | var window: UIWindow? 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /benchmark/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /benchmark/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /benchmark/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /benchmark/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /benchmark/DeepLab.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Photoroom/coreml-benchmark/f6ffdf6400c975a7c02753de3e7cd56b05cf7c66/benchmark/DeepLab.mlmodel -------------------------------------------------------------------------------- /benchmark/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /benchmark/UIImage+CVPixelBuffer.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017-2019 M.I. Hollemans 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in 10 | all copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 16 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 17 | IN THE SOFTWARE. 18 | */ 19 | 20 | import UIKit 21 | import VideoToolbox 22 | 23 | extension UIImage { 24 | /** 25 | Resizes the image to width x height and converts it to an RGB CVPixelBuffer. 26 | */ 27 | public func pixelBuffer(width: Int, height: Int) -> CVPixelBuffer? { 28 | return pixelBuffer(width: width, height: height, 29 | pixelFormatType: kCVPixelFormatType_32ARGB, 30 | colorSpace: CGColorSpaceCreateDeviceRGB(), 31 | alphaInfo: .noneSkipFirst) 32 | } 33 | 34 | /** 35 | Resizes the image to width x height and converts it to a grayscale CVPixelBuffer. 36 | */ 37 | public func pixelBufferGray(width: Int, height: Int) -> CVPixelBuffer? { 38 | return pixelBuffer(width: width, height: height, 39 | pixelFormatType: kCVPixelFormatType_OneComponent8, 40 | colorSpace: CGColorSpaceCreateDeviceGray(), 41 | alphaInfo: .none) 42 | } 43 | 44 | func pixelBuffer(width: Int, height: Int, pixelFormatType: OSType, 45 | colorSpace: CGColorSpace, alphaInfo: CGImageAlphaInfo) -> CVPixelBuffer? { 46 | var maybePixelBuffer: CVPixelBuffer? 47 | let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, 48 | kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] 49 | let status = CVPixelBufferCreate(kCFAllocatorDefault, 50 | width, 51 | height, 52 | pixelFormatType, 53 | attrs as CFDictionary, 54 | &maybePixelBuffer) 55 | 56 | guard status == kCVReturnSuccess, let pixelBuffer = maybePixelBuffer else { 57 | return nil 58 | } 59 | 60 | let flags = CVPixelBufferLockFlags(rawValue: 0) 61 | guard kCVReturnSuccess == CVPixelBufferLockBaseAddress(pixelBuffer, flags) else { 62 | return nil 63 | } 64 | defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, flags) } 65 | 66 | guard let context = CGContext(data: CVPixelBufferGetBaseAddress(pixelBuffer), 67 | width: width, 68 | height: height, 69 | bitsPerComponent: 8, 70 | bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), 71 | space: colorSpace, 72 | bitmapInfo: alphaInfo.rawValue) 73 | else { 74 | return nil 75 | } 76 | 77 | UIGraphicsPushContext(context) 78 | context.translateBy(x: 0, y: CGFloat(height)) 79 | context.scaleBy(x: 1, y: -1) 80 | self.draw(in: CGRect(x: 0, y: 0, width: width, height: height)) 81 | UIGraphicsPopContext() 82 | 83 | return pixelBuffer 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /benchmark/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // benchmark 4 | // 5 | // Created by Eliot Andres on 9/20/19. 6 | // Copyright © 2019 Eliot Andres. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet weak var label: UILabel! 13 | @IBOutlet weak var button: UIButton! 14 | 15 | var inputData: CVPixelBuffer? 16 | let deeplab = DeepLab() 17 | let size = 513 18 | let numRuns = 10 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | button.addTarget(self, action: #selector(startBenchmark), for: .touchUpInside) 23 | label.text = "" 24 | 25 | let image = #imageLiteral(resourceName: "cat.jpg") 26 | self.inputData = image.pixelBuffer(width: size, height: size) 27 | } 28 | 29 | @objc func startBenchmark() { 30 | label.text = "Loading..." 31 | DispatchQueue.global(qos: .userInitiated).async { 32 | self.benchmark() 33 | } 34 | 35 | } 36 | 37 | func benchmark() { 38 | let start = Date() 39 | 40 | for i in 1...numRuns { 41 | do { 42 | print(i) 43 | let result = try deeplab.prediction(image: self.inputData!) 44 | } catch let error { 45 | print(error.localizedDescription) 46 | } 47 | 48 | } 49 | 50 | let end = Date() 51 | let executionTime = end.timeIntervalSince(start) 52 | let imagesPerSecond = Double(numRuns) / executionTime 53 | 54 | DispatchQueue.main.async { 55 | self.label.text = String(format: "%.2f images/second", imagesPerSecond) 56 | } 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /benchmark/benchmark_iphone_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Photoroom/coreml-benchmark/f6ffdf6400c975a7c02753de3e7cd56b05cf7c66/benchmark/benchmark_iphone_11.jpg -------------------------------------------------------------------------------- /benchmark/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Photoroom/coreml-benchmark/f6ffdf6400c975a7c02753de3e7cd56b05cf7c66/benchmark/cat.jpg -------------------------------------------------------------------------------- /benchmark_iphone_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Photoroom/coreml-benchmark/f6ffdf6400c975a7c02753de3e7cd56b05cf7c66/benchmark_iphone_11.jpg --------------------------------------------------------------------------------