This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from matplotlib import animation | |
| from scipy.ndimage import gaussian_filter | |
| from PIL import Image | |
| n_steps = 1000 | |
| bins = 100 | |
| num_dummy_images = 5000 | |
| n_animate = 50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FourierFeatures(nn.Module): | |
| """ Copied from https://github.com/NVIDIA/Cosmos/blob/c47b35b7618a6e263556f3e3fb7cfba3705c08a5/cosmos1/models/diffusion/module/blocks.py | |
| Related Research: https://arxiv.org/pdf/2006.10739 | |
| Implements a layer that generates Fourier features from input tensors, based on randomly sampled | |
| frequencies and phases. This can help in learning high-frequency functions in low-dimensional problems. | |
| [B] -> [B, D] | |
| Parameters: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| from torch import nn | |
| # 1. | |
| # register_forward_pre_hook(hook) | |
| # The hook will be called every time before forward() is invoked. It should have the following signature: | |
| # `hook(module, input) -> None` | |
| # The hook should not modify the input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def correct_orientation(image): | |
| try: | |
| for orientation in ExifTags.TAGS.keys(): | |
| if ExifTags.TAGS[orientation] == 'Orientation': | |
| break | |
| exif = dict(image._getexif().items()) | |
| if exif[orientation] == 3: | |
| image = image.rotate(180, expand=True) | |
| elif exif[orientation] == 6: | |
| image = image.rotate(270, expand=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To list installed distributions | |
| wsl -l | |
| wsl --list | |
| # To list installed distributions along with its running status and wsl config being 1 or 2 | |
| wsl -l --verbose | |
| wsl -l -v | |
| # To run a specific distro | |
| wsl -d distro_name |