├── CoreMLDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── simon.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── simon.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── CoreMLDemo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── CoreMLDemoStarter.zip ├── Inceptionv3.mlmodel └── README.md /CoreMLDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F44543791EF0461F0024AFAC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44543781EF0461F0024AFAC /* AppDelegate.swift */; }; 11 | F445437B1EF0461F0024AFAC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F445437A1EF0461F0024AFAC /* ViewController.swift */; }; 12 | F445437E1EF0461F0024AFAC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F445437C1EF0461F0024AFAC /* Main.storyboard */; }; 13 | F44543801EF0461F0024AFAC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F445437F1EF0461F0024AFAC /* Assets.xcassets */; }; 14 | F44543831EF0461F0024AFAC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F44543811EF0461F0024AFAC /* LaunchScreen.storyboard */; }; 15 | F445438D1EF10CE00024AFAC /* Inceptionv3.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = F445438C1EF10CE00024AFAC /* Inceptionv3.mlmodel */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | F44543751EF0461F0024AFAC /* CoreMLDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoreMLDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | F44543781EF0461F0024AFAC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | F445437A1EF0461F0024AFAC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | F445437D1EF0461F0024AFAC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | F445437F1EF0461F0024AFAC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | F44543821EF0461F0024AFAC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | F44543841EF0461F0024AFAC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | F445438C1EF10CE00024AFAC /* Inceptionv3.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; name = Inceptionv3.mlmodel; path = ../../Downloads/Inceptionv3.mlmodel; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | F44543721EF0461F0024AFAC /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | F445436C1EF0461F0024AFAC = { 41 | isa = PBXGroup; 42 | children = ( 43 | F445438C1EF10CE00024AFAC /* Inceptionv3.mlmodel */, 44 | F44543771EF0461F0024AFAC /* CoreMLDemo */, 45 | F44543761EF0461F0024AFAC /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | F44543761EF0461F0024AFAC /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | F44543751EF0461F0024AFAC /* CoreMLDemo.app */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | F44543771EF0461F0024AFAC /* CoreMLDemo */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | F44543781EF0461F0024AFAC /* AppDelegate.swift */, 61 | F445437A1EF0461F0024AFAC /* ViewController.swift */, 62 | F445437C1EF0461F0024AFAC /* Main.storyboard */, 63 | F445437F1EF0461F0024AFAC /* Assets.xcassets */, 64 | F44543811EF0461F0024AFAC /* LaunchScreen.storyboard */, 65 | F44543841EF0461F0024AFAC /* Info.plist */, 66 | ); 67 | path = CoreMLDemo; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | F44543741EF0461F0024AFAC /* CoreMLDemo */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = F44543871EF0461F0024AFAC /* Build configuration list for PBXNativeTarget "CoreMLDemo" */; 76 | buildPhases = ( 77 | F44543711EF0461F0024AFAC /* Sources */, 78 | F44543721EF0461F0024AFAC /* Frameworks */, 79 | F44543731EF0461F0024AFAC /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = CoreMLDemo; 86 | productName = CoreMLDemo; 87 | productReference = F44543751EF0461F0024AFAC /* CoreMLDemo.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | F445436D1EF0461F0024AFAC /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0900; 97 | LastUpgradeCheck = 0900; 98 | ORGANIZATIONNAME = AppCoda; 99 | TargetAttributes = { 100 | F44543741EF0461F0024AFAC = { 101 | CreatedOnToolsVersion = 9.0; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = F44543701EF0461F0024AFAC /* Build configuration list for PBXProject "CoreMLDemo" */; 106 | compatibilityVersion = "Xcode 8.0"; 107 | developmentRegion = en; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | Base, 112 | ); 113 | mainGroup = F445436C1EF0461F0024AFAC; 114 | productRefGroup = F44543761EF0461F0024AFAC /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | F44543741EF0461F0024AFAC /* CoreMLDemo */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | F44543731EF0461F0024AFAC /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | F44543831EF0461F0024AFAC /* LaunchScreen.storyboard in Resources */, 129 | F44543801EF0461F0024AFAC /* Assets.xcassets in Resources */, 130 | F445437E1EF0461F0024AFAC /* Main.storyboard in Resources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXResourcesBuildPhase section */ 135 | 136 | /* Begin PBXSourcesBuildPhase section */ 137 | F44543711EF0461F0024AFAC /* Sources */ = { 138 | isa = PBXSourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | F445437B1EF0461F0024AFAC /* ViewController.swift in Sources */, 142 | F445438D1EF10CE00024AFAC /* Inceptionv3.mlmodel in Sources */, 143 | F44543791EF0461F0024AFAC /* AppDelegate.swift in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXVariantGroup section */ 150 | F445437C1EF0461F0024AFAC /* Main.storyboard */ = { 151 | isa = PBXVariantGroup; 152 | children = ( 153 | F445437D1EF0461F0024AFAC /* Base */, 154 | ); 155 | name = Main.storyboard; 156 | sourceTree = ""; 157 | }; 158 | F44543811EF0461F0024AFAC /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | F44543821EF0461F0024AFAC /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | F44543851EF0461F0024AFAC /* Debug */ = { 170 | isa = XCBuildConfiguration; 171 | buildSettings = { 172 | ALWAYS_SEARCH_USER_PATHS = NO; 173 | CLANG_ANALYZER_NONNULL = YES; 174 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 180 | CLANG_WARN_BOOL_CONVERSION = YES; 181 | CLANG_WARN_COMMA = YES; 182 | CLANG_WARN_CONSTANT_CONVERSION = YES; 183 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 184 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 185 | CLANG_WARN_EMPTY_BODY = YES; 186 | CLANG_WARN_ENUM_CONVERSION = YES; 187 | CLANG_WARN_INFINITE_RECURSION = YES; 188 | CLANG_WARN_INT_CONVERSION = YES; 189 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 190 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 191 | CLANG_WARN_STRICT_PROTOTYPES = YES; 192 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 193 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | CODE_SIGN_IDENTITY = "iPhone Developer"; 197 | COPY_PHASE_STRIP = NO; 198 | DEBUG_INFORMATION_FORMAT = dwarf; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | ENABLE_TESTABILITY = YES; 201 | GCC_C_LANGUAGE_STANDARD = gnu11; 202 | GCC_DYNAMIC_NO_PIC = NO; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_OPTIMIZATION_LEVEL = 0; 205 | GCC_PREPROCESSOR_DEFINITIONS = ( 206 | "DEBUG=1", 207 | "$(inherited)", 208 | ); 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 216 | MTL_ENABLE_DEBUG_INFO = YES; 217 | ONLY_ACTIVE_ARCH = YES; 218 | SDKROOT = iphoneos; 219 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 220 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 221 | }; 222 | name = Debug; 223 | }; 224 | F44543861EF0461F0024AFAC /* Release */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | CLANG_ANALYZER_NONNULL = YES; 229 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_COMMA = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 239 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 240 | CLANG_WARN_EMPTY_BODY = YES; 241 | CLANG_WARN_ENUM_CONVERSION = YES; 242 | CLANG_WARN_INFINITE_RECURSION = YES; 243 | CLANG_WARN_INT_CONVERSION = YES; 244 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 245 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 246 | CLANG_WARN_STRICT_PROTOTYPES = YES; 247 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 248 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 249 | CLANG_WARN_UNREACHABLE_CODE = YES; 250 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 251 | CODE_SIGN_IDENTITY = "iPhone Developer"; 252 | COPY_PHASE_STRIP = NO; 253 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 254 | ENABLE_NS_ASSERTIONS = NO; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | GCC_C_LANGUAGE_STANDARD = gnu11; 257 | GCC_NO_COMMON_BLOCKS = YES; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 265 | MTL_ENABLE_DEBUG_INFO = NO; 266 | SDKROOT = iphoneos; 267 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 268 | VALIDATE_PRODUCT = YES; 269 | }; 270 | name = Release; 271 | }; 272 | F44543881EF0461F0024AFAC /* Debug */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 276 | INFOPLIST_FILE = CoreMLDemo/Info.plist; 277 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 278 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.CoreMLDemo; 279 | PRODUCT_NAME = "$(TARGET_NAME)"; 280 | SWIFT_VERSION = 4.0; 281 | TARGETED_DEVICE_FAMILY = "1,2"; 282 | }; 283 | name = Debug; 284 | }; 285 | F44543891EF0461F0024AFAC /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 289 | INFOPLIST_FILE = CoreMLDemo/Info.plist; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.CoreMLDemo; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | SWIFT_VERSION = 4.0; 294 | TARGETED_DEVICE_FAMILY = "1,2"; 295 | }; 296 | name = Release; 297 | }; 298 | /* End XCBuildConfiguration section */ 299 | 300 | /* Begin XCConfigurationList section */ 301 | F44543701EF0461F0024AFAC /* Build configuration list for PBXProject "CoreMLDemo" */ = { 302 | isa = XCConfigurationList; 303 | buildConfigurations = ( 304 | F44543851EF0461F0024AFAC /* Debug */, 305 | F44543861EF0461F0024AFAC /* Release */, 306 | ); 307 | defaultConfigurationIsVisible = 0; 308 | defaultConfigurationName = Release; 309 | }; 310 | F44543871EF0461F0024AFAC /* Build configuration list for PBXNativeTarget "CoreMLDemo" */ = { 311 | isa = XCConfigurationList; 312 | buildConfigurations = ( 313 | F44543881EF0461F0024AFAC /* Debug */, 314 | F44543891EF0461F0024AFAC /* Release */, 315 | ); 316 | defaultConfigurationIsVisible = 0; 317 | defaultConfigurationName = Release; 318 | }; 319 | /* End XCConfigurationList section */ 320 | }; 321 | rootObject = F445436D1EF0461F0024AFAC /* Project object */; 322 | } 323 | -------------------------------------------------------------------------------- /CoreMLDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CoreMLDemo.xcodeproj/project.xcworkspace/xcuserdata/simon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/CoreMLDemo/0ba1d2fd5aa44f3820d34531146367b891ff3709/CoreMLDemo.xcodeproj/project.xcworkspace/xcuserdata/simon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CoreMLDemo.xcodeproj/xcuserdata/simon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CoreMLDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /CoreMLDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CoreMLDemo 4 | // 5 | // Created by Sai Kambampati on 14/6/2017. 6 | // Copyright © 2017 AppCoda. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CoreMLDemo/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 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /CoreMLDemo/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 | 27 | 28 | -------------------------------------------------------------------------------- /CoreMLDemo/Base.lproj/Main.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 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CoreMLDemo/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 | APPL 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 | NSCameraUsageDescription 38 | For you to shoot a photo for object recognition 39 | NSPhotoLibraryUsageDescription 40 | For you to select a photo for object recognition 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /CoreMLDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CoreMLDemo 4 | // 5 | // Created by Sai Kambampati on 14/6/2017. 6 | // Copyright © 2017 AppCoda. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreML 11 | 12 | class ViewController: UIViewController, UINavigationControllerDelegate { 13 | 14 | @IBOutlet weak var imageView: UIImageView! 15 | @IBOutlet weak var classifier: UILabel! 16 | 17 | var model: Inceptionv3! 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | // Do any additional setup after loading the view, typically from a nib. 22 | } 23 | 24 | override func viewWillAppear(_ animated: Bool) { 25 | model = Inceptionv3() 26 | } 27 | 28 | override func didReceiveMemoryWarning() { 29 | super.didReceiveMemoryWarning() 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | @IBAction func camera(_ sender: Any) { 34 | 35 | if !UIImagePickerController.isSourceTypeAvailable(.camera) { 36 | return 37 | } 38 | 39 | let cameraPicker = UIImagePickerController() 40 | cameraPicker.delegate = self 41 | cameraPicker.sourceType = .camera 42 | cameraPicker.allowsEditing = false 43 | 44 | present(cameraPicker, animated: true) 45 | } 46 | 47 | @IBAction func openLibrary(_ sender: Any) { 48 | let picker = UIImagePickerController() 49 | picker.allowsEditing = false 50 | picker.delegate = self 51 | picker.sourceType = .photoLibrary 52 | present(picker, animated: true) 53 | } 54 | 55 | } 56 | 57 | extension ViewController: UIImagePickerControllerDelegate { 58 | func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 59 | dismiss(animated: true, completion: nil) 60 | } 61 | 62 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 63 | 64 | picker.dismiss(animated: true) 65 | classifier.text = "Analyzing Image..." 66 | guard let image = info["UIImagePickerControllerOriginalImage"] as? UIImage else { 67 | return 68 | } //1 69 | 70 | UIGraphicsBeginImageContextWithOptions(CGSize(width: 299, height: 299), true, 2.0) 71 | image.draw(in: CGRect(x: 0, y: 0, width: 299, height: 299)) 72 | let newImage = UIGraphicsGetImageFromCurrentImageContext()! 73 | UIGraphicsEndImageContext() 74 | 75 | let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary 76 | var pixelBuffer : CVPixelBuffer? 77 | let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(newImage.size.width), Int(newImage.size.height), kCVPixelFormatType_32ARGB, attrs, &pixelBuffer) 78 | guard (status == kCVReturnSuccess) else { 79 | return 80 | } 81 | 82 | CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 83 | let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!) 84 | 85 | let rgbColorSpace = CGColorSpaceCreateDeviceRGB() 86 | let context = CGContext(data: pixelData, width: Int(newImage.size.width), height: Int(newImage.size.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) //3 87 | 88 | context?.translateBy(x: 0, y: newImage.size.height) 89 | context?.scaleBy(x: 1.0, y: -1.0) 90 | 91 | UIGraphicsPushContext(context!) 92 | newImage.draw(in: CGRect(x: 0, y: 0, width: newImage.size.width, height: newImage.size.height)) 93 | UIGraphicsPopContext() 94 | CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 95 | imageView.image = newImage 96 | 97 | // Core ML 98 | guard let prediction = try? model.prediction(image: pixelBuffer!) else { 99 | return 100 | } 101 | 102 | classifier.text = "I think this is a \(prediction.classLabel)." 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /CoreMLDemoStarter.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/CoreMLDemo/0ba1d2fd5aa44f3820d34531146367b891ff3709/CoreMLDemoStarter.zip -------------------------------------------------------------------------------- /Inceptionv3.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/CoreMLDemo/0ba1d2fd5aa44f3820d34531146367b891ff3709/Inceptionv3.mlmodel -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A simple demo for Core ML in Swift 2 | 3 | At WWDC 2017, Apple released a lot of exciting frameworks and APIs for us developer to use. Among these releases, the most popular one was Core ML. Core ML is a framework that can be harnessed to integrate machine learning models into your app. The best part about Core ML is that you don’t require extensive knowledge about neural networks or machine learning. Another bonus feature about Core ML is that you can use pre-trained data models as long as you convert it into a Core ML model. For the purpose of this tutorial, we will be using a Core ML model that is available on Apple’s Developer Website. Without further ado, let’s start to learn Core ML. 4 | 5 | For the full tutorial, please check it out at: 6 | 7 | http://www.appcoda.com/coreml-introduction 8 | --------------------------------------------------------------------------------