Add lg and variant style spaces
Browse filesFiles changed (4)
- README.md+8
- sref.py+18-10
- sref_space_lg.npzAdded+3
- sref_space_variant.npzAdded+3
70 unmodified lines71727374757670 unmodified linesRun this on every denoising step. With classifier-free guidance, add the block on the conditional pass. No model weights change. It adds 108 tokens to the sequence.## Strength- `6` is a full restyle for most codes.70 unmodified lines717273747576777879808182838470 unmodified linesRun this on every denoising step. With classifier-free guidance, add the block on the conditional pass. No model weights change. It adds 108 tokens to the sequence.## VariantsThree style spaces ship side by side, `sref_space.npz`, `sref_space_lg.npz` and `sref_space_variant.npz`: they're roughly equal, but slightly different, and the same code gives a different style in each.```pythonblock = style_block(768519172, strength=6.0, space_name="lg") # or "variant"; "default" when omitted```## Strength- `6` is a full restyle for most codes.
8 unmodified lines91011121314151617181920212223242526272829308 unmodified linesimport numpy as np_space = np.load(Path(__file__).parent / "sref_space.npz")BASIS = _space["basis"].astype(np.float32) # [64, 108, 6144]SD = _space["sd"].astype(np.float32) # [64]TOKENS, WIDTH = BASIS.shape[1], BASIS.shape[2]def coords(code: int) -> np.ndarray:"""The 64 style coordinates for a code."""return np.random.default_rng(code).standard_normal(len(SD)).astype(np.float32) * SDdef style_block(code: int, strength: float = 6.0) -> np.ndarray:"""The token block for a code: [108, 6144]."""return strength * np.tensordot(coords(code), BASIS, axes=1)def block_from_coords(z: np.ndarray, strength: float = 6.0) -> np.ndarray:"""The token block for 64 coordinates you supply, for blending or editing styles."""return strength * np.tensordot(np.asarray(z, dtype=np.float32), BASIS, axes=1)8 unmodified lines910111213141516171819202122232425262728293031323334353637388 unmodified linesimport numpy as npSPACES = {"default": "sref_space.npz", "lg": "sref_space_lg.npz", "variant": "sref_space_variant.npz"}_loaded = {}def space(name: str = "default"):"""(basis [64, 108, 6144], sd [64]) of a style space. The same code is a different style in each space."""if name not in _loaded:f = np.load(Path(__file__).parent / SPACES[name], allow_pickle=False)_loaded[name] = (f["basis"].astype(np.float32), f["sd"].astype(np.float32))return _loaded[name]def coords(code: int, space_name: str = "default") -> np.ndarray:"""The 64 style coordinates for a code."""_, sd = space(space_name)return np.random.default_rng(code).standard_normal(len(sd)).astype(np.float32) * sddef style_block(code: int, strength: float = 6.0, space_name: str = "default") -> np.ndarray:"""The token block for a code: [108, 6144]."""return block_from_coords(coords(code, space_name), strength, space_name)def block_from_coords(z: np.ndarray, strength: float = 6.0, space_name: str = "default") -> np.ndarray:"""The token block for 64 coordinates you supply, for blending or editing styles."""basis, _ = space(space_name)return strength * np.tensordot(np.asarray(z, dtype=np.float32), basis, axes=1)
123version https://git-lfs.github.com/spec/v1oid sha256:5639bf3084e17a5efabab794ed2a9b30aadb41a4cc4412255bda8382abd1aafesize 84935412123version https://git-lfs.github.com/spec/v1oid sha256:f0a7159fcd0100a36638eb5acdb6ae4829d340580601017096c8b21c1d8d542fsize 84935412README.md+8
sref.py+18-10
sref_space_lg.npzAdded+3
sref_space_variant.npzAdded+3