├── CarDetectionUsingML.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── ashis.laha.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── CarDetectionUsingML.xcscheme ├── CarDetectionUsingML ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── BaseViewController.swift ├── CarDetectionUsingML.xcdatamodeld │ ├── .xccurrentversion │ └── CarDetectionUsingML.xcdatamodel │ │ └── contents ├── Info.plist └── Machine Learning Modules │ ├── ImagePreProcessing.swift │ ├── car_detection_keras_CNN.mlmodel │ └── car_detection_keras_DNN.mlmodel ├── CarDetectionUsingMLTests ├── CarDetectionUsingMLTests.swift └── Info.plist ├── CarDetectionUsingMLUITests ├── CarDetectionUsingMLUITests.swift └── Info.plist └── README.md /CarDetectionUsingML.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 80EC398D1F4ED0A000673975 /* car_detection_keras_DNN.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 80EC398C1F4ED09B00673975 /* car_detection_keras_DNN.mlmodel */; }; 11 | 80EC398E1F4ED0A300673975 /* car_detection_keras_CNN.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 80EC398B1F4ED08500673975 /* car_detection_keras_CNN.mlmodel */; }; 12 | 80FCBB4C1F2C60180081A0B8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB4B1F2C60180081A0B8 /* AppDelegate.swift */; }; 13 | 80FCBB4E1F2C60180081A0B8 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB4D1F2C60180081A0B8 /* BaseViewController.swift */; }; 14 | 80FCBB511F2C60180081A0B8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 80FCBB4F1F2C60180081A0B8 /* Main.storyboard */; }; 15 | 80FCBB541F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB521F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodeld */; }; 16 | 80FCBB561F2C60180081A0B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 80FCBB551F2C60180081A0B8 /* Assets.xcassets */; }; 17 | 80FCBB591F2C60180081A0B8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 80FCBB571F2C60180081A0B8 /* LaunchScreen.storyboard */; }; 18 | 80FCBB641F2C60180081A0B8 /* CarDetectionUsingMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB631F2C60180081A0B8 /* CarDetectionUsingMLTests.swift */; }; 19 | 80FCBB6F1F2C60180081A0B8 /* CarDetectionUsingMLUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB6E1F2C60180081A0B8 /* CarDetectionUsingMLUITests.swift */; }; 20 | 80FCBB831F2C63300081A0B8 /* ImagePreProcessing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FCBB801F2C63300081A0B8 /* ImagePreProcessing.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 80FCBB601F2C60180081A0B8 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 80FCBB401F2C60180081A0B8 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 80FCBB471F2C60180081A0B8; 29 | remoteInfo = CarDetectionUsingML; 30 | }; 31 | 80FCBB6B1F2C60180081A0B8 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 80FCBB401F2C60180081A0B8 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 80FCBB471F2C60180081A0B8; 36 | remoteInfo = CarDetectionUsingML; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 80EC398B1F4ED08500673975 /* car_detection_keras_CNN.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = car_detection_keras_CNN.mlmodel; sourceTree = ""; }; 42 | 80EC398C1F4ED09B00673975 /* car_detection_keras_DNN.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = car_detection_keras_DNN.mlmodel; sourceTree = ""; }; 43 | 80FCBB481F2C60180081A0B8 /* CarDetectionUsingML.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CarDetectionUsingML.app; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 80FCBB4B1F2C60180081A0B8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 45 | 80FCBB4D1F2C60180081A0B8 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; 46 | 80FCBB501F2C60180081A0B8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 47 | 80FCBB531F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CarDetectionUsingML.xcdatamodel; sourceTree = ""; }; 48 | 80FCBB551F2C60180081A0B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 80FCBB581F2C60180081A0B8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | 80FCBB5A1F2C60180081A0B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 80FCBB5F1F2C60180081A0B8 /* CarDetectionUsingMLTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CarDetectionUsingMLTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 80FCBB631F2C60180081A0B8 /* CarDetectionUsingMLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarDetectionUsingMLTests.swift; sourceTree = ""; }; 53 | 80FCBB651F2C60180081A0B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 80FCBB6A1F2C60180081A0B8 /* CarDetectionUsingMLUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CarDetectionUsingMLUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 80FCBB6E1F2C60180081A0B8 /* CarDetectionUsingMLUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarDetectionUsingMLUITests.swift; sourceTree = ""; }; 56 | 80FCBB701F2C60180081A0B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | 80FCBB801F2C63300081A0B8 /* ImagePreProcessing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePreProcessing.swift; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 80FCBB451F2C60180081A0B8 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 80FCBB5C1F2C60180081A0B8 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 80FCBB671F2C60180081A0B8 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | /* End PBXFrameworksBuildPhase section */ 83 | 84 | /* Begin PBXGroup section */ 85 | 80FCBB3F1F2C60180081A0B8 = { 86 | isa = PBXGroup; 87 | children = ( 88 | 80FCBB4A1F2C60180081A0B8 /* CarDetectionUsingML */, 89 | 80FCBB621F2C60180081A0B8 /* CarDetectionUsingMLTests */, 90 | 80FCBB6D1F2C60180081A0B8 /* CarDetectionUsingMLUITests */, 91 | 80FCBB491F2C60180081A0B8 /* Products */, 92 | ); 93 | sourceTree = ""; 94 | }; 95 | 80FCBB491F2C60180081A0B8 /* Products */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 80FCBB481F2C60180081A0B8 /* CarDetectionUsingML.app */, 99 | 80FCBB5F1F2C60180081A0B8 /* CarDetectionUsingMLTests.xctest */, 100 | 80FCBB6A1F2C60180081A0B8 /* CarDetectionUsingMLUITests.xctest */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | 80FCBB4A1F2C60180081A0B8 /* CarDetectionUsingML */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 80FCBB4B1F2C60180081A0B8 /* AppDelegate.swift */, 109 | 80FCBB4D1F2C60180081A0B8 /* BaseViewController.swift */, 110 | 80FCBB7E1F2C63300081A0B8 /* Machine Learning Modules */, 111 | 80FCBB7C1F2C62FD0081A0B8 /* View */, 112 | 80FCBB5A1F2C60180081A0B8 /* Info.plist */, 113 | 80FCBB7D1F2C63110081A0B8 /* CoreData */, 114 | ); 115 | path = CarDetectionUsingML; 116 | sourceTree = ""; 117 | }; 118 | 80FCBB621F2C60180081A0B8 /* CarDetectionUsingMLTests */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 80FCBB631F2C60180081A0B8 /* CarDetectionUsingMLTests.swift */, 122 | 80FCBB651F2C60180081A0B8 /* Info.plist */, 123 | ); 124 | path = CarDetectionUsingMLTests; 125 | sourceTree = ""; 126 | }; 127 | 80FCBB6D1F2C60180081A0B8 /* CarDetectionUsingMLUITests */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 80FCBB6E1F2C60180081A0B8 /* CarDetectionUsingMLUITests.swift */, 131 | 80FCBB701F2C60180081A0B8 /* Info.plist */, 132 | ); 133 | path = CarDetectionUsingMLUITests; 134 | sourceTree = ""; 135 | }; 136 | 80FCBB7C1F2C62FD0081A0B8 /* View */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 80FCBB4F1F2C60180081A0B8 /* Main.storyboard */, 140 | 80FCBB551F2C60180081A0B8 /* Assets.xcassets */, 141 | 80FCBB571F2C60180081A0B8 /* LaunchScreen.storyboard */, 142 | ); 143 | name = View; 144 | sourceTree = ""; 145 | }; 146 | 80FCBB7D1F2C63110081A0B8 /* CoreData */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | 80FCBB521F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodeld */, 150 | ); 151 | name = CoreData; 152 | sourceTree = ""; 153 | }; 154 | 80FCBB7E1F2C63300081A0B8 /* Machine Learning Modules */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 80EC398B1F4ED08500673975 /* car_detection_keras_CNN.mlmodel */, 158 | 80EC398C1F4ED09B00673975 /* car_detection_keras_DNN.mlmodel */, 159 | 80FCBB801F2C63300081A0B8 /* ImagePreProcessing.swift */, 160 | ); 161 | path = "Machine Learning Modules"; 162 | sourceTree = ""; 163 | }; 164 | /* End PBXGroup section */ 165 | 166 | /* Begin PBXNativeTarget section */ 167 | 80FCBB471F2C60180081A0B8 /* CarDetectionUsingML */ = { 168 | isa = PBXNativeTarget; 169 | buildConfigurationList = 80FCBB731F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingML" */; 170 | buildPhases = ( 171 | 80FCBB441F2C60180081A0B8 /* Sources */, 172 | 80FCBB451F2C60180081A0B8 /* Frameworks */, 173 | 80FCBB461F2C60180081A0B8 /* Resources */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | ); 179 | name = CarDetectionUsingML; 180 | productName = CarDetectionUsingML; 181 | productReference = 80FCBB481F2C60180081A0B8 /* CarDetectionUsingML.app */; 182 | productType = "com.apple.product-type.application"; 183 | }; 184 | 80FCBB5E1F2C60180081A0B8 /* CarDetectionUsingMLTests */ = { 185 | isa = PBXNativeTarget; 186 | buildConfigurationList = 80FCBB761F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingMLTests" */; 187 | buildPhases = ( 188 | 80FCBB5B1F2C60180081A0B8 /* Sources */, 189 | 80FCBB5C1F2C60180081A0B8 /* Frameworks */, 190 | 80FCBB5D1F2C60180081A0B8 /* Resources */, 191 | ); 192 | buildRules = ( 193 | ); 194 | dependencies = ( 195 | 80FCBB611F2C60180081A0B8 /* PBXTargetDependency */, 196 | ); 197 | name = CarDetectionUsingMLTests; 198 | productName = CarDetectionUsingMLTests; 199 | productReference = 80FCBB5F1F2C60180081A0B8 /* CarDetectionUsingMLTests.xctest */; 200 | productType = "com.apple.product-type.bundle.unit-test"; 201 | }; 202 | 80FCBB691F2C60180081A0B8 /* CarDetectionUsingMLUITests */ = { 203 | isa = PBXNativeTarget; 204 | buildConfigurationList = 80FCBB791F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingMLUITests" */; 205 | buildPhases = ( 206 | 80FCBB661F2C60180081A0B8 /* Sources */, 207 | 80FCBB671F2C60180081A0B8 /* Frameworks */, 208 | 80FCBB681F2C60180081A0B8 /* Resources */, 209 | ); 210 | buildRules = ( 211 | ); 212 | dependencies = ( 213 | 80FCBB6C1F2C60180081A0B8 /* PBXTargetDependency */, 214 | ); 215 | name = CarDetectionUsingMLUITests; 216 | productName = CarDetectionUsingMLUITests; 217 | productReference = 80FCBB6A1F2C60180081A0B8 /* CarDetectionUsingMLUITests.xctest */; 218 | productType = "com.apple.product-type.bundle.ui-testing"; 219 | }; 220 | /* End PBXNativeTarget section */ 221 | 222 | /* Begin PBXProject section */ 223 | 80FCBB401F2C60180081A0B8 /* Project object */ = { 224 | isa = PBXProject; 225 | attributes = { 226 | LastSwiftUpdateCheck = 0830; 227 | LastUpgradeCheck = 0830; 228 | ORGANIZATIONNAME = "Ashis Laha"; 229 | TargetAttributes = { 230 | 80FCBB471F2C60180081A0B8 = { 231 | CreatedOnToolsVersion = 8.3.2; 232 | DevelopmentTeam = W3Z9URG96M; 233 | ProvisioningStyle = Automatic; 234 | }; 235 | 80FCBB5E1F2C60180081A0B8 = { 236 | CreatedOnToolsVersion = 8.3.2; 237 | DevelopmentTeam = 87F557PJ6U; 238 | ProvisioningStyle = Automatic; 239 | TestTargetID = 80FCBB471F2C60180081A0B8; 240 | }; 241 | 80FCBB691F2C60180081A0B8 = { 242 | CreatedOnToolsVersion = 8.3.2; 243 | DevelopmentTeam = 87F557PJ6U; 244 | ProvisioningStyle = Automatic; 245 | TestTargetID = 80FCBB471F2C60180081A0B8; 246 | }; 247 | }; 248 | }; 249 | buildConfigurationList = 80FCBB431F2C60180081A0B8 /* Build configuration list for PBXProject "CarDetectionUsingML" */; 250 | compatibilityVersion = "Xcode 3.2"; 251 | developmentRegion = English; 252 | hasScannedForEncodings = 0; 253 | knownRegions = ( 254 | en, 255 | Base, 256 | ); 257 | mainGroup = 80FCBB3F1F2C60180081A0B8; 258 | productRefGroup = 80FCBB491F2C60180081A0B8 /* Products */; 259 | projectDirPath = ""; 260 | projectRoot = ""; 261 | targets = ( 262 | 80FCBB471F2C60180081A0B8 /* CarDetectionUsingML */, 263 | 80FCBB5E1F2C60180081A0B8 /* CarDetectionUsingMLTests */, 264 | 80FCBB691F2C60180081A0B8 /* CarDetectionUsingMLUITests */, 265 | ); 266 | }; 267 | /* End PBXProject section */ 268 | 269 | /* Begin PBXResourcesBuildPhase section */ 270 | 80FCBB461F2C60180081A0B8 /* Resources */ = { 271 | isa = PBXResourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | 80FCBB591F2C60180081A0B8 /* LaunchScreen.storyboard in Resources */, 275 | 80FCBB561F2C60180081A0B8 /* Assets.xcassets in Resources */, 276 | 80FCBB511F2C60180081A0B8 /* Main.storyboard in Resources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | 80FCBB5D1F2C60180081A0B8 /* Resources */ = { 281 | isa = PBXResourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | 80FCBB681F2C60180081A0B8 /* Resources */ = { 288 | isa = PBXResourcesBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | /* End PBXResourcesBuildPhase section */ 295 | 296 | /* Begin PBXSourcesBuildPhase section */ 297 | 80FCBB441F2C60180081A0B8 /* Sources */ = { 298 | isa = PBXSourcesBuildPhase; 299 | buildActionMask = 2147483647; 300 | files = ( 301 | 80EC398E1F4ED0A300673975 /* car_detection_keras_CNN.mlmodel in Sources */, 302 | 80FCBB831F2C63300081A0B8 /* ImagePreProcessing.swift in Sources */, 303 | 80FCBB541F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodeld in Sources */, 304 | 80EC398D1F4ED0A000673975 /* car_detection_keras_DNN.mlmodel in Sources */, 305 | 80FCBB4E1F2C60180081A0B8 /* BaseViewController.swift in Sources */, 306 | 80FCBB4C1F2C60180081A0B8 /* AppDelegate.swift in Sources */, 307 | ); 308 | runOnlyForDeploymentPostprocessing = 0; 309 | }; 310 | 80FCBB5B1F2C60180081A0B8 /* Sources */ = { 311 | isa = PBXSourcesBuildPhase; 312 | buildActionMask = 2147483647; 313 | files = ( 314 | 80FCBB641F2C60180081A0B8 /* CarDetectionUsingMLTests.swift in Sources */, 315 | ); 316 | runOnlyForDeploymentPostprocessing = 0; 317 | }; 318 | 80FCBB661F2C60180081A0B8 /* Sources */ = { 319 | isa = PBXSourcesBuildPhase; 320 | buildActionMask = 2147483647; 321 | files = ( 322 | 80FCBB6F1F2C60180081A0B8 /* CarDetectionUsingMLUITests.swift in Sources */, 323 | ); 324 | runOnlyForDeploymentPostprocessing = 0; 325 | }; 326 | /* End PBXSourcesBuildPhase section */ 327 | 328 | /* Begin PBXTargetDependency section */ 329 | 80FCBB611F2C60180081A0B8 /* PBXTargetDependency */ = { 330 | isa = PBXTargetDependency; 331 | target = 80FCBB471F2C60180081A0B8 /* CarDetectionUsingML */; 332 | targetProxy = 80FCBB601F2C60180081A0B8 /* PBXContainerItemProxy */; 333 | }; 334 | 80FCBB6C1F2C60180081A0B8 /* PBXTargetDependency */ = { 335 | isa = PBXTargetDependency; 336 | target = 80FCBB471F2C60180081A0B8 /* CarDetectionUsingML */; 337 | targetProxy = 80FCBB6B1F2C60180081A0B8 /* PBXContainerItemProxy */; 338 | }; 339 | /* End PBXTargetDependency section */ 340 | 341 | /* Begin PBXVariantGroup section */ 342 | 80FCBB4F1F2C60180081A0B8 /* Main.storyboard */ = { 343 | isa = PBXVariantGroup; 344 | children = ( 345 | 80FCBB501F2C60180081A0B8 /* Base */, 346 | ); 347 | name = Main.storyboard; 348 | sourceTree = ""; 349 | }; 350 | 80FCBB571F2C60180081A0B8 /* LaunchScreen.storyboard */ = { 351 | isa = PBXVariantGroup; 352 | children = ( 353 | 80FCBB581F2C60180081A0B8 /* Base */, 354 | ); 355 | name = LaunchScreen.storyboard; 356 | sourceTree = ""; 357 | }; 358 | /* End PBXVariantGroup section */ 359 | 360 | /* Begin XCBuildConfiguration section */ 361 | 80FCBB711F2C60180081A0B8 /* Debug */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ALWAYS_SEARCH_USER_PATHS = NO; 365 | CLANG_ANALYZER_NONNULL = YES; 366 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 367 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 368 | CLANG_CXX_LIBRARY = "libc++"; 369 | CLANG_ENABLE_MODULES = YES; 370 | CLANG_ENABLE_OBJC_ARC = YES; 371 | CLANG_WARN_BOOL_CONVERSION = YES; 372 | CLANG_WARN_CONSTANT_CONVERSION = YES; 373 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 374 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 375 | CLANG_WARN_EMPTY_BODY = YES; 376 | CLANG_WARN_ENUM_CONVERSION = YES; 377 | CLANG_WARN_INFINITE_RECURSION = YES; 378 | CLANG_WARN_INT_CONVERSION = YES; 379 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 380 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = dwarf; 386 | ENABLE_STRICT_OBJC_MSGSEND = YES; 387 | ENABLE_TESTABILITY = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu99; 389 | GCC_DYNAMIC_NO_PIC = NO; 390 | GCC_NO_COMMON_BLOCKS = YES; 391 | GCC_OPTIMIZATION_LEVEL = 0; 392 | GCC_PREPROCESSOR_DEFINITIONS = ( 393 | "DEBUG=1", 394 | "$(inherited)", 395 | ); 396 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 397 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 398 | GCC_WARN_UNDECLARED_SELECTOR = YES; 399 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 400 | GCC_WARN_UNUSED_FUNCTION = YES; 401 | GCC_WARN_UNUSED_VARIABLE = YES; 402 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 403 | MTL_ENABLE_DEBUG_INFO = YES; 404 | ONLY_ACTIVE_ARCH = YES; 405 | SDKROOT = iphoneos; 406 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 407 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 408 | TARGETED_DEVICE_FAMILY = "1,2"; 409 | }; 410 | name = Debug; 411 | }; 412 | 80FCBB721F2C60180081A0B8 /* Release */ = { 413 | isa = XCBuildConfiguration; 414 | buildSettings = { 415 | ALWAYS_SEARCH_USER_PATHS = NO; 416 | CLANG_ANALYZER_NONNULL = YES; 417 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 418 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 419 | CLANG_CXX_LIBRARY = "libc++"; 420 | CLANG_ENABLE_MODULES = YES; 421 | CLANG_ENABLE_OBJC_ARC = YES; 422 | CLANG_WARN_BOOL_CONVERSION = YES; 423 | CLANG_WARN_CONSTANT_CONVERSION = YES; 424 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 425 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 426 | CLANG_WARN_EMPTY_BODY = YES; 427 | CLANG_WARN_ENUM_CONVERSION = YES; 428 | CLANG_WARN_INFINITE_RECURSION = YES; 429 | CLANG_WARN_INT_CONVERSION = YES; 430 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 431 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 432 | CLANG_WARN_UNREACHABLE_CODE = YES; 433 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 434 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 435 | COPY_PHASE_STRIP = NO; 436 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 437 | ENABLE_NS_ASSERTIONS = NO; 438 | ENABLE_STRICT_OBJC_MSGSEND = YES; 439 | GCC_C_LANGUAGE_STANDARD = gnu99; 440 | GCC_NO_COMMON_BLOCKS = YES; 441 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 442 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 443 | GCC_WARN_UNDECLARED_SELECTOR = YES; 444 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 445 | GCC_WARN_UNUSED_FUNCTION = YES; 446 | GCC_WARN_UNUSED_VARIABLE = YES; 447 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 448 | MTL_ENABLE_DEBUG_INFO = NO; 449 | SDKROOT = iphoneos; 450 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 451 | TARGETED_DEVICE_FAMILY = "1,2"; 452 | VALIDATE_PRODUCT = YES; 453 | }; 454 | name = Release; 455 | }; 456 | 80FCBB741F2C60180081A0B8 /* Debug */ = { 457 | isa = XCBuildConfiguration; 458 | buildSettings = { 459 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 460 | DEVELOPMENT_TEAM = W3Z9URG96M; 461 | INFOPLIST_FILE = CarDetectionUsingML/Info.plist; 462 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 464 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingNeuralNetwork; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | SWIFT_VERSION = 3.0; 467 | }; 468 | name = Debug; 469 | }; 470 | 80FCBB751F2C60180081A0B8 /* Release */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 474 | DEVELOPMENT_TEAM = W3Z9URG96M; 475 | INFOPLIST_FILE = CarDetectionUsingML/Info.plist; 476 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 477 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 478 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingNeuralNetwork; 479 | PRODUCT_NAME = "$(TARGET_NAME)"; 480 | SWIFT_VERSION = 3.0; 481 | }; 482 | name = Release; 483 | }; 484 | 80FCBB771F2C60180081A0B8 /* Debug */ = { 485 | isa = XCBuildConfiguration; 486 | buildSettings = { 487 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 488 | BUNDLE_LOADER = "$(TEST_HOST)"; 489 | DEVELOPMENT_TEAM = 87F557PJ6U; 490 | INFOPLIST_FILE = CarDetectionUsingMLTests/Info.plist; 491 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 492 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingMLTests; 493 | PRODUCT_NAME = "$(TARGET_NAME)"; 494 | SWIFT_VERSION = 3.0; 495 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CarDetectionUsingML.app/CarDetectionUsingML"; 496 | }; 497 | name = Debug; 498 | }; 499 | 80FCBB781F2C60180081A0B8 /* Release */ = { 500 | isa = XCBuildConfiguration; 501 | buildSettings = { 502 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 503 | BUNDLE_LOADER = "$(TEST_HOST)"; 504 | DEVELOPMENT_TEAM = 87F557PJ6U; 505 | INFOPLIST_FILE = CarDetectionUsingMLTests/Info.plist; 506 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 507 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingMLTests; 508 | PRODUCT_NAME = "$(TARGET_NAME)"; 509 | SWIFT_VERSION = 3.0; 510 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CarDetectionUsingML.app/CarDetectionUsingML"; 511 | }; 512 | name = Release; 513 | }; 514 | 80FCBB7A1F2C60180081A0B8 /* Debug */ = { 515 | isa = XCBuildConfiguration; 516 | buildSettings = { 517 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 518 | DEVELOPMENT_TEAM = 87F557PJ6U; 519 | INFOPLIST_FILE = CarDetectionUsingMLUITests/Info.plist; 520 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 521 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingMLUITests; 522 | PRODUCT_NAME = "$(TARGET_NAME)"; 523 | SWIFT_VERSION = 3.0; 524 | TEST_TARGET_NAME = CarDetectionUsingML; 525 | }; 526 | name = Debug; 527 | }; 528 | 80FCBB7B1F2C60180081A0B8 /* Release */ = { 529 | isa = XCBuildConfiguration; 530 | buildSettings = { 531 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 532 | DEVELOPMENT_TEAM = 87F557PJ6U; 533 | INFOPLIST_FILE = CarDetectionUsingMLUITests/Info.plist; 534 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 535 | PRODUCT_BUNDLE_IDENTIFIER = ALaha.CarDetectionUsingMLUITests; 536 | PRODUCT_NAME = "$(TARGET_NAME)"; 537 | SWIFT_VERSION = 3.0; 538 | TEST_TARGET_NAME = CarDetectionUsingML; 539 | }; 540 | name = Release; 541 | }; 542 | /* End XCBuildConfiguration section */ 543 | 544 | /* Begin XCConfigurationList section */ 545 | 80FCBB431F2C60180081A0B8 /* Build configuration list for PBXProject "CarDetectionUsingML" */ = { 546 | isa = XCConfigurationList; 547 | buildConfigurations = ( 548 | 80FCBB711F2C60180081A0B8 /* Debug */, 549 | 80FCBB721F2C60180081A0B8 /* Release */, 550 | ); 551 | defaultConfigurationIsVisible = 0; 552 | defaultConfigurationName = Release; 553 | }; 554 | 80FCBB731F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingML" */ = { 555 | isa = XCConfigurationList; 556 | buildConfigurations = ( 557 | 80FCBB741F2C60180081A0B8 /* Debug */, 558 | 80FCBB751F2C60180081A0B8 /* Release */, 559 | ); 560 | defaultConfigurationIsVisible = 0; 561 | defaultConfigurationName = Release; 562 | }; 563 | 80FCBB761F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingMLTests" */ = { 564 | isa = XCConfigurationList; 565 | buildConfigurations = ( 566 | 80FCBB771F2C60180081A0B8 /* Debug */, 567 | 80FCBB781F2C60180081A0B8 /* Release */, 568 | ); 569 | defaultConfigurationIsVisible = 0; 570 | defaultConfigurationName = Release; 571 | }; 572 | 80FCBB791F2C60180081A0B8 /* Build configuration list for PBXNativeTarget "CarDetectionUsingMLUITests" */ = { 573 | isa = XCConfigurationList; 574 | buildConfigurations = ( 575 | 80FCBB7A1F2C60180081A0B8 /* Debug */, 576 | 80FCBB7B1F2C60180081A0B8 /* Release */, 577 | ); 578 | defaultConfigurationIsVisible = 0; 579 | defaultConfigurationName = Release; 580 | }; 581 | /* End XCConfigurationList section */ 582 | 583 | /* Begin XCVersionGroup section */ 584 | 80FCBB521F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodeld */ = { 585 | isa = XCVersionGroup; 586 | children = ( 587 | 80FCBB531F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodel */, 588 | ); 589 | currentVersion = 80FCBB531F2C60180081A0B8 /* CarDetectionUsingML.xcdatamodel */; 590 | path = CarDetectionUsingML.xcdatamodeld; 591 | sourceTree = ""; 592 | versionGroupType = wrapper.xcdatamodel; 593 | }; 594 | /* End XCVersionGroup section */ 595 | }; 596 | rootObject = 80FCBB401F2C60180081A0B8 /* Project object */; 597 | } 598 | -------------------------------------------------------------------------------- /CarDetectionUsingML.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CarDetectionUsingML.xcodeproj/xcuserdata/ashis.laha.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CarDetectionUsingML.xcodeproj/xcuserdata/ashis.laha.xcuserdatad/xcschemes/CarDetectionUsingML.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /CarDetectionUsingML/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CarDetectionUsingML 4 | // 5 | // Created by Ashis Laha on 29/07/17. 6 | // Copyright © 2017 Ashis Laha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | // Override point for customization after application launch. 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // 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. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // 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. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | // Saves changes in the application's managed object context before the application terminates. 44 | self.saveContext() 45 | } 46 | 47 | // MARK: - Core Data stack 48 | 49 | lazy var persistentContainer: NSPersistentContainer = { 50 | /* 51 | The persistent container for the application. This implementation 52 | creates and returns a container, having loaded the store for the 53 | application to it. This property is optional since there are legitimate 54 | error conditions that could cause the creation of the store to fail. 55 | */ 56 | let container = NSPersistentContainer(name: "CarDetectionUsingML") 57 | container.loadPersistentStores(completionHandler: { (storeDescription, error) in 58 | if let error = error as NSError? { 59 | // Replace this implementation with code to handle the error appropriately. 60 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 61 | 62 | /* 63 | Typical reasons for an error here include: 64 | * The parent directory does not exist, cannot be created, or disallows writing. 65 | * The persistent store is not accessible, due to permissions or data protection when the device is locked. 66 | * The device is out of space. 67 | * The store could not be migrated to the current model version. 68 | Check the error message to determine what the actual problem was. 69 | */ 70 | fatalError("Unresolved error \(error), \(error.userInfo)") 71 | } 72 | }) 73 | return container 74 | }() 75 | 76 | // MARK: - Core Data Saving support 77 | 78 | func saveContext () { 79 | let context = persistentContainer.viewContext 80 | if context.hasChanges { 81 | do { 82 | try context.save() 83 | } catch { 84 | // Replace this implementation with code to handle the error appropriately. 85 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 86 | let nserror = error as NSError 87 | fatalError("Unresolved error \(nserror), \(nserror.userInfo)") 88 | } 89 | } 90 | } 91 | 92 | } 93 | 94 | -------------------------------------------------------------------------------- /CarDetectionUsingML/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CarDetectionUsingML/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 | -------------------------------------------------------------------------------- /CarDetectionUsingML/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 | 34 | 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 | -------------------------------------------------------------------------------- /CarDetectionUsingML/BaseViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CarDetectionUsingML 4 | // 5 | // Created by Ashis Laha on 29/07/17. 6 | // Copyright © 2017 Ashis Laha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreML 11 | import Vision 12 | 13 | enum ButtonAction { 14 | case takePhoto 15 | case identifyPhoto 16 | } 17 | 18 | enum Classifier { 19 | case DNN 20 | case CNN 21 | } 22 | 23 | class BaseViewController: UIViewController , UIImagePickerControllerDelegate, UINavigationControllerDelegate { 24 | 25 | let row = 100 26 | let column = 100 27 | let classes = 2 28 | 29 | var actionType : ButtonAction = .takePhoto { 30 | didSet { 31 | switch actionType { 32 | case .takePhoto : buttonOutlet.setTitle("Take Photo", for: .normal) 33 | case .identifyPhoto : buttonOutlet.setTitle("Identify Photo", for: .normal) 34 | } 35 | } 36 | } 37 | var classifier : Classifier = .CNN { 38 | didSet { 39 | switch classifier { 40 | case .CNN : title = "CNN" 41 | case .DNN : title = "DNN" 42 | } 43 | } 44 | } 45 | 46 | @IBAction func chooseClassifier(_ sender: UIBarButtonItem) { 47 | let actionSheet = UIAlertController(title: "Classfier", message: "", preferredStyle: .actionSheet) 48 | let dnn = UIAlertAction(title: "DNN", style: .default) { [weak self] (action) in 49 | self?.classifier = .DNN 50 | } 51 | let cnn = UIAlertAction(title: "CNN (Default)", style: .default) { [weak self] (action) in 52 | self?.classifier = .CNN 53 | } 54 | let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) 55 | actionSheet.addAction(cnn) 56 | actionSheet.addAction(dnn) 57 | actionSheet.addAction(cancel) 58 | self.present(actionSheet, animated: true, completion: nil) 59 | } 60 | 61 | @IBOutlet weak var imageView: UIImageView! { 62 | didSet { 63 | imageView.isHidden = true 64 | } 65 | } 66 | 67 | @IBOutlet weak var buttonOutlet: UIButton! { 68 | didSet { 69 | buttonOutlet.setTitle("Take Photo", for: .normal) 70 | buttonOutlet.backgroundColor = UIColor.brown.withAlphaComponent(0.5) 71 | } 72 | } 73 | 74 | @IBOutlet weak var label: UILabel! { 75 | didSet { 76 | label.isHidden = true 77 | } 78 | } 79 | 80 | @IBAction func buttonAction(_ sender: UIButton) { 81 | switch actionType { 82 | case .takePhoto : takePhoto() 83 | case .identifyPhoto: classify(image: imageView.image) 84 | } 85 | } 86 | 87 | override func viewDidLoad() { 88 | super.viewDidLoad() 89 | } 90 | 91 | private func takePhoto() { 92 | label.text = "" 93 | let imagePickerVC = UIImagePickerController() 94 | imagePickerVC.delegate = self 95 | 96 | let actionSheet = UIAlertController(title: "Take Photo", message: "Car Detection", preferredStyle: .actionSheet) 97 | let cameraAction = UIAlertAction(title: "Camera", style: .default) { [weak self] (action) in 98 | imagePickerVC.sourceType = .camera 99 | self?.present(imagePickerVC, animated: true, completion: nil) 100 | } 101 | actionSheet.addAction(cameraAction) 102 | 103 | let photoLibrary = UIAlertAction(title: "Photo Galary", style: .default) { [weak self] (action) in 104 | imagePickerVC.sourceType = .photoLibrary 105 | self?.present(imagePickerVC, animated: true, completion: nil) 106 | } 107 | actionSheet.addAction(photoLibrary) 108 | let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) 109 | actionSheet.addAction(cancelAction) 110 | self.present(actionSheet, animated: true, completion: nil) 111 | } 112 | 113 | // Delegate method 114 | func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 115 | picker.dismiss(animated: true, completion: nil) 116 | } 117 | 118 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 119 | if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { 120 | imageView.image = image 121 | imageView.isHidden = false 122 | actionType = .identifyPhoto 123 | } 124 | picker.dismiss(animated: true, completion: nil) 125 | } 126 | 127 | 128 | //MARK:- Classification 129 | 130 | private func classify(image : UIImage?) { 131 | 132 | guard let image = image else { return } 133 | let imageInfo : (image : UIImage, pixel: [Double]) = ImagePreProcessing.shared.preProcessImage(image: image) 134 | 135 | imageView.image = imageInfo.image 136 | label.isHidden = false 137 | 138 | if classifier == .DNN { 139 | let mlModel = car_detection_keras_DNN() // Input Matrix is [10000] Matrix - 1D Matrix 140 | guard let inputMatrix = try? MLMultiArray(shape: [10000], dataType: .double) else { fatalError("Unexpected runtime error. MLMultiArray") } 141 | 142 | // Feed data to inputMatrix 143 | for i in 0.. outputArray[1] ? "It's A CAR" : "It's not a CAR" 152 | } 153 | } else if self.classifier == .CNN { 154 | let mlModel = car_detection_keras_CNN() // Input Matrix is [1, 100, 100] Matrix - 1D Matrix 155 | 156 | guard let inputMatrix = try? MLMultiArray(shape: [1,100,100], dataType: .double) else { fatalError("Unexpected runtime error. MLMultiArray") } 157 | 158 | // Feed data to inputMatrix 159 | for i in 0.. outputArray[1] ? "It's A CAR" : "It's not a CAR" 168 | } 169 | } 170 | 171 | 172 | actionType = .takePhoto 173 | } 174 | 175 | 176 | //MARK:- Vision 177 | private func recognizeUsingVision() { 178 | let coreMLmodel = car_detection_keras_DNN() 179 | let model = try? VNCoreMLModel(for:coreMLmodel.model) 180 | let request = VNCoreMLRequest(model: model!, completionHandler: myResultsMethod) 181 | if let cgImage = imageView.image?.cgImage { 182 | let handler = VNImageRequestHandler(cgImage:cgImage, options: [:] ) 183 | try? handler.perform([request]) 184 | } 185 | } 186 | 187 | private func myResultsMethod(request: VNRequest, error: Error?) { 188 | guard let results = request.results as? [VNClassificationObservation] else { fatalError("Error in Results") } 189 | for classification in results { 190 | if classification.confidence > 0.25 { 191 | print(classification.identifier, classification.confidence) 192 | label.text = classification.identifier 193 | } 194 | } 195 | } 196 | } 197 | 198 | 199 | -------------------------------------------------------------------------------- /CarDetectionUsingML/CarDetectionUsingML.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | CarDetectionUsingML.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /CarDetectionUsingML/CarDetectionUsingML.xcdatamodeld/CarDetectionUsingML.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CarDetectionUsingML/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSCameraUsageDescription 6 | camera 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CarDetectionUsingML/Machine Learning Modules/ImagePreProcessing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImagePreProcessing.swift 3 | // Handwritten Recognition 4 | // 5 | // Created by Ashis Laha on 07/03/17. 6 | // Copyright © 2017 Ashis Laha. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreGraphics 11 | import UIKit 12 | 13 | /* 14 | Image Preprocessing : 15 | 16 | 1. Normalize Aspect ratio with respect to N*M dimension 17 | 2. Edge detection of the image 18 | 3. Reduce the noise from image 19 | 20 | */ 21 | 22 | 23 | struct ImageProcessingConstants { 24 | static let maxDimension : CGFloat = 120 25 | static let optimalDimensionX : Int = 100 26 | static let optimalDimensionY : Int = 100 27 | // For Edge Detection 28 | static let intensityThreshold : Double = 120 29 | } 30 | 31 | struct PixelData { 32 | var r : UInt8 = 0 33 | var g : UInt8 = 0 34 | var b : UInt8 = 0 35 | var a : UInt8 = 0 36 | } 37 | 38 | // Crop the picture 10 % 39 | private extension UIImage { 40 | 41 | func crop( rect: CGRect) -> UIImage { 42 | var rect = rect 43 | rect.origin.x*=self.scale 44 | rect.origin.y*=self.scale 45 | rect.size.width*=self.scale 46 | rect.size.height*=self.scale 47 | 48 | let imageRef = self.cgImage!.cropping(to: rect) 49 | let image = UIImage(cgImage: imageRef!, scale: self.scale, orientation: self.imageOrientation) 50 | return image 51 | } 52 | } 53 | 54 | 55 | class ImagePreProcessing { 56 | 57 | static let shared = ImagePreProcessing() 58 | private init() { } 59 | 60 | var optimalPixelMatrix = [[Double]]() 61 | var pixelData = [[PixelData]]() 62 | 63 | private func mask8( x : UInt32) -> UInt32 { return x & 0xFF } 64 | private func R(x : UInt32) -> UInt32 { return mask8(x: x) } 65 | private func G(x : UInt32) -> UInt32 { return mask8(x: x >> 8 )} 66 | private func B(x : UInt32) -> UInt32 { return mask8(x: x >> 16)} 67 | private func alphaComponent(x : UInt32) -> UInt32 { return mask8(x: x>>24)} 68 | private func RGBAlphaMake( r : UInt32, g : UInt32, b : UInt32, alpha : UInt32 ) -> UInt32 { return mask8(x: r) | mask8(x: g<<8) | mask8(x: b<<16) | mask8(x: alpha<<24)} 69 | 70 | public func preProcessImage(image : UIImage ) -> (UIImage, [Double]) { 71 | 72 | var grayScalePixels : [Double] = [] 73 | // Resize the image 74 | let smallSizeImage = resizeImage(image: image, targetSize: CGSize(width: 2 * 100.0, height: 2 * 100.0)) 75 | 76 | // Make it Gray 77 | if let grayImage = grayScaleImage(image : smallSizeImage) { 78 | // Compute Pixel Information 79 | grayScalePixels = normalizedIntensityMatrix(image: grayImage) 80 | return (grayImage, grayScalePixels) 81 | } 82 | 83 | return (smallSizeImage, grayScalePixels) 84 | } 85 | 86 | // MARK:- Crop the image 10% around 87 | 88 | private func cropImage(image : UIImage ) -> UIImage { 89 | let imageWidth = image.size.width 90 | let imageHeight = image.size.height 91 | let cropWidth = imageWidth * 0.8 92 | let cropHeight = imageWidth * 0.8 93 | 94 | let origin = CGPoint(x: (imageWidth - cropWidth)/2, y: (imageHeight-cropHeight)/2) 95 | let size = CGSize(width: cropWidth, height: cropHeight) 96 | 97 | return image.crop(rect: CGRect(origin: origin, size: size)) 98 | } 99 | 100 | 101 | //MARK:- Resize Image 102 | 103 | private func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage { 104 | let size = image.size 105 | 106 | let widthRatio = targetSize.width / image.size.width 107 | let heightRatio = targetSize.height / image.size.height 108 | 109 | // Figure out what our orientation is, and use that to form the rectangle 110 | var newSize: CGSize 111 | if(widthRatio < heightRatio) { 112 | newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio) 113 | } else { 114 | newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio) 115 | } 116 | 117 | // This is the rect that we've calculated out and this is what is actually used below 118 | let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height) 119 | 120 | // Actually do the resizing to the rect using the ImageContext stuff 121 | 122 | UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) 123 | image.draw(in: rect) 124 | guard let scaledImage = UIGraphicsGetImageFromCurrentImageContext() else { return UIImage() } 125 | UIGraphicsEndImageContext() 126 | return scaledImage 127 | } 128 | 129 | //MARK:- GrayScale Image 130 | 131 | private func grayScaleImage(image : UIImage) -> UIImage? { 132 | UIGraphicsBeginImageContextWithOptions(image.size, true, 1.0) 133 | let rect = CGRect(origin: CGPoint.zero, size: image.size) 134 | image.draw(in: rect, blendMode: .luminosity, alpha: 1.0) 135 | let returnImage = UIGraphicsGetImageFromCurrentImageContext() 136 | UIGraphicsEndImageContext() 137 | return returnImage 138 | } 139 | 140 | //MARK:- Normalized Image 141 | 142 | fileprivate func normalizedIntensityMatrix(image: UIImage) -> [Double] { 143 | let logMatrix = logPixelOfImage(image: image) 144 | return create1DMatrix(inputMatrix: logMatrix) 145 | } 146 | 147 | //MARK:- Log Pixel image 148 | 149 | fileprivate func logPixelOfImage(image : UIImage) -> [[Double]] { 150 | guard let coreImageRef = image.cgImage else { return [] } 151 | let height = coreImageRef.height 152 | let width = coreImageRef.width 153 | 154 | let bytesPerPixel = coreImageRef.bitsPerPixel / 8 // 1 byte = 8 bits 155 | let bytesPerRow = bytesPerPixel * width 156 | let bitsPerComponent = coreImageRef.bitsPerComponent 157 | 158 | let pixels = UnsafeMutablePointer.allocate(capacity: height * width) 159 | let colorSpace = CGColorSpaceCreateDeviceRGB() 160 | let context = CGContext(data: pixels, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: colorSpace,bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 161 | context?.draw(coreImageRef, in: CGRect(x: 0, y: 0, width: width, height: height)) 162 | 163 | var pixelMatrix = [[Double]]() 164 | var tempPixels = pixels 165 | 166 | for i in 0.. 0 { pixelMatrix.append(rowData) } 184 | if rowPixel.count > 0 { pixelData.append(rowPixel) } 185 | } 186 | free(pixels) 187 | return pixelMatrix 188 | } 189 | 190 | fileprivate func create1DMatrix(inputMatrix : [[Double]]) -> [Double] { 191 | var intensities = [Double]() 192 | for i in 0.. [[Double]] { 221 | 222 | // apply gaussian filter to remove noise 223 | let gaussainOutput = gaussianFilter(inputMatrix:inputMatrix) 224 | printMatrix(inputMatrix: gaussainOutput, name : "Gaussain Output") 225 | 226 | // Find the intensity gradients of the image (apply sobel operator) 227 | let sobelOutput = sobelOperator(inputMatrix: gaussainOutput) 228 | printMatrix(inputMatrix: sobelOutput, name : "Sobel Output") 229 | 230 | // Apply non-maximum suppression to get rid of spurious response to edge detection 231 | let suppressedMatrix = suppression(inputMatrix: sobelOutput, intensityThreshold: ImageProcessingConstants.intensityThreshold) 232 | printMatrix(inputMatrix: suppressedMatrix, name : "Supression") 233 | 234 | return suppressedMatrix 235 | } 236 | 237 | //MARK:- Remove noise from Image 238 | 239 | func gaussianFilter(inputMatrix : [[Double]]) -> [[Double]] { // use 5*5 filter 240 | 241 | let gaussainMatrix = [ 242 | [ 2.0, 4.0, 5.0, 4.0, 2.0 ], 243 | [ 4.0, 9.0, 12.0, 9.0, 4.0], 244 | [ 5.0, 12.0, 15.0, 12.0, 5.0], 245 | [ 4.0, 9.0, 12.0, 9.0, 4.0], 246 | [ 2.0, 4.0, 5.0, 4.0, 2.0 ] 247 | ] 248 | var filteredMatrix = [[Double]]() 249 | 250 | // intialize filteredMatrix 251 | 252 | for _ in 0.. [[Double]] { 287 | 288 | var filteredOutput = [[Double]]() 289 | 290 | // Initialize all elements with Zero elements 291 | 292 | for _ in 0.. [[Double]] { 335 | 336 | var results = [[Double]]() 337 | 338 | //initialise 339 | for _ in 0.. intensityThreshold { 353 | input = 255 354 | } 355 | results[row][column] = 255 - input 356 | } 357 | } 358 | return results 359 | } 360 | 361 | 362 | 363 | //MARK:- Create Image from Pixel data 364 | 365 | fileprivate func createImageFromRGBData(inputMatrix : [Double], width : Int, height : Int) -> UIImage { 366 | 367 | var resultImage = UIImage() 368 | let bytesPerPixel = 4 // 4 bytes or 32 bits 369 | let bytesPerRow = bytesPerPixel * width 370 | let bitsPerComponent = 8 // rgba, so total lenghth = 32 bits 371 | var pixelData = inputMatrix 372 | let bitmapContext = CGContext(data: &pixelData[0], width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) 373 | 374 | if let cgImage = bitmapContext?.makeImage() { 375 | let image = UIImage(cgImage: cgImage) 376 | resultImage = image 377 | } 378 | return resultImage 379 | } 380 | 381 | // MARK:- CVPixelBuffer convert 382 | 383 | class func buffer(from image: UIImage) -> CVPixelBuffer? { 384 | let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary 385 | var pixelBuffer : CVPixelBuffer? 386 | let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(image.size.width), Int(image.size.height), kCVPixelFormatType_32ARGB, attrs, &pixelBuffer) 387 | guard (status == kCVReturnSuccess) else { return nil } 388 | 389 | CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 390 | let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!) 391 | 392 | let rgbColorSpace = CGColorSpaceCreateDeviceRGB() 393 | let context = CGContext(data: pixelData, width: Int(image.size.width), height: Int(image.size.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) 394 | 395 | context?.translateBy(x: 0, y: image.size.height) 396 | context?.scaleBy(x: 1.0, y: -1.0) 397 | 398 | UIGraphicsPushContext(context!) 399 | image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)) 400 | UIGraphicsPopContext() 401 | CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 402 | 403 | return pixelBuffer 404 | } 405 | } 406 | 407 | -------------------------------------------------------------------------------- /CarDetectionUsingML/Machine Learning Modules/car_detection_keras_CNN.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashislaha/CarDetection-iOS/3f398824a691668c784354e6b19edf1c68dfaaf0/CarDetectionUsingML/Machine Learning Modules/car_detection_keras_CNN.mlmodel -------------------------------------------------------------------------------- /CarDetectionUsingML/Machine Learning Modules/car_detection_keras_DNN.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashislaha/CarDetection-iOS/3f398824a691668c784354e6b19edf1c68dfaaf0/CarDetectionUsingML/Machine Learning Modules/car_detection_keras_DNN.mlmodel -------------------------------------------------------------------------------- /CarDetectionUsingMLTests/CarDetectionUsingMLTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CarDetectionUsingMLTests.swift 3 | // CarDetectionUsingMLTests 4 | // 5 | // Created by Ashis Laha on 29/07/17. 6 | // Copyright © 2017 Ashis Laha. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import CarDetectionUsingML 11 | 12 | class CarDetectionUsingMLTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CarDetectionUsingMLTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CarDetectionUsingMLUITests/CarDetectionUsingMLUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CarDetectionUsingMLUITests.swift 3 | // CarDetectionUsingMLUITests 4 | // 5 | // Created by Ashis Laha on 29/07/17. 6 | // Copyright © 2017 Ashis Laha. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class CarDetectionUsingMLUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CarDetectionUsingMLUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CarDetection-iOS 2 | 3 | "Car Detection" is trained in Keras using Tensorflow as back-end. It's taking an image as input and it gives a binary 4 | decision whether a car is present in the image or not. Both Convolutional Neural Network(CNN) and Dense Neural Network(DNN) 5 | are used in the project. After train, converting the .h5 model into .mlmodel to use in Xcode. 6 | 7 | Please check https://github.com/ashislaha/CarDetection-Keras . 8 | --------------------------------------------------------------------------------