Fix typos

Found via `codespell -L therefrom,siz` and `typos --format brief`.
This commit is contained in:
Kian-Meng Ang 2022-12-12 12:54:04 +08:00
parent c12d960d1e
commit 5576aee1b0
11 changed files with 25 additions and 25 deletions

View file

@ -233,7 +233,7 @@ class PLMSSampler(object):
# 2nd order Pseudo Linear Multistep (Adams-Bashforth) # 2nd order Pseudo Linear Multistep (Adams-Bashforth)
e_t_prime = (3 * e_t - old_eps[-1]) / 2 e_t_prime = (3 * e_t - old_eps[-1]) / 2
elif len(old_eps) == 2: elif len(old_eps) == 2:
# 3nd order Pseudo Linear Multistep (Adams-Bashforth) # 3rd order Pseudo Linear Multistep (Adams-Bashforth)
e_t_prime = (23 * e_t - 16 * old_eps[-1] + 5 * old_eps[-2]) / 12 e_t_prime = (23 * e_t - 16 * old_eps[-1] + 5 * old_eps[-2]) / 12
elif len(old_eps) >= 3: elif len(old_eps) >= 3:
# 4nd order Pseudo Linear Multistep (Adams-Bashforth) # 4nd order Pseudo Linear Multistep (Adams-Bashforth)

View file

@ -12,9 +12,9 @@ from ldm.modules.diffusionmodules.util import checkpoint
try: try:
import xformers import xformers
import xformers.ops import xformers.ops
XFORMERS_IS_AVAILBLE = True XFORMERS_IS_AVAILABLE = True
except: except:
XFORMERS_IS_AVAILBLE = False XFORMERS_IS_AVAILABLE = False
# CrossAttn precision handling # CrossAttn precision handling
import os import os
@ -251,7 +251,7 @@ class BasicTransformerBlock(nn.Module):
def __init__(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True, def __init__(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True,
disable_self_attn=False): disable_self_attn=False):
super().__init__() super().__init__()
attn_mode = "softmax-xformers" if XFORMERS_IS_AVAILBLE else "softmax" attn_mode = "softmax-xformers" if XFORMERS_IS_AVAILABLE else "softmax"
assert attn_mode in self.ATTENTION_MODES assert attn_mode in self.ATTENTION_MODES
attn_cls = self.ATTENTION_MODES[attn_mode] attn_cls = self.ATTENTION_MODES[attn_mode]
self.disable_self_attn = disable_self_attn self.disable_self_attn = disable_self_attn

View file

@ -11,9 +11,9 @@ from ldm.modules.attention import MemoryEfficientCrossAttention
try: try:
import xformers import xformers
import xformers.ops import xformers.ops
XFORMERS_IS_AVAILBLE = True XFORMERS_IS_AVAILABLE = True
except: except:
XFORMERS_IS_AVAILBLE = False XFORMERS_IS_AVAILABLE = False
print("No module 'xformers'. Proceeding without it.") print("No module 'xformers'. Proceeding without it.")
@ -279,7 +279,7 @@ class MemoryEfficientCrossAttentionWrapper(MemoryEfficientCrossAttention):
def make_attn(in_channels, attn_type="vanilla", attn_kwargs=None): def make_attn(in_channels, attn_type="vanilla", attn_kwargs=None):
assert attn_type in ["vanilla", "vanilla-xformers", "memory-efficient-cross-attn", "linear", "none"], f'attn_type {attn_type} unknown' assert attn_type in ["vanilla", "vanilla-xformers", "memory-efficient-cross-attn", "linear", "none"], f'attn_type {attn_type} unknown'
if XFORMERS_IS_AVAILBLE and attn_type == "vanilla": if XFORMERS_IS_AVAILABLE and attn_type == "vanilla":
attn_type = "vanilla-xformers" attn_type = "vanilla-xformers"
print(f"making attention of type '{attn_type}' with {in_channels} in_channels") print(f"making attention of type '{attn_type}' with {in_channels} in_channels")
if attn_type == "vanilla": if attn_type == "vanilla":

View file

@ -345,7 +345,7 @@ def count_flops_attn(model, _x, y):
class QKVAttentionLegacy(nn.Module): class QKVAttentionLegacy(nn.Module):
""" """
A module which performs QKV attention. Matches legacy QKVAttention + input/ouput heads shaping A module which performs QKV attention. Matches legacy QKVAttention + input/output heads shaping
""" """
def __init__(self, n_heads): def __init__(self, n_heads):

View file

@ -3,14 +3,14 @@ from torch import nn
class LitEma(nn.Module): class LitEma(nn.Module):
def __init__(self, model, decay=0.9999, use_num_upates=True): def __init__(self, model, decay=0.9999, use_num_updates=True):
super().__init__() super().__init__()
if decay < 0.0 or decay > 1.0: if decay < 0.0 or decay > 1.0:
raise ValueError('Decay must be between 0 and 1') raise ValueError('Decay must be between 0 and 1')
self.m_name2s_name = {} self.m_name2s_name = {}
self.register_buffer('decay', torch.tensor(decay, dtype=torch.float32)) self.register_buffer('decay', torch.tensor(decay, dtype=torch.float32))
self.register_buffer('num_updates', torch.tensor(0, dtype=torch.int) if use_num_upates self.register_buffer('num_updates', torch.tensor(0, dtype=torch.int) if use_num_updates
else torch.tensor(-1, dtype=torch.int)) else torch.tensor(-1, dtype=torch.int))
for name, p in model.named_parameters(): for name, p in model.named_parameters():

View file

@ -170,7 +170,7 @@ def gen_kernel(k_size=np.array([15, 15]), scale_factor=np.array([4, 4]), min_var
[X, Y] = np.meshgrid(range(k_size[0]), range(k_size[1])) [X, Y] = np.meshgrid(range(k_size[0]), range(k_size[1]))
Z = np.stack([X, Y], 2)[:, :, :, None] Z = np.stack([X, Y], 2)[:, :, :, None]
# Calcualte Gaussian for every pixel of the kernel # Calculate Gaussian for every pixel of the kernel
ZZ = Z - MU ZZ = Z - MU
ZZ_t = ZZ.transpose(0, 1, 3, 2) ZZ_t = ZZ.transpose(0, 1, 3, 2)
raw_kernel = np.exp(-0.5 * np.squeeze(ZZ_t @ INV_SIGMA @ ZZ)) * (1 + noise) raw_kernel = np.exp(-0.5 * np.squeeze(ZZ_t @ INV_SIGMA @ ZZ)) * (1 + noise)

View file

@ -169,7 +169,7 @@ def gen_kernel(k_size=np.array([15, 15]), scale_factor=np.array([4, 4]), min_var
[X, Y] = np.meshgrid(range(k_size[0]), range(k_size[1])) [X, Y] = np.meshgrid(range(k_size[0]), range(k_size[1]))
Z = np.stack([X, Y], 2)[:, :, :, None] Z = np.stack([X, Y], 2)[:, :, :, None]
# Calcualte Gaussian for every pixel of the kernel # Calculate Gaussian for every pixel of the kernel
ZZ = Z - MU ZZ = Z - MU
ZZ_t = ZZ.transpose(0, 1, 3, 2) ZZ_t = ZZ.transpose(0, 1, 3, 2)
raw_kernel = np.exp(-0.5 * np.squeeze(ZZ_t @ INV_SIGMA @ ZZ)) * (1 + noise) raw_kernel = np.exp(-0.5 * np.squeeze(ZZ_t @ INV_SIGMA @ ZZ)) * (1 + noise)

View file

@ -59,7 +59,7 @@ def surf(Z, cmap='rainbow', figsize=None):
''' '''
# -------------------------------------------- # --------------------------------------------
# get image pathes # get image paths
# -------------------------------------------- # --------------------------------------------
''' '''
@ -122,14 +122,14 @@ def imssave(imgs, img_path):
cv2.imwrite(new_path, img) cv2.imwrite(new_path, img)
def split_imageset(original_dataroot, taget_dataroot, n_channels=3, p_size=800, p_overlap=96, p_max=1000): def split_imageset(original_dataroot, target_dataroot, n_channels=3, p_size=800, p_overlap=96, p_max=1000):
""" """
split the large images from original_dataroot into small overlapped images with size (p_size)x(p_size), split the large images from original_dataroot into small overlapped images with size (p_size)x(p_size),
and save them into taget_dataroot; only the images with larger size than (p_max)x(p_max) and save them into target_dataroot; only the images with larger size than (p_max)x(p_max)
will be splitted. will be split.
Args: Args:
original_dataroot: original_dataroot:
taget_dataroot: target_dataroot:
p_size: size of small images p_size: size of small images
p_overlap: patch size in training is a good choice p_overlap: patch size in training is a good choice
p_max: images with smaller size than (p_max)x(p_max) keep unchanged. p_max: images with smaller size than (p_max)x(p_max) keep unchanged.
@ -139,8 +139,8 @@ def split_imageset(original_dataroot, taget_dataroot, n_channels=3, p_size=800,
# img_name, ext = os.path.splitext(os.path.basename(img_path)) # img_name, ext = os.path.splitext(os.path.basename(img_path))
img = imread_uint(img_path, n_channels=n_channels) img = imread_uint(img_path, n_channels=n_channels)
patches = patches_from_image(img, p_size, p_overlap, p_max) patches = patches_from_image(img, p_size, p_overlap, p_max)
imssave(patches, os.path.join(taget_dataroot,os.path.basename(img_path))) imssave(patches, os.path.join(target_dataroot,os.path.basename(img_path)))
#if original_dataroot == taget_dataroot: #if original_dataroot == target_dataroot:
#del img_path #del img_path
''' '''
@ -180,7 +180,7 @@ def mkdir_and_rename(path):
# -------------------------------------------- # --------------------------------------------
# get uint8 image of size HxWxn_channles (RGB) # get uint8 image of size HxWxn_channels (RGB)
# -------------------------------------------- # --------------------------------------------
def imread_uint(path, n_channels=3): def imread_uint(path, n_channels=3):
# input: path # input: path
@ -215,7 +215,7 @@ def imwrite(img, img_path):
# -------------------------------------------- # --------------------------------------------
# get single image of size HxWxn_channles (BGR) # get single image of size HxWxn_channels (BGR)
# -------------------------------------------- # --------------------------------------------
def read_img(path): def read_img(path):
# read image by cv2 # read image by cv2

View file

@ -125,7 +125,7 @@ class Resize(object):
# fit height # fit height
scale_width = scale_height scale_width = scale_height
elif self.__resize_method == "minimal": elif self.__resize_method == "minimal":
# scale as least as possbile # scale as least as possible
if abs(1 - scale_width) < abs(1 - scale_height): if abs(1 - scale_width) < abs(1 - scale_height):
# fit width # fit width
scale_height = scale_width scale_height = scale_width

View file

@ -23,7 +23,7 @@ def log_txt_as_img(wh, xc, size=10):
try: try:
draw.text((0, 0), lines, fill="black", font=font) draw.text((0, 0), lines, fill="black", font=font)
except UnicodeEncodeError: except UnicodeEncodeError:
print("Cant encode string for logging. Skipping.") print("Can't encode string for logging. Skipping.")
txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0 txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
txts.append(txt) txts.append(txt)