Skip to content

YamamotoDesu/ImageClassificationSwiftUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

ImageClassificationSwiftUI

スクリーンショット 2022-12-27 15 20 52

Core MLモデル
https://developer.apple.com/jp/machine-learning/models/

Download Model

機械学習_-_モデル_-_Apple_Developer

Place Model into Project

ImageClassificationSwiftUI_—_MobileNetV2_と_New_File

Classfy the image

ImageClassificationSwiftUI_—_MobileNetV2

スクリーンショット_2022_12_27_15_25

 @State private var classficationLabel: String = ""
    
    let model = MobileNetV2()
    
    private func performImageClassfication() {
        
        let currentImageName = photos[currentIndex]
        
        guard let img = UIImage(named: currentImageName),
              let resizedImage = img.resizeTo(size: CGSize(width: 224, height: 224)),
              let buffer = resizedImage.toBuffer() else {
            return
        }
        
        let output = try? model.prediction(image: buffer)
        
        if let output = output {
            
            self.classficationLabel = output.classLabel
        }
        
    }
  

How to classfy Images

  
let results = output.classLabelProbs.sorted { $0.value > $1.value }
            
let result = results.map { key, value in
  return "\(key) = \(value * 100)"
}.joined(separator: "\n")

スクリーンショット_2022_12_27_15_48

Releases

No releases published

Packages

No packages published

Languages