Skip to content

Instantly share code, notes, and snippets.

View NormXU's full-sized avatar
🎯
Pixels Do Think Like Text.

Norm Inui NormXU

🎯
Pixels Do Think Like Text.
View GitHub Profile
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
@NormXU
NormXU / FourierFeatures.py
Created January 9, 2025 14:02
FourierFeatures
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:
@NormXU
NormXU / hook_pth.py
Created February 10, 2024 06:32 — forked from raytroop/hook_pth.py
try hook of pytorch
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
@NormXU
NormXU / correct_orientation.py
Created December 14, 2023 01:55
Correct the image orientation mismatch between viewing and loading with PIL
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)
@NormXU
NormXU / wsl-cheatsheet.ps1
Created November 16, 2023 17:20 — forked from karthiks/wsl-cheatsheet.ps1
WSL 2 CLI Cheat-sheet To Be Run In Powershell
# 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