doreai / IOSFrameworks

IOSFrameworks
0 stars 0 forks source link

HairSegment and FaceSegment don't work on iPhone 15 Pro and iPhone 15 Pro Max #2

Open stepanov-standy opened 7 months ago

stepanov-standy commented 7 months ago

Due to some changes in Apple Neural Engine that is available in the chip A17 Pro on latest iPhone 15 Pro and iPhone 15 Pro Max, previously working segmentation has stopped working:

[Espresso::ANERuntimeEngine::__forward_segment 0] evaluate[RealTime]WithModel returned 0; code=8 err=Error Domain=com.apple.appleneuralengine Code=8 "processRequest:model:qos:qIndex:modelStringID:options:error:: ANEProgramProcessRequestDirect() Failed with status=0x1d : statusType=0x9: Program Inference error" UserInfo={NSLocalizedDescription=processRequest:model:qos:qIndex:modelStringID:options:error:: ANEProgramProcessRequestDirect() Failed with status=0x1d : statusType=0x9: Program Inference error}
[Espresso::handle_ex_plan] exception=Espresso exception: "Generic error": ANEF error: /private/var/mobile/Containers/Data/Application/8BEE4B89-CF4F-4E7D-A162-B5B834365B94/Documents/facesegment/model/model.espresso.net, processRequest:model:qos:qIndex:modelStringID:options:error:: ANEProgramProcessRequestDirect() Failed with status=0x1d : statusType=0x9: Program Inference error status=-1
Unable to compute the prediction using a neural network model. It can be an invalid input data or broken/unsupported model (error code: -1).
Error Domain=com.apple.Vision Code=3 "The VNCoreMLTransform request failed" UserInfo={NSLocalizedDescription=The VNCoreMLTransform request failed, NSUnderlyingError=0x3031f0e40 {Error Domain=com.apple.CoreML Code=0 "Unable to compute the prediction using a neural network model. It can be an invalid input data or broken/unsupported model (error code: -1)." UserInfo={NSLocalizedDescription=Unable to compute the prediction using a neural network model. It can be an invalid input data or broken/unsupported model (error code: -1).}}}

Looks like we need some kind of parameter that can specify on which compute units we want to run the model. So that the library can configure CoreML accordingly:

let config = MLModelConfiguration()
config.computeUnits = .all / .cpuAndGPU / .cpuOnly

let model = try MyModel(configuration: config)

This will help to avoid using ANE and most probably it is a good workaround for this and possible future weird issues with ANE not capable to correctly run working model.

doreai commented 7 months ago

Fixed in DoreFaceSegment new version 1.0.2