9 Replies
      Latest reply on Sep 7, 2019 10:17 PM by AthenaY
      AthenaY Level 1 Level 1 (0 points)

        My trained model is working fine on Xcode (11 Beta) on my computer but when deployed to my iphone to try it out, it is not predicting anything. Anyone encountered this problem and has an idea why or has a solution? Thank-you!

        • Re: Model not predicting when deployed on phone
          kerfuffle Level 3 Level 3 (120 points)

          What do you mean by "not predicting anything"?

           

          Is it giving an error?

           

          Is it giving the wrong predictions?

           

          Is it not giving _any_ predictions at all?

            • Re: Model not predicting when deployed on phone
              AthenaY Level 1 Level 1 (0 points)

              It is not giving out the predicted Label like it does in Simulation. It just pops up the Catch error message that I put in. It's like it just skipped the "do" part of the function where I call the model. But why would it do so when deplyed on the phone but works fine when I launched it in Simulation?

                • Re: Model not predicting when deployed on phone
                  kerfuffle Level 3 Level 3 (120 points)

                  What is the error message?

                    • Re: Model not predicting when deployed on phone
                      AthenaY Level 1 Level 1 (0 points)

                      I really apreciate your time in trying to help me. I feel so stuck. The error message is the catch error message I setup within the function. It pops up on the screen like I intended it to do but it should be the predicted label instead. It's like the "do" section of the function that calls out the model is skipped and the "catch" error messages were displayed instead. Any idea why it works on the simulator but not on the device? Is it because the trained model somehow not deploying together with the rest of the app? But why? I don't know how to fix this.

                       

                      I have tried updating my iPhone software to the latest version. I have checked to make sure data captured on the phone is indeed captured for the prediction.

                       

                      Below is the function.

                       

                      The message below is displayed instead of "The Language is" followed by the predicted label like in the simulator.

                      "Error" "Sorry, seems like we are having some problems predicting"

                       

                       

                      @objc func PredictLanguage(){
                        let model = MyLanguageClassifier_1()

                        let title: String
                        let message: String

                        do {
                        let prediction = try model.prediction(text: Speech)

                        let ResultLanguage = prediction.label

                        message = ResultLanguage
                        title = "The Language is"

                        } catch {
                        title = "Error"
                        message = "Sorry, seems like we are having some problems predicting"
                        }

                        let ac = UIAlertController(title: title, message: message, preferredStyle: .alert)
                        ac.addAction(UIAlertAction(title: "OK", style: .default))
                        present(ac, animated: true)
                      }

                        • Re: Model not predicting when deployed on phone
                          kerfuffle Level 3 Level 3 (120 points)

                          Inside the catch, write print(error). Now it will print the reason why you're getting the error to the Xcode debug output pane.

                            • Re: Model not predicting when deployed on phone
                              AthenaY Level 1 Level 1 (0 points)

                              Thank-you! I will try that to debug.

                              • Re: Model not predicting when deployed on phone
                                AthenaY Level 1 Level 1 (0 points)

                                Hi Kerfuffle,

                                 

                                I'm just coming back to debugging this project.

                                 

                                Got the following error message when I added print(error) in Catch

                                Error Domain=com.apple.CoreML Code=0 "Prediction failed"

                                UserInfo={NSLocalizedDescription=Prediction failed}

                                 

                                I don't understand why my prediction part of the function works in the simulator but not work when deployed on my phone. I check to see if Speech is captured properly and it does. It's almost like CoreML model.prediction is not deployed along with the rest of the app. Have you seen anything like this? What's the possible fix?

                                 

                                 

                                @objc func PredictLanguage(){

                                  let model = MyLanguageClassifier_1()

                                 

                                  let title: String

                                  let message: String

                                 

                                  do {

                                  let prediction = try model.prediction(text: Speech)

                                 

                                  let ResultLanguage = prediction.label

                                 

                                  message = ResultLanguage

                                  title = "The Language is"

                                 

                                  } catch {

                                  title = "Error"

                                  message = "Sorry, seems like we are having some problems predicting"

                                  }

                                 

                                  let ac = UIAlertController(title: title, message: message, preferredStyle: .alert)

                                  ac.addAction(UIAlertAction(title: "OK", style: .default))

                                  present(ac, animated: true)

                                }