(
tensor: "torch.Tensor",
processor: "VaeImageProcessor" | "VideoProcessor" | None = None,
do_scaling: bool = True,
scaling_factor: float | None = None,
shift_factor: float | None = None,
output_type: Literal["mp4", "pil", "pt"] = "pil",
image_format: Literal["png", "jpg"] = "jpg",
partial_postprocess: bool = False,
height: int | None = None,
width: int | None = None,
)
| 145 | |
| 146 | |
| 147 | def prepare_decode( |
| 148 | tensor: "torch.Tensor", |
| 149 | processor: "VaeImageProcessor" | "VideoProcessor" | None = None, |
| 150 | do_scaling: bool = True, |
| 151 | scaling_factor: float | None = None, |
| 152 | shift_factor: float | None = None, |
| 153 | output_type: Literal["mp4", "pil", "pt"] = "pil", |
| 154 | image_format: Literal["png", "jpg"] = "jpg", |
| 155 | partial_postprocess: bool = False, |
| 156 | height: int | None = None, |
| 157 | width: int | None = None, |
| 158 | ): |
| 159 | headers = {} |
| 160 | parameters = { |
| 161 | "image_format": image_format, |
| 162 | "output_type": output_type, |
| 163 | "partial_postprocess": partial_postprocess, |
| 164 | "shape": list(tensor.shape), |
| 165 | "dtype": str(tensor.dtype).split(".")[-1], |
| 166 | } |
| 167 | if do_scaling and scaling_factor is not None: |
| 168 | parameters["scaling_factor"] = scaling_factor |
| 169 | if do_scaling and shift_factor is not None: |
| 170 | parameters["shift_factor"] = shift_factor |
| 171 | if do_scaling and scaling_factor is None: |
| 172 | parameters["do_scaling"] = do_scaling |
| 173 | elif do_scaling and scaling_factor is None and shift_factor is None: |
| 174 | parameters["do_scaling"] = do_scaling |
| 175 | if height is not None and width is not None: |
| 176 | parameters["height"] = height |
| 177 | parameters["width"] = width |
| 178 | headers["Content-Type"] = "tensor/binary" |
| 179 | headers["Accept"] = "tensor/binary" |
| 180 | if output_type == "pil" and image_format == "jpg" and processor is None: |
| 181 | headers["Accept"] = "image/jpeg" |
| 182 | elif output_type == "pil" and image_format == "png" and processor is None: |
| 183 | headers["Accept"] = "image/png" |
| 184 | elif output_type == "mp4": |
| 185 | headers["Accept"] = "text/plain" |
| 186 | tensor_data = safetensors.torch._tobytes(tensor, "tensor") |
| 187 | return {"data": tensor_data, "params": parameters, "headers": headers} |
| 188 | |
| 189 | |
| 190 | def remote_decode( |
no test coverage detected
searching dependent graphs…