report full size for fast latents and update conversion matrix for v1.5

This commit is contained in:
damian0815 2022-11-02 01:18:50 +01:00 committed by blessedcoolant
parent 688d7258f1
commit 0cc39f01a3
2 changed files with 12 additions and 10 deletions

View File

@ -640,9 +640,11 @@ class InvokeAIWebServer:
if generation_parameters['progress_latents']: if generation_parameters['progress_latents']:
image = self.generate.sample_to_lowres_estimated_image(sample) image = self.generate.sample_to_lowres_estimated_image(sample)
(width, height) = image.size (width, height) = image.size
width *= 8
height *= 8
buffered = io.BytesIO() buffered = io.BytesIO()
image.save(buffered, format="PNG") image.save(buffered, format="PNG")
img_base64 = "data:image/jpeg;base64," + base64.b64encode(buffered.getvalue()).decode('UTF-8') img_base64 = "data:image/png;base64," + base64.b64encode(buffered.getvalue()).decode('UTF-8')
self.socketio.emit( self.socketio.emit(
"intermediateResult", "intermediateResult",
{ {

View File

@ -119,19 +119,19 @@ class Generator():
# write an approximate RGB image from latent samples for a single step to PNG # write an approximate RGB image from latent samples for a single step to PNG
def sample_to_lowres_estimated_image(self,samples): def sample_to_lowres_estimated_image(self,samples):
# adapted from code by @erucipe and @keturn here: # origingally adapted from code by @erucipe and @keturn here:
# https://discuss.huggingface.co/t/decoding-latents-to-rgb-without-upscaling/23204/7 # https://discuss.huggingface.co/t/decoding-latents-to-rgb-without-upscaling/23204/7
# these numbers were determined empirically by @keturn # these updated numbers for v1.5 are from @torridgristle
v1_4_latent_rgb_factors = torch.tensor([ v1_5_latent_rgb_factors = torch.tensor([
# R G B # R G B
[ 0.298, 0.207, 0.208], # L1 [ 0.3444, 0.1385, 0.0670], # L1
[ 0.187, 0.286, 0.173], # L2 [ 0.1247, 0.4027, 0.1494], # L2
[-0.158, 0.189, 0.264], # L3 [-0.3192, 0.2513, 0.2103], # L3
[-0.184, -0.271, -0.473], # L4 [-0.1307, -0.1874, -0.7445] # L4
], dtype=samples.dtype, device=samples.device) ], dtype=samples.dtype, device=samples.device)
latent_image = samples[0].permute(1, 2, 0) @ v1_4_latent_rgb_factors latent_image = samples[0].permute(1, 2, 0) @ v1_5_latent_rgb_factors
latents_ubyte = (((latent_image + 1) / 2) latents_ubyte = (((latent_image + 1) / 2)
.clamp(0, 1) # change scale from -1..1 to 0..1 .clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255 .mul(0xFF) # to 0..255