yiiim / flutter_stable_diffusion

8 stars 3 forks source link

Never ending generate execution #1

Open aloisdeniel opened 1 month ago

aloisdeniel commented 1 month ago

Hello,

Thanks for doing this package, I love playing with Stable Diffusion, and bringing it into my apps is even funnier.

But I struggle to get results out of it...

I'm a complete beginner with these technologies, so it is probably a skill issue, but I did this and the future never completes...

Here is what I did :

const stableDiffusionModel =
    '/Users/alois/Downloads/coreml-stable-diffusion-2-1-base-palettized_original_compiled';

 const params = PlatformStableDiffusionPipelineCreationParams(
        modelPath: stableDiffusionModel,
 );
 _diffusion = FlutterStableDiffusionPipeline(params);
await _diffusion!.loadResources();

final generateParams = PlatformStableDiffusionPipelineGenerateParams(
      prompt: prompt,
      negativePrompt: 'ugly scary',
      stepCount: 20,
      guidanceScale: 7.5,
);

final result = await _diffusion!.generate(generateParams); // < Infinite 
 if (result.isSuccess && result.imageData != null) {
      return result.imageData!;
}
 throw Exception('Failed to generate image');

The generate method execution is infinite.

Am I missing something?

yiiim commented 1 month ago

Hello, I tried your code and it generated the image correctly. Is your model folder correct? It should be located in the original/compiled folder of the model repository, not the root directory of the repository. The folder should contain files like: [vocab.json, merges.txt, VAEEncoder.mlmodelc...]. Additionally, the generation speed depends on your computer's configuration. You can add the onProgress parameter to the generate method to monitor its progress.

final result = await _diffusion!.generate(
  generateParams,
  onProgress: (progress) {
    print("${progress.step}/${progress.stepCount}");
  },
);
aloisdeniel commented 1 month ago

Thanks for taking the time!

It seems to stop at step 8 :

image

I waited for about 20min and still blocked at this step.

I tried with 6 steps and it is locked at step 0:

image

The model directory contains these files :

image

I have a Macbook M1 Max, and it works well with DiffusionBee application with these parameters, as an example :

image

That said, I can't select the model directory in DiffusionBee :

image

I tried another model and I have the same issue.

yiiim commented 1 month ago

This is strange. Can you try using this model and then use the official Apple repository? The platform implementation of this package basically comes from there. Also, I noticed that your folder seems to be missing the files UnetChunk1.mlmodelc and UnetChunk2.mlmodelc. I'm not sure if this is the issue.