Maps a string describing an interpolation function to the corresponding torchvision `InterpolationMode` enum. The full list of supported enums is documented at https://pytorch.org/vision/0.9/transforms.html#torchvision.transforms.functional.InterpolationMode. Args: interpol
(interpolation_type: str)
| 77 | |
| 78 | |
| 79 | def resolve_interpolation_mode(interpolation_type: str): |
| 80 | """ |
| 81 | Maps a string describing an interpolation function to the corresponding torchvision `InterpolationMode` enum. The |
| 82 | full list of supported enums is documented at |
| 83 | https://pytorch.org/vision/0.9/transforms.html#torchvision.transforms.functional.InterpolationMode. |
| 84 | |
| 85 | Args: |
| 86 | interpolation_type (`str`): |
| 87 | A string describing an interpolation method. Currently, `bilinear`, `bicubic`, `box`, `nearest`, |
| 88 | `nearest_exact`, `hamming`, and `lanczos` are supported, corresponding to the supported interpolation modes |
| 89 | in torchvision. |
| 90 | |
| 91 | Returns: |
| 92 | `torchvision.transforms.InterpolationMode`: an `InterpolationMode` enum used by torchvision's `resize` |
| 93 | transform. |
| 94 | """ |
| 95 | if not is_torchvision_available(): |
| 96 | raise ImportError( |
| 97 | "Please make sure to install `torchvision` to be able to use the `resolve_interpolation_mode()` function." |
| 98 | ) |
| 99 | |
| 100 | if interpolation_type == "bilinear": |
| 101 | interpolation_mode = transforms.InterpolationMode.BILINEAR |
| 102 | elif interpolation_type == "bicubic": |
| 103 | interpolation_mode = transforms.InterpolationMode.BICUBIC |
| 104 | elif interpolation_type == "box": |
| 105 | interpolation_mode = transforms.InterpolationMode.BOX |
| 106 | elif interpolation_type == "nearest": |
| 107 | interpolation_mode = transforms.InterpolationMode.NEAREST |
| 108 | elif interpolation_type == "nearest_exact": |
| 109 | interpolation_mode = transforms.InterpolationMode.NEAREST_EXACT |
| 110 | elif interpolation_type == "hamming": |
| 111 | interpolation_mode = transforms.InterpolationMode.HAMMING |
| 112 | elif interpolation_type == "lanczos": |
| 113 | interpolation_mode = transforms.InterpolationMode.LANCZOS |
| 114 | else: |
| 115 | raise ValueError( |
| 116 | f"The given interpolation mode {interpolation_type} is not supported. Currently supported interpolation" |
| 117 | f" modes are `bilinear`, `bicubic`, `box`, `nearest`, `nearest_exact`, `hamming`, and `lanczos`." |
| 118 | ) |
| 119 | |
| 120 | return interpolation_mode |
| 121 | |
| 122 | |
| 123 | def compute_dream_and_update_latents( |