Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I change the image's size and aspect ratio? #343

Open
caol64 opened this issue Jul 30, 2024 · 4 comments
Open

How can I change the image's size and aspect ratio? #343

caol64 opened this issue Jul 30, 2024 · 4 comments

Comments

@caol64
Copy link

caol64 commented Jul 30, 2024

I'm using a Swift library, but I cannot find a way to change the image's size and aspect ratio. The following code is not functioning properly:

        pipelineConfig.originalSize = 768
        pipelineConfig.targetSize = 768
        let images = try pipeline!.generateImages(configuration: pipelineConfig,
                                                 progressHandler: { progress in
            onProgress(progress)
            return !canceled
        })

The generated image size is fixed at 1024x1024 (XL) and 512x512, and the code does not seem to support changing the aspect ratio. Can anyone give me some suggestions?

Thanks!

@swiftuiux
Copy link

Hi If you are dealing with NSImage take a look on the code Might help

https://gist.github.com/The-Igor/5b41fa5ee881112de770665fc103a4d9

@ZachNagengast
Copy link
Contributor

ZachNagengast commented Aug 3, 2024

the originalSize and targetSize parameters are actually just another condition for the model, similar to text embeddings, where you can influence the composition of the scene by telling the model that you want a specific size or cropping. Here's a link from HF discussing the size conditioning, and here is a screenshot from the paper on crop conditioning.
image
If you want to change the actual pixel size value of the output image, you'll need to export a model using the --latent-w and --latent-h cli parameters. Or resize the image directly per @The-Igor's comment.

@caol64
Copy link
Author

caol64 commented Aug 4, 2024

@The-Igor Thank you for your awesome example.
@ZachNagengast Thank you for your awesome response.

So far, it has not been possible to use the same model to generate images of different aspect ratios by varying parameters. To achieve this, one would have to use --latent-w and --latent-h to generate different models, and then use these models to generate images of various aspect ratios. Is my understanding correct?

@ZachNagengast
Copy link
Contributor

ZachNagengast commented Aug 6, 2024

Correct, and this is also theoretically achievable via two options alternative options:

  1. Use the new adapters for the input layer to combine multiple models with a couple common aspect ratios into the same model
  2. Use flexible/enumerated shapes for the input - but this will reduce performance quite a bit due to being limited to CPU

These will both need supporting code to achieve in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants