私は、CoreMLとVisionを使って簡単にコンピュータビジョンアプリケーションを作成しようと努力してきました。 64x64解像度のカラー画像を取得し、アルファベットの文字を教えてくれる自分のKerasネットワークを訓練しました。VN分類が機能していませんか?
//send a request to the network to identify the image
let request = VNCoreMLRequest(model: model) { (request, error) in
guard let results = request.results as? [VNClassificationObservation] else {
fatalError("Model failed to load image")
}
私は過去3時間と希望のために、このエラーに引っかかって頂いております:私は自分の携帯電話でこのアプリケーションを実行し、画像を撮影し、ヒットすると、コードのこの部分では、コードがクラッシュ「は、この画像を使用して」あなたたちは何が間違っているのか理解する手助けをすることができます!以下は、私が使用したコードの残りの部分です。
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.allowsEditing = false
}
//function to chose an image from your library or take one with your camera
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let userPickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = userPickedImage
//transform the image from UIImage to a CIIMage type
guard let ciImage = CIImage(image: userPickedImage) else {
fatalError("Couldn't transform image to CIImage type")
}
//call the detect function to pass the new ciImage into the network
detect(image: ciImage)
}
imagePicker.dismiss(animated: true, completion: nil)
}
//function to classify the image that is taken with the camera or chosen from the library
func detect(image: CIImage) {
//try to load the model, if not throw an error
guard let model = try? VNCoreMLModel(for: chars74k().model) else {
fatalError("Loading coreML model failed")
}
//send a request to the network to identify the image
let request = VNCoreMLRequest(model: model) { (request, error) in
guard let results = request.results as? [VNClassificationObservation] else {
fatalError("Model failed to load image")
}
print(results)
}
//create handler for image
let handler = VNImageRequestHandler(ciImage: image)
do{
try handler.perform([request])
}
catch {
print(error)
}
どのラインで正確にクラッシュしますか?あなたの 'fatalError'や' VMCoreMLRequest() 'や' try handler.perform() 'の呼び出しで? –
結果をVNClassificationObservationとして要求した後にfatalError行がクラッシュする –
InceptionV3モデルでテストした結果、このコードが正しく動作することがわかっていますが、自分のKeras CNNでコードをテストすると64x64カラーの画像を入力すると、そのfatalErrorでコードがクラッシュします。 –