MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / main_kwargs

Function main_kwargs

diffusers/examples/research_projects/vae/vae_roundtrip.py:153–190  ·  view source on GitHub ↗
(
    *,
    device: torch.device,
    input_image_path: str,
    pretrained_model_name_or_path: str,
    revision: Optional[str],
    variant: Optional[str],
    subfolder: Optional[str],
    use_tiny_nn: bool,
)

Source from the content-addressed store, hash-verified

151
152
153def main_kwargs(
154 *,
155 device: torch.device,
156 input_image_path: str,
157 pretrained_model_name_or_path: str,
158 revision: Optional[str],
159 variant: Optional[str],
160 subfolder: Optional[str],
161 use_tiny_nn: bool,
162) -> None:
163 vae = load_vae_model(
164 device=device,
165 model_name_or_path=pretrained_model_name_or_path,
166 revision=revision,
167 variant=variant,
168 subfolder=subfolder,
169 use_tiny_nn=use_tiny_nn,
170 )
171 original_pil = Image.open(input_image_path).convert("RGB")
172 original_image = pil_to_nhwc(
173 device=device,
174 image=original_pil,
175 )
176 print(f"Original image shape: {original_image.shape}")
177 reconstructed_image: Optional[torch.Tensor] = None
178
179 with torch.no_grad():
180 latent_image = to_latent(rgb_nchw=original_image, vae=vae)
181 print(f"Latent shape: {latent_image.shape}")
182 reconstructed_image = from_latent(latent_nchw=latent_image, vae=vae)
183 reconstructed_pil = nhwc_to_pil(nhwc=reconstructed_image)
184 combined_image = concatenate_images(
185 left=original_pil,
186 right=reconstructed_pil,
187 vertical=False,
188 )
189 combined_image.show("Original | Reconstruction")
190 print(f"Reconstructed image shape: {reconstructed_image.shape}")
191
192
193def parse_args() -> argparse.Namespace:

Callers 1

main_cliFunction · 0.85

Calls 6

load_vae_modelFunction · 0.85
pil_to_nhwcFunction · 0.85
to_latentFunction · 0.85
from_latentFunction · 0.85
nhwc_to_pilFunction · 0.85
concatenate_imagesFunction · 0.85

Tested by

no test coverage detected