Skip to content

Commit

Permalink
Refactoring Image Classification project
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoroney committed Feb 28, 2021
1 parent 3b395eb commit 465d100
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 255 deletions.
Binary file not shown.
Binary file not shown.

This file was deleted.

109 changes: 0 additions & 109 deletions BookSource/Chapter06/Chapter6ImageLabelling/Podfile.lock

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Chapter6ImageLabelling.xcscheme_^#shared#^_</key>
<key>MLKitImageClassifier.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>18</integer>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// AppDelegate.swift
// Chapter6ImageLabelling
// MLKitImageClassifier
//
// Created by Laurence Moroney on 2/22/21.
// Created by Laurence Moroney on 2/28/21.
//

import UIKit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment version="4864" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand All @@ -12,25 +11,25 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Chapter6ImageLabelling" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="MLKitImageClassifier" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4xo-fI-227">
<rect key="frame" x="0.0" y="0.0" width="375" height="213"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="f0E-Zd-hZy">
<rect key="frame" x="20" y="53" width="374" height="264"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cZj-Yn-1t5">
<rect key="frame" x="143" y="221" width="88" height="30"/>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nyQ-1j-n5u">
<rect key="frame" x="163" y="365" width="88" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Do Inference"/>
<connections>
<action selector="btnPress:" destination="BYZ-38-t0r" eventType="touchUpInside" id="L95-TI-45A"/>
<action selector="doInference:" destination="BYZ-38-t0r" eventType="touchUpInside" id="UCe-5S-QfI"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0WH-hq-rpK">
<rect key="frame" x="16" y="259" width="343" height="250"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iMj-za-fZT">
<rect key="frame" x="29" y="438" width="365" height="281"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -41,13 +40,13 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<connections>
<outlet property="imageView" destination="4xo-fI-227" id="DWy-fz-Q3D"/>
<outlet property="lblOutput" destination="0WH-hq-rpK" id="pZv-AW-DFD"/>
<outlet property="imageView" destination="f0E-Zd-hZy" id="hTP-av-X0p"/>
<outlet property="lblOutput" destination="iMj-za-fZT" id="YhZ-8a-Mdn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="18.399999999999999" y="93.103448275862078"/>
<point key="canvasLocation" x="18.840579710144929" y="93.75"/>
</scene>
</scenes>
<resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// SceneDelegate.swift
// Chapter6ImageLabelling
// MLKitImageClassifier
//
// Created by Laurence Moroney on 2/22/21.
// Created by Laurence Moroney on 2/28/21.
//

import UIKit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
//
// ViewController.swift
// Chapter6ImageLabelling

// MLKitImageClassifier
//
// Created by Laurence Moroney on 2/28/21.
//

import UIKit
// Import the MLKit Vision and Image Labeling libraries
import MLKitVision
import MLKitImageLabeling

class ViewController: UIViewController {
// Outlet for image view, so we can read the image

@IBOutlet weak var imageView: UIImageView!
// Outlet for the output label so we can write to it
@IBOutlet weak var lblOutput: UILabel!

// An Action for the button so we can handle pressing it - it will call getLabels
@IBAction func btnPress(_ sender: Any) {
@IBAction func doInference(_ sender: Any) {
getLabels(with: imageView.image!)
}

// We'll have a var to hold all the labels
var labeltexts = ""

// On view did load we only need to initialize the image, so we can do that here
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
imageView.image = UIImage(named:"figure4-1.jpg")
imageView.image = UIImage(named:"fig6-1dog.jpg")
}

// This is called when the user presses the button
func getLabels(with image: UIImage){
// Get the image from the UI Image element and set its orientation
Expand All @@ -48,20 +44,22 @@ class ViewController: UIViewController {
self.processResult(from: labels, error: error)
}
}

// This gets called by the labeler's callback
func processResult(from labels: [ImageLabel]?, error: Error?){
// String to hold the labels
var labeltexts = ""
// Check that we have valid labels first
guard let labels = labels else{
return
}
// ...and if we do we can iterate through the set to get the description and confidence
for label in labels{
let labelText = label.text + " : " + label.confidence.description + "\n"
self.labeltexts += labelText
labeltexts += labelText
}
// And when we're done we can update the UI with the list of labels
self.lblOutput.text = self.labeltexts
lblOutput.text = labeltexts
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ platform :ios, '10.0'
use_frameworks!


target 'Chapter6ImageLabelling' do
target 'MLKitImageClassifier' do
pod 'GoogleMLKit/ImageLabeling'
end
end

0 comments on commit 465d100

Please sign in to comment.