diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.pbxproj b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.pbxproj new file mode 100644 index 0000000..282d5c0 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.pbxproj @@ -0,0 +1,347 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 1E6946CB2343A9AA00FB45AD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E6946CA2343A9AA00FB45AD /* AppDelegate.swift */; }; + 1E6946CD2343A9AA00FB45AD /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E6946CC2343A9AA00FB45AD /* SceneDelegate.swift */; }; + 1E6946CF2343A9AA00FB45AD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E6946CE2343A9AA00FB45AD /* ViewController.swift */; }; + 1E6946D22343A9AA00FB45AD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E6946D02343A9AA00FB45AD /* Main.storyboard */; }; + 1E6946D42343A9B100FB45AD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1E6946D32343A9B100FB45AD /* Assets.xcassets */; }; + 1E6946D72343A9B100FB45AD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E6946D52343A9B100FB45AD /* LaunchScreen.storyboard */; }; + 1E6946DF2343B36A00FB45AD /* CatDogUpdatable.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 1E6946DE2343B36A00FB45AD /* CatDogUpdatable.mlmodel */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 1E6946C72343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSCoreMLTrainModelOnDevice.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 1E6946CA2343A9AA00FB45AD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 1E6946CC2343A9AA00FB45AD /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 1E6946CE2343A9AA00FB45AD /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 1E6946D12343A9AA00FB45AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 1E6946D32343A9B100FB45AD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 1E6946D62343A9B100FB45AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 1E6946D82343A9B100FB45AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1E6946DE2343B36A00FB45AD /* CatDogUpdatable.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = CatDogUpdatable.mlmodel; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1E6946C42343A9AA00FB45AD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1E6946BE2343A9AA00FB45AD = { + isa = PBXGroup; + children = ( + 1E6946C92343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice */, + 1E6946C82343A9AA00FB45AD /* Products */, + ); + sourceTree = ""; + }; + 1E6946C82343A9AA00FB45AD /* Products */ = { + isa = PBXGroup; + children = ( + 1E6946C72343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice.app */, + ); + name = Products; + sourceTree = ""; + }; + 1E6946C92343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice */ = { + isa = PBXGroup; + children = ( + 1E6946DE2343B36A00FB45AD /* CatDogUpdatable.mlmodel */, + 1E6946CA2343A9AA00FB45AD /* AppDelegate.swift */, + 1E6946CC2343A9AA00FB45AD /* SceneDelegate.swift */, + 1E6946CE2343A9AA00FB45AD /* ViewController.swift */, + 1E6946D02343A9AA00FB45AD /* Main.storyboard */, + 1E6946D32343A9B100FB45AD /* Assets.xcassets */, + 1E6946D52343A9B100FB45AD /* LaunchScreen.storyboard */, + 1E6946D82343A9B100FB45AD /* Info.plist */, + ); + path = iOSCoreMLTrainModelOnDevice; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 1E6946C62343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1E6946DB2343A9B100FB45AD /* Build configuration list for PBXNativeTarget "iOSCoreMLTrainModelOnDevice" */; + buildPhases = ( + 1E6946C32343A9AA00FB45AD /* Sources */, + 1E6946C42343A9AA00FB45AD /* Frameworks */, + 1E6946C52343A9AA00FB45AD /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = iOSCoreMLTrainModelOnDevice; + productName = iOSCoreMLTrainModelOnDevice; + productReference = 1E6946C72343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1E6946BF2343A9AA00FB45AD /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1100; + LastUpgradeCheck = 1100; + ORGANIZATIONNAME = "Anupam Chugh"; + TargetAttributes = { + 1E6946C62343A9AA00FB45AD = { + CreatedOnToolsVersion = 11.0; + }; + }; + }; + buildConfigurationList = 1E6946C22343A9AA00FB45AD /* Build configuration list for PBXProject "iOSCoreMLTrainModelOnDevice" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 1E6946BE2343A9AA00FB45AD; + productRefGroup = 1E6946C82343A9AA00FB45AD /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 1E6946C62343A9AA00FB45AD /* iOSCoreMLTrainModelOnDevice */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 1E6946C52343A9AA00FB45AD /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1E6946D72343A9B100FB45AD /* LaunchScreen.storyboard in Resources */, + 1E6946D42343A9B100FB45AD /* Assets.xcassets in Resources */, + 1E6946D22343A9AA00FB45AD /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 1E6946C32343A9AA00FB45AD /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1E6946CF2343A9AA00FB45AD /* ViewController.swift in Sources */, + 1E6946CB2343A9AA00FB45AD /* AppDelegate.swift in Sources */, + 1E6946CD2343A9AA00FB45AD /* SceneDelegate.swift in Sources */, + 1E6946DF2343B36A00FB45AD /* CatDogUpdatable.mlmodel in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 1E6946D02343A9AA00FB45AD /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 1E6946D12343A9AA00FB45AD /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 1E6946D52343A9B100FB45AD /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 1E6946D62343A9B100FB45AD /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 1E6946D92343A9B100FB45AD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 1E6946DA2343A9B100FB45AD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 1E6946DC2343A9B100FB45AD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = M6P56H6G97; + INFOPLIST_FILE = iOSCoreMLTrainModelOnDevice/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.iowncode.iOSCoreMLTrainModelOnDevice; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 1E6946DD2343A9B100FB45AD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = M6P56H6G97; + INFOPLIST_FILE = iOSCoreMLTrainModelOnDevice/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.iowncode.iOSCoreMLTrainModelOnDevice; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1E6946C22343A9AA00FB45AD /* Build configuration list for PBXProject "iOSCoreMLTrainModelOnDevice" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1E6946D92343A9B100FB45AD /* Debug */, + 1E6946DA2343A9B100FB45AD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1E6946DB2343A9B100FB45AD /* Build configuration list for PBXNativeTarget "iOSCoreMLTrainModelOnDevice" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1E6946DC2343A9B100FB45AD /* Debug */, + 1E6946DD2343A9B100FB45AD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1E6946BF2343A9AA00FB45AD /* Project object */; +} diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..092cee8 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcuserdata/anupamchugh.xcuserdatad/UserInterfaceState.xcuserstate b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcuserdata/anupamchugh.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..685eab3 Binary files /dev/null and b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/project.xcworkspace/xcuserdata/anupamchugh.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/xcuserdata/anupamchugh.xcuserdatad/xcschemes/xcschememanagement.plist b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/xcuserdata/anupamchugh.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..5c61e61 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice.xcodeproj/xcuserdata/anupamchugh.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + iOSCoreMLTrainModelOnDevice.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/AppDelegate.swift b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/AppDelegate.swift new file mode 100644 index 0000000..b96e8b2 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// iOSCoreMLTrainModelOnDevice +// +// Created by Anupam Chugh on 01/10/19. +// Copyright © 2019 Anupam Chugh. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/Contents.json b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/LaunchScreen.storyboard b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/Main.storyboard b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/Main.storyboard new file mode 100644 index 0000000..b7a8405 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Base.lproj/Main.storyboard @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/CatDogUpdatable.mlmodel b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/CatDogUpdatable.mlmodel new file mode 100644 index 0000000..d76de03 Binary files /dev/null and b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/CatDogUpdatable.mlmodel differ diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Info.plist b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Info.plist new file mode 100644 index 0000000..2a3483c --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/SceneDelegate.swift b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/SceneDelegate.swift new file mode 100644 index 0000000..3d48883 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/SceneDelegate.swift @@ -0,0 +1,53 @@ +// +// SceneDelegate.swift +// iOSCoreMLTrainModelOnDevice +// +// Created by Anupam Chugh on 01/10/19. +// Copyright © 2019 Anupam Chugh. All rights reserved. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/ViewController.swift b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/ViewController.swift new file mode 100644 index 0000000..c00bcb6 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/iOSCoreMLTrainModelOnDevice/iOSCoreMLTrainModelOnDevice/ViewController.swift @@ -0,0 +1,271 @@ +// +// ViewController.swift +// iOSCoreMLTrainModelOnDevice +// +// Created by Anupam Chugh on 01/10/19. +// Copyright © 2019 Anupam Chugh. All rights reserved. +// + +import UIKit +import CoreML +import Vision + +enum Animal { + case cat + case dog +} + + +class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { + + @IBOutlet weak var btnTrainImages: UIButton! + @IBOutlet weak var trainingImagesCount: UILabel! + @IBOutlet weak var predicatedClassLabel: UILabel! + @IBOutlet weak var btnToggleClassLabel: UIButton! + private var updatableModel : MLModel? + + + @IBOutlet weak var imageView: UIImageView! + var imageLabelDictionary : [UIImage:String] = [:] + + var retrainImageCount = 0{ + didSet{ + if retrainImageCount == 0{ + trainingImagesCount.text = "" + btnTrainImages.alpha = 0 + } + } + } + + var imageConstraint: MLImageConstraint! + + + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + do{ + + let fileManager = FileManager.default + + let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true) + + let fileURL = documentDirectory.appendingPathComponent("CatDog.mlmodelc") + if let model = loadModel(url: fileURL){ + print("updatable \(model.modelDescription.isUpdatable)") + print("model description is \(model.description)") + updatableModel = model + } + else{ + if let modelURL = Bundle.main.url(forResource: "CatDogUpdatable", withExtension: "mlmodelc") + { + if let model = loadModel(url: modelURL){ + updatableModel = model + } + } + } + + if let updatableModel = updatableModel{ + imageConstraint = self.getImageConstraint(model: updatableModel) + } + + }catch(let error) + { + print("initial error is \(error.localizedDescription)") + } + + btnToggleClassLabel.alpha = 0 + + } + + @IBAction func startTraining(_ sender: Any) { + + let modelConfig = MLModelConfiguration() + modelConfig.computeUnits = .cpuAndGPU + do { + let fileManager = FileManager.default + let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true) + + var modelURL = CatDogUpdatable.urlOfModelInThisBundle + + let pathOfFile = documentDirectory.appendingPathComponent("CatDog.mlmodelc") + + if fileManager.fileExists(atPath: pathOfFile.path){ + modelURL = pathOfFile + } + + + let updateTask = try MLUpdateTask(forModelAt: modelURL, trainingData: batchProvider(), configuration: modelConfig, + progressHandlers: MLUpdateProgressHandlers(forEvents: [.trainingBegin,.epochEnd], + progressHandler: { (contextProgress) in + print(contextProgress.event) + // you can check the progress here, after each epoch + + }) { (finalContext) in + + if finalContext.task.error?.localizedDescription == nil + { + let fileManager = FileManager.default + do { + + let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true) + let fileURL = documentDirectory.appendingPathComponent("CatDog.mlmodelc") + try finalContext.model.write(to: fileURL) + + self.updatableModel = self.loadModel(url: fileURL) + + DispatchQueue.main.async { + self.btnTrainImages.alpha = 0 + self.imageLabelDictionary = [:] + self.retrainImageCount = 0 + } + + + } catch(let error) { + print("error is \(error.localizedDescription)") + } + + } + + + }) + updateTask.resume() + + } catch { + print("Error while upgrading \(error.localizedDescription)") + } + + + } + + func getImageConstraint(model: MLModel) -> MLImageConstraint { + return model.modelDescription.inputDescriptionsByName["image"]!.imageConstraint! + } + + + @IBAction func btnAddToTraining(_ sender: UIButton) { + btnToggleClassLabel.alpha = 0 + + if btnTrainImages.alpha == 0{ + btnTrainImages.alpha = 1 + } + + retrainImageCount = retrainImageCount + 1 + + trainingImagesCount.text = "\(retrainImageCount)" + + if let image = imageView.image{ + + var label = "Dog" + if sender.tag == 0{ + label = "Cat" + } + imageLabelDictionary[image] = label + } + + + } + + private func loadModel(url: URL) -> MLModel? { + do { + let config = MLModelConfiguration() + config.computeUnits = .all + return try MLModel(contentsOf: url, configuration: config) + } catch { + print("Error loading model: \(error)") + return nil + } + } + + + private func batchProvider() -> MLArrayBatchProvider + { + + var batchInputs: [MLFeatureProvider] = [] + let imageOptions: [MLFeatureValue.ImageOption: Any] = [ + .cropAndScale: VNImageCropAndScaleOption.scaleFill.rawValue + ] + for (image,label) in imageLabelDictionary { + + do{ + let featureValue = try MLFeatureValue(cgImage: image.cgImage!, constraint: imageConstraint, options: imageOptions) + + if let pixelBuffer = featureValue.imageBufferValue{ + let x = CatDogUpdatableTrainingInput(image: pixelBuffer, classLabel: label) + batchInputs.append(x) + } + } + catch(let error){ + print("error description is \(error.localizedDescription)") + } + } + return MLArrayBatchProvider(array: batchInputs) + } + + + @IBAction func takePhotoClicked(_ sender: Any) { + + let imagePicker = UIImagePickerController() + imagePicker.sourceType = .photoLibrary + imagePicker.delegate = self + present(imagePicker, animated: true, completion: nil) + } + + func predict(image: UIImage) -> Animal? { + + + do{ + + let imageOptions: [MLFeatureValue.ImageOption: Any] = [ + .cropAndScale: VNImageCropAndScaleOption.scaleFill.rawValue + ] + + let featureValue = try MLFeatureValue(cgImage: image.cgImage!, constraint: imageConstraint, options: imageOptions) + let featureProviderDict = try MLDictionaryFeatureProvider(dictionary: ["image" : featureValue]) + let prediction = try updatableModel?.prediction(from: featureProviderDict) + let value = prediction?.featureValue(for: "classLabel")?.stringValue + if value == "Dog"{ + return .dog + } + else{ + return .cat + } + }catch(let error){ + print("error is \(error.localizedDescription)") + } + return nil + } + func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { + dismiss(animated: true, completion: nil) + } + + + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + dismiss(animated: true) { + if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { + self.imageView.image = image + let animal = self.predict(image: image) + + if let animal = animal{ + if animal == .dog{ + self.predicatedClassLabel.text = "Dog" + self.btnToggleClassLabel.alpha = 1 + self.btnToggleClassLabel.tag = 0 + self.btnToggleClassLabel.setTitle("Click here if it's a Cat!", for: .normal) + } + else if animal == .cat{ + self.btnToggleClassLabel.alpha = 1 + self.predicatedClassLabel.text = "Cat" + + self.btnToggleClassLabel.tag = 1 + self.btnToggleClassLabel.setTitle("Click here if it's a Dog!", for: .normal) + } + } + else{ + self.predicatedClassLabel.text = "Neither dog nor cat." + } + } + } + } +} + diff --git a/iOSCoreMLOnDeviceTraining/model + scripts/coremlupdatablemodel.py b/iOSCoreMLOnDeviceTraining/model + scripts/coremlupdatablemodel.py new file mode 100644 index 0000000..148b670 --- /dev/null +++ b/iOSCoreMLOnDeviceTraining/model + scripts/coremlupdatablemodel.py @@ -0,0 +1,68 @@ +import coremltools + +output_labels = ['Cat', 'Dog'] +coreml_model = coremltools.converters.keras.convert('model.h5', input_names=['image'], output_names=['output'], + class_labels=output_labels, + image_input_names='image') + +coreml_model.author = 'Anupam Chugh' +coreml_model.short_description = 'Cat Dog Classifier converted from a Keras model' +coreml_model.input_description['image'] = 'Takes as input an image' +coreml_model.output_description['output'] = 'Prediction as cat or dog' +coreml_model.output_description['classLabel'] = 'Returns Cat Or Dog as class label' + + +coreml_model.save('catdogmodel.mlmodel') + +coreml_model_path = "./catdogmodel.mlmodel" + +spec = coremltools.utils.load_spec(coreml_model_path) +builder = coremltools.models.neural_network.NeuralNetworkBuilder(spec=spec) +builder.inspect_layers(last=3) +builder.inspect_input_features() + +neuralnetwork_spec = builder.spec + +neuralnetwork_spec.description.input[0].type.imageType.width = 150 +neuralnetwork_spec.description.input[0].type.imageType.height = 150 + +# Set input and output description +neuralnetwork_spec.description.input[0].shortDescription = 'Takes as input an image' +neuralnetwork_spec.description.output[0].shortDescription = 'Prediction as cat or dog' + +# Provide metadata +neuralnetwork_spec.description.metadata.author = 'Anupam Chugh' +neuralnetwork_spec.description.metadata.license = 'MIT' +neuralnetwork_spec.description.metadata.shortDescription = ( + 'Cat Dog Classifier converted from a Keras model') + + +model_spec = builder.spec + +# make_updatable method is used to make a layer updatable. It requires a list of layer names. +# dense_5 and dense_6 are two innerProduct layer in this example and we make them updatable. +builder.make_updatable(['dense_5', 'dense_6']) + +# Categorical Cross Entropy or Mean Squared Error can be chosen for the loss layer. +builder.set_categorical_cross_entropy_loss(name='lossLayer', input='output') + + +# in addition of the loss layer, an optimizer must also be defined. SGD and Adam optimizers are supported. +# SGD has been used for this example. To use SGD, one must set lr(learningRate) and batch(miniBatchSize) (momentum is an optional parameter). +from coremltools.models.neural_network import SgdParams +builder.set_sgd_optimizer(SgdParams(lr=0.01, batch=5)) + +# The number of epochs must be set as follows. +builder.set_epochs(1) + +model_spec.isUpdatable = True +model_spec.specificationVersion = coremltools._MINIMUM_UPDATABLE_SPEC_VERSION + + +# Set training inputs descriptions +model_spec.description.trainingInput[0].shortDescription = 'Image for training and updating the model' +model_spec.description.trainingInput[1].shortDescription = 'Set the value as Cat or Dog and update the model' + + +# save the updated spec +coremltools.utils.save_spec(model_spec, "CatDogUpdatable.mlmodel") diff --git a/iOSCoreMLOnDeviceTraining/model + scripts/model.h5 b/iOSCoreMLOnDeviceTraining/model + scripts/model.h5 new file mode 100644 index 0000000..ab4dfef Binary files /dev/null and b/iOSCoreMLOnDeviceTraining/model + scripts/model.h5 differ