MCPcopy
hub / github.com/vladmandic/sdnext / vae_encode

Function vae_encode

modules/processing_vae.py:352–373  ·  view source on GitHub ↗
(image, model, vae_type='Full')

Source from the content-addressed store, hash-verified

350
351
352def vae_encode(image, model, vae_type='Full'): # pylint: disable=unused-variable
353 jobid = shared.state.begin('VAE Encode')
354 from modules.image import convert
355 if shared.state.interrupted or shared.state.skipped:
356 return []
357 if not hasattr(model, 'vae') and hasattr(model, 'pipe'):
358 model = model.pipe
359 if not hasattr(model, 'vae'):
360 log.error('VAE not found in model')
361 return []
362 tensor = convert.to_tensor(image.convert("RGB")).unsqueeze(0).to(devices.device, devices.dtype_vae)
363 if vae_type == 'Tiny':
364 latents = taesd_vae_encode(image=tensor)
365 elif vae_type == 'Full' and hasattr(model, 'vae'):
366 tensor = tensor * 2 - 1
367 latents = full_vae_encode(image=tensor, model=shared.sd_model)
368 else:
369 log.error('VAE not found in model')
370 latents = []
371 devices.torch_gc()
372 shared.state.end(jobid)
373 return latents
374
375
376def reprocess(gallery):

Callers 2

latentFunction · 0.90
create_latentsFunction · 0.70

Calls 6

taesd_vae_encodeFunction · 0.85
full_vae_encodeFunction · 0.85
beginMethod · 0.80
toMethod · 0.45
convertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected