apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.42k stars 640 forks source link

"Provided shape is not compatible with the model's feature description" for custom after ML conversion in Swift API #1717

Closed NekoNeko66 closed 1 year ago

NekoNeko66 commented 1 year ago

Hello,

I tried to use the following command to convert a stable diffusion model rinna/japanese-stable-diffusion to Apple Core ML package:

python -m python_coreml_stable_diffusion.torch2coreml --convert-unet --convert-text-encoder --convert-vae-decoder --convert-safety-checker -o /Users/<username>/Downloads/japanese-stable-diffusion-converted --model-version rinna/japanese-stable-diffusion --bundle-resources-for-swift-cli

The command successfully generates a folder of ml packages and a resources file.

I then proceed to use the Swift API for the processing resources(tried .all and CPU and NE) on MacOS. But the image generation failed with the following error:

TestingApp[3087:59450] [espresso] [Espresso::handle_ex_plan] exception=ANECF error: failed to load ANE model. Error=createProgramInstanceForModel:modelToken:qos:isPreCompiled:enablePowerSaving:statsMask:memoryPoolID:enableLateLatch:modelIdentityStr:error:: Program load failure (0x20004)

TestingApp[3087:59450] [coreml] Error plan build: -1.

TestingApp[3087:59450] [client] doUnloadModel:options:qos:error:: nil _ANEModel

TestingApp[3087:59450] [espresso] ANECF error:

TestingApp[3087:59158] [coreml] Error Domain=com.apple.CoreML Code=1 "For input feature 'images', the provided shape 1 × 512 × 512 × 3 is not compatible with the model's feature description." UserInfo={NSLocalizedDescription=For input feature 'images', the provided shape 1 × 512 × 512 × 3 is not compatible with the model's feature description., NSUnderlyingError=0x600002c20f60 {Error Domain=com.apple.CoreML Code=0 "MultiArray shape (1 x 512 x 512 x 3) does not match the shape (1 x 256 x 256 x 3) specified in the model description" UserInfo={NSLocalizedDescription=MultiArray shape (1 x 512 x 512 x 3) does not match the shape (1 x 256 x 256 x 3) specified in the model description}}}

I added debug logs in Python to print the size parameters (pipe unet), but found it to be the same as the Apple/StableDiffusion1-4

Replies are greatly appreciated!

Best,

NekoNeko66 commented 1 year ago

Sorry. This is posted in the wrong repository. It should be in the https://github.com/apple/ml-stable-diffusion