mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
report full size for fast latents and update conversion matrix for v1.5
This commit is contained in:
parent
00378e1ea6
commit
3f5bf7ac44
@ -637,6 +637,25 @@ class InvokeAIWebServer:
|
|||||||
"height": height,
|
"height": height,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if generation_parameters['progress_latents']:
|
||||||
|
image = self.generate.sample_to_lowres_estimated_image(sample)
|
||||||
|
(width, height) = image.size
|
||||||
|
width *= 8
|
||||||
|
height *= 8
|
||||||
|
buffered = io.BytesIO()
|
||||||
|
image.save(buffered, format="PNG")
|
||||||
|
img_base64 = "data:image/png;base64," + base64.b64encode(buffered.getvalue()).decode('UTF-8')
|
||||||
|
self.socketio.emit(
|
||||||
|
"intermediateResult",
|
||||||
|
{
|
||||||
|
"url": img_base64,
|
||||||
|
"isBase64": True,
|
||||||
|
"mtime": 0,
|
||||||
|
"metadata": {},
|
||||||
|
"width": width,
|
||||||
|
"height": height,
|
||||||
|
}
|
||||||
|
)
|
||||||
self.socketio.emit("progressUpdate", progress.to_formatted_dict())
|
self.socketio.emit("progressUpdate", progress.to_formatted_dict())
|
||||||
eventlet.sleep(0)
|
eventlet.sleep(0)
|
||||||
|
|
||||||
|
@ -116,6 +116,29 @@ class Generator():
|
|||||||
)
|
)
|
||||||
return Image.fromarray(x_sample.astype(np.uint8))
|
return Image.fromarray(x_sample.astype(np.uint8))
|
||||||
|
|
||||||
|
# write an approximate RGB image from latent samples for a single step to PNG
|
||||||
|
|
||||||
|
def sample_to_lowres_estimated_image(self,samples):
|
||||||
|
# origingally adapted from code by @erucipe and @keturn here:
|
||||||
|
# https://discuss.huggingface.co/t/decoding-latents-to-rgb-without-upscaling/23204/7
|
||||||
|
|
||||||
|
# these updated numbers for v1.5 are from @torridgristle
|
||||||
|
v1_5_latent_rgb_factors = torch.tensor([
|
||||||
|
# R G B
|
||||||
|
[ 0.3444, 0.1385, 0.0670], # L1
|
||||||
|
[ 0.1247, 0.4027, 0.1494], # L2
|
||||||
|
[-0.3192, 0.2513, 0.2103], # L3
|
||||||
|
[-0.1307, -0.1874, -0.7445] # L4
|
||||||
|
], dtype=samples.dtype, device=samples.device)
|
||||||
|
|
||||||
|
latent_image = samples[0].permute(1, 2, 0) @ v1_5_latent_rgb_factors
|
||||||
|
latents_ubyte = (((latent_image + 1) / 2)
|
||||||
|
.clamp(0, 1) # change scale from -1..1 to 0..1
|
||||||
|
.mul(0xFF) # to 0..255
|
||||||
|
.byte()).cpu()
|
||||||
|
|
||||||
|
return Image.fromarray(latents_ubyte.numpy())
|
||||||
|
|
||||||
def generate_initial_noise(self, seed, width, height):
|
def generate_initial_noise(self, seed, width, height):
|
||||||
initial_noise = None
|
initial_noise = None
|
||||||
if self.variation_amount > 0 or len(self.with_variations) > 0:
|
if self.variation_amount > 0 or len(self.with_variations) > 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user