├── CoreMLCatsDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── dima.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── CoreMLCatsDemo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Inceptionv3.mlmodel ├── Info.plist └── ViewController.swift ├── README.md └── media └── demo.gif /CoreMLCatsDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 32F77B5C1F0C1C1D006950B5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F77B5B1F0C1C1D006950B5 /* AppDelegate.swift */; }; 11 | 32F77B5E1F0C1C1D006950B5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F77B5D1F0C1C1D006950B5 /* ViewController.swift */; }; 12 | 32F77B611F0C1C1D006950B5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32F77B5F1F0C1C1D006950B5 /* Main.storyboard */; }; 13 | 32F77B631F0C1C1D006950B5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32F77B621F0C1C1D006950B5 /* Assets.xcassets */; }; 14 | 32F77B661F0C1C1D006950B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32F77B641F0C1C1D006950B5 /* LaunchScreen.storyboard */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 32F77B581F0C1C1D006950B5 /* CoreMLCatsDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoreMLCatsDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 32F77B5B1F0C1C1D006950B5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 32F77B5D1F0C1C1D006950B5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 21 | 32F77B601F0C1C1D006950B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | 32F77B621F0C1C1D006950B5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 32F77B651F0C1C1D006950B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 32F77B671F0C1C1D006950B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 32F77B551F0C1C1D006950B5 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 32F77B4F1F0C1C1D006950B5 = { 39 | isa = PBXGroup; 40 | children = ( 41 | 32F77B5A1F0C1C1D006950B5 /* CoreMLCatsDemo */, 42 | 32F77B591F0C1C1D006950B5 /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 32F77B591F0C1C1D006950B5 /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 32F77B581F0C1C1D006950B5 /* CoreMLCatsDemo.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 32F77B5A1F0C1C1D006950B5 /* CoreMLCatsDemo */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 32F77B5B1F0C1C1D006950B5 /* AppDelegate.swift */, 58 | 32F77B5D1F0C1C1D006950B5 /* ViewController.swift */, 59 | 32F77B5F1F0C1C1D006950B5 /* Main.storyboard */, 60 | 32F77B621F0C1C1D006950B5 /* Assets.xcassets */, 61 | 32F77B641F0C1C1D006950B5 /* LaunchScreen.storyboard */, 62 | 32F77B671F0C1C1D006950B5 /* Info.plist */, 63 | ); 64 | path = CoreMLCatsDemo; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 32F77B571F0C1C1D006950B5 /* CoreMLCatsDemo */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 32F77B6A1F0C1C1D006950B5 /* Build configuration list for PBXNativeTarget "CoreMLCatsDemo" */; 73 | buildPhases = ( 74 | 32F77B541F0C1C1D006950B5 /* Sources */, 75 | 32F77B551F0C1C1D006950B5 /* Frameworks */, 76 | 32F77B561F0C1C1D006950B5 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = CoreMLCatsDemo; 83 | productName = CoreMLCatsDemo; 84 | productReference = 32F77B581F0C1C1D006950B5 /* CoreMLCatsDemo.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 32F77B501F0C1C1D006950B5 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0900; 94 | LastUpgradeCheck = 0900; 95 | ORGANIZATIONNAME = "Dmitriy Rozov"; 96 | TargetAttributes = { 97 | 32F77B571F0C1C1D006950B5 = { 98 | CreatedOnToolsVersion = 9.0; 99 | ProvisioningStyle = Manual; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = 32F77B531F0C1C1D006950B5 /* Build configuration list for PBXProject "CoreMLCatsDemo" */; 104 | compatibilityVersion = "Xcode 8.0"; 105 | developmentRegion = en; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = 32F77B4F1F0C1C1D006950B5; 112 | productRefGroup = 32F77B591F0C1C1D006950B5 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 32F77B571F0C1C1D006950B5 /* CoreMLCatsDemo */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 32F77B561F0C1C1D006950B5 /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 32F77B661F0C1C1D006950B5 /* LaunchScreen.storyboard in Resources */, 127 | 32F77B631F0C1C1D006950B5 /* Assets.xcassets in Resources */, 128 | 32F77B611F0C1C1D006950B5 /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 32F77B541F0C1C1D006950B5 /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 32F77B5E1F0C1C1D006950B5 /* ViewController.swift in Sources */, 140 | 32F77B5C1F0C1C1D006950B5 /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | 32F77B5F1F0C1C1D006950B5 /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | 32F77B601F0C1C1D006950B5 /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | 32F77B641F0C1C1D006950B5 /* LaunchScreen.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 32F77B651F0C1C1D006950B5 /* Base */, 159 | ); 160 | name = LaunchScreen.storyboard; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXVariantGroup section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 32F77B681F0C1C1D006950B5 /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 181 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 188 | CLANG_WARN_STRICT_PROTOTYPES = YES; 189 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 190 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 191 | CLANG_WARN_UNREACHABLE_CODE = YES; 192 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 193 | CODE_SIGN_IDENTITY = "iPhone Developer"; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = dwarf; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | ENABLE_TESTABILITY = YES; 198 | GCC_C_LANGUAGE_STANDARD = gnu11; 199 | GCC_DYNAMIC_NO_PIC = NO; 200 | GCC_NO_COMMON_BLOCKS = YES; 201 | GCC_OPTIMIZATION_LEVEL = 0; 202 | GCC_PREPROCESSOR_DEFINITIONS = ( 203 | "DEBUG=1", 204 | "$(inherited)", 205 | ); 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 213 | MTL_ENABLE_DEBUG_INFO = YES; 214 | ONLY_ACTIVE_ARCH = YES; 215 | SDKROOT = iphoneos; 216 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 217 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 218 | }; 219 | name = Debug; 220 | }; 221 | 32F77B691F0C1C1D006950B5 /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_ANALYZER_NONNULL = YES; 226 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_COMMA = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INFINITE_RECURSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | CODE_SIGN_IDENTITY = "iPhone Developer"; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu11; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 262 | MTL_ENABLE_DEBUG_INFO = NO; 263 | SDKROOT = iphoneos; 264 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 265 | VALIDATE_PRODUCT = YES; 266 | }; 267 | name = Release; 268 | }; 269 | 32F77B6B1F0C1C1D006950B5 /* Debug */ = { 270 | isa = XCBuildConfiguration; 271 | buildSettings = { 272 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 273 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 274 | CODE_SIGN_STYLE = Manual; 275 | DEVELOPMENT_TEAM = ""; 276 | INFOPLIST_FILE = CoreMLCatsDemo/Info.plist; 277 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 278 | PRODUCT_BUNDLE_IDENTIFIER = me.dmrozov.CoreMLCatsDemo; 279 | PRODUCT_NAME = "$(TARGET_NAME)"; 280 | PROVISIONING_PROFILE_SPECIFIER = ""; 281 | SWIFT_VERSION = 4.0; 282 | TARGETED_DEVICE_FAMILY = "1,2"; 283 | }; 284 | name = Debug; 285 | }; 286 | 32F77B6C1F0C1C1D006950B5 /* Release */ = { 287 | isa = XCBuildConfiguration; 288 | buildSettings = { 289 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 290 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 291 | CODE_SIGN_STYLE = Manual; 292 | DEVELOPMENT_TEAM = ""; 293 | INFOPLIST_FILE = CoreMLCatsDemo/Info.plist; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = me.dmrozov.CoreMLCatsDemo; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | PROVISIONING_PROFILE_SPECIFIER = ""; 298 | SWIFT_VERSION = 4.0; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | }; 301 | name = Release; 302 | }; 303 | /* End XCBuildConfiguration section */ 304 | 305 | /* Begin XCConfigurationList section */ 306 | 32F77B531F0C1C1D006950B5 /* Build configuration list for PBXProject "CoreMLCatsDemo" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | 32F77B681F0C1C1D006950B5 /* Debug */, 310 | 32F77B691F0C1C1D006950B5 /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | defaultConfigurationName = Release; 314 | }; 315 | 32F77B6A1F0C1C1D006950B5 /* Build configuration list for PBXNativeTarget "CoreMLCatsDemo" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | 32F77B6B1F0C1C1D006950B5 /* Debug */, 319 | 32F77B6C1F0C1C1D006950B5 /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | defaultConfigurationName = Release; 323 | }; 324 | /* End XCConfigurationList section */ 325 | }; 326 | rootObject = 32F77B501F0C1C1D006950B5 /* Project object */; 327 | } 328 | -------------------------------------------------------------------------------- /CoreMLCatsDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CoreMLCatsDemo.xcodeproj/xcuserdata/dima.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CoreMLCatsDemo.xcodeproj/xcuserdata/dima.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CoreMLCatsDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /CoreMLCatsDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CoreMLCatsDemo 4 | // 5 | // Created by Dmitriy Rozov on 04/07/2017. 6 | // Copyright © 2017 Dmitriy Rozov. 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 | -------------------------------------------------------------------------------- /CoreMLCatsDemo/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 | } -------------------------------------------------------------------------------- /CoreMLCatsDemo/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 | -------------------------------------------------------------------------------- /CoreMLCatsDemo/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 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 | -------------------------------------------------------------------------------- /CoreMLCatsDemo/Inceptionv3.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmrozov/CoreMLCatsDemo/105c2759a859b36d25e874adeff6790a7f3cfce1/CoreMLCatsDemo/Inceptionv3.mlmodel -------------------------------------------------------------------------------- /CoreMLCatsDemo/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 | NSCameraUsageDescription 24 | AI Man 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CoreMLCatsDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CoreMLCatsDemo 4 | // 5 | // Created by Dmitriy Rozov on 04/07/2017. 6 | // Copyright © 2017 Dmitriy Rozov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVFoundation 11 | import Vision 12 | 13 | class ViewController: UIViewController { 14 | 15 | @IBOutlet var resultLabel: UILabel! 16 | @IBOutlet var resultView: UIView! 17 | 18 | let session = AVCaptureSession() 19 | var previewLayer: AVCaptureVideoPreviewLayer! 20 | let captureQueue = DispatchQueue(label: "captureQueue") 21 | var visionRequests = [VNRequest]() 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | 26 | guard let camera = AVCaptureDevice.default(for: .video) else { 27 | return 28 | } 29 | do { 30 | previewLayer = AVCaptureVideoPreviewLayer(session: session) 31 | resultView.layer.addSublayer(previewLayer) 32 | 33 | let cameraInput = try AVCaptureDeviceInput(device: camera) 34 | let videoOutput = AVCaptureVideoDataOutput() 35 | videoOutput.setSampleBufferDelegate(self, queue: captureQueue) 36 | videoOutput.alwaysDiscardsLateVideoFrames = true 37 | videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA] 38 | 39 | session.sessionPreset = .high 40 | session.addInput(cameraInput) 41 | session.addOutput(videoOutput) 42 | 43 | let connection = videoOutput.connection(with: .video) 44 | connection?.videoOrientation = .portrait 45 | session.startRunning() 46 | 47 | guard let visionModel = try? VNCoreMLModel(for: Inceptionv3().model) else { 48 | fatalError("Could not load model") 49 | } 50 | 51 | let classificationRequest = VNCoreMLRequest(model: visionModel, completionHandler: handleClassifications) 52 | classificationRequest.imageCropAndScaleOption = VNImageCropAndScaleOptionCenterCrop 53 | visionRequests = [classificationRequest] 54 | } catch { 55 | let alertController = UIAlertController(title: nil, message: error.localizedDescription, preferredStyle: .alert) 56 | alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) 57 | present(alertController, animated: true, completion: nil) 58 | } 59 | } 60 | 61 | override func viewDidLayoutSubviews() { 62 | super.viewDidLayoutSubviews() 63 | previewLayer.frame = view.frame 64 | } 65 | 66 | private func handleClassifications(request: VNRequest, error: Error?) { 67 | if let error = error { 68 | print(error.localizedDescription) 69 | return 70 | } 71 | guard let results = request.results as? [VNClassificationObservation] else { 72 | print("No results") 73 | return 74 | } 75 | 76 | var resultString = "Это не кот!" 77 | results[0...3].forEach { 78 | let identifer = $0.identifier.lowercased() 79 | if identifer.range(of: " cat") != nil || identifer.range(of: "cat ") != nil || identifer == "cat" { 80 | resultString = "Это кот!" 81 | } 82 | } 83 | DispatchQueue.main.async { 84 | self.resultLabel.text = resultString 85 | } 86 | } 87 | } 88 | 89 | // MARK: - AVCaptureVideoDataOutputSampleBufferDelegate 90 | 91 | extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { 92 | 93 | func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 94 | guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { 95 | return 96 | } 97 | 98 | var requestOptions: [VNImageOption: Any] = [:] 99 | if let cameraIntrinsicData = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil) { 100 | requestOptions = [.cameraIntrinsics: cameraIntrinsicData] 101 | } 102 | 103 | let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: 1, options: requestOptions) 104 | do { 105 | try imageRequestHandler.perform(visionRequests) 106 | } catch { 107 | print(error) 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoreMLCatsDemo 2 | 3 | This app recognizes сats 😺 using Core ML and Vision. 4 | 5 | ![Image alt](media/demo.gif) 6 | -------------------------------------------------------------------------------- /media/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmrozov/CoreMLCatsDemo/105c2759a859b36d25e874adeff6790a7f3cfce1/media/demo.gif --------------------------------------------------------------------------------