MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / upscale

Method upscale

diffsynth/extensions/ESRGAN/__init__.py:109–137  ·  view source on GitHub ↗
(self, images, batch_size=4, progress_bar=lambda x:x)

Source from the content-addressed store, hash-verified

107
108 @torch.no_grad()
109 def upscale(self, images, batch_size=4, progress_bar=lambda x:x):
110 if not isinstance(images, list):
111 images = [images]
112 is_single_image = True
113 else:
114 is_single_image = False
115
116 # Preprocess
117 input_tensor = self.process_images(images)
118
119 # Interpolate
120 output_tensor = []
121 for batch_id in progress_bar(range(0, input_tensor.shape[0], batch_size)):
122 batch_id_ = min(batch_id + batch_size, input_tensor.shape[0])
123 batch_input_tensor = input_tensor[batch_id: batch_id_]
124 batch_input_tensor = batch_input_tensor.to(
125 device=self.model.conv_first.weight.device,
126 dtype=self.model.conv_first.weight.dtype)
127 batch_output_tensor = self.model(batch_input_tensor)
128 output_tensor.append(batch_output_tensor.cpu())
129
130 # Output
131 output_tensor = torch.concat(output_tensor, dim=0)
132
133 # To images
134 output_images = self.decode_images(output_tensor)
135 if is_single_image:
136 output_images = output_images[0]
137 return output_images

Callers

nothing calls this directly

Calls 4

process_imagesMethod · 0.95
decode_imagesMethod · 0.95
cpuMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected