Views
No views yet
| Sample | Description | Audio |
|---|---|---|
| Meow 1 | Short meow | |
| Meow 2 | Medium meow | |
| Meow 3 | Long meow | |
| Meow 4 | High pitch | |
| Meow 5 | Low pitch |
| Variation 1 | Variation 2 | Variation 3 |
|---|---|---|
Audio → Mel Spectrogram → Encoder → Latent Space (z) → Decoder → Mel Spectrogram → Audio
↓
Sample random z to generate new meowspip install torch torchaudio librosa soundfile numpy1import torch
2import torch.nn as nn
3import librosa
4import soundfile as sf
5import numpy as np
6
7# Download the checkpoint
8from huggingface_hub import hf_hub_download
9
10checkpoint_path = hf_hub_download(
11 repo_id="liladhii/meowVAE03-335K",
12 filename="meowVAE03-335K.pth"
13)
14
15# Load the model (see full code below)
16device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
17checkpoint = torch.load(checkpoint_path, map_location=device)
18
19# Generate a meow!
20z = torch.randn(1, 128).to(device) * 0.8
21mel = model.decode(z)
22# ... convert to audio1import torch
2import torch.nn as nn
3import librosa
4import soundfile as sf
5import numpy as np
6from huggingface_hub import hf_hub_download
7
8# ============================================
9# MODEL DEFINITION
10# ============================================
11class MeowVAE(nn.Module):
12 def __init__(self, h, w, latent_dim):
13 super().__init__()
14 self.h, self.w = h, w
15 self.latent_dim = latent_dim
16
17 # Encoder
18 self.enc = nn.Sequential(
19 nn.Conv2d(1, 32, 4, 2, 1), nn.BatchNorm2d(32), nn.LeakyReLU(0.2),
20 nn.Conv2d(32, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.LeakyReLU(0.2),
21 nn.Conv2d(64, 128, 4, 2, 1), nn.BatchNorm2d(128), nn.LeakyReLU(0.2),
22 nn.Conv2d(128, 256, 4, 2, 1), nn.BatchNorm2d(256), nn.LeakyReLU(0.2),
23 nn.Flatten()
24 )
25
26 with torch.no_grad():
27 dummy = torch.zeros(1, 1, h, w)
28 flat_size = self.enc(dummy).shape[1]
29
30 self.fc_mu = nn.Linear(flat_size, latent_dim)
31 self.fc_var = nn.Linear(flat_size, latent_dim)
32 self.fc_dec = nn.Linear(latent_dim, flat_size)
33
34 self.dec_h = h // 16
35 self.dec_w = w // 16
36 self.flat_size = flat_size
37
38 # Decoder
39 self.dec = nn.Sequential(
40 nn.ConvTranspose2d(256, 128, 4, 2, 1), nn.BatchNorm2d(128), nn.ReLU(),
41 nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU(),
42 nn.ConvTranspose2d(64, 32, 4, 2, 1), nn.BatchNorm2d(32), nn.ReLU(),
43 nn.ConvTranspose2d(32, 1, 4, 2, 1), nn.Sigmoid()
44 )
45
46 def encode(self, x):
47 h = self.enc(x)
48 return self.fc_mu(h), self.fc_var(h)
49
50 def reparameterize(self, mu, logvar):
51 std = torch.exp(0.5 * logvar)
52 return mu + torch.randn_like(std) * std
53
54 def decode(self, z):
55 h = self.fc_dec(z).view(-1, 256, self.dec_h, self.dec_w)
56 out = self.dec(h)
57 return nn.functional.interpolate(out, (self.h, self.w), mode='bilinear', align_corners=False)
58
59 def forward(self, x):
60 mu, logvar = self.encode(x)
61 z = self.reparameterize(mu, logvar)
62 return self.decode(z), mu, logvar
63
64
65# ============================================
66# LOAD MODEL
67# ============================================
68def load_model(repo_id="liladhii/meowVAE03-335K", filename="meowVAE03-335K.pth"):
69 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
70
71 # Download checkpoint
72 checkpoint_path = hf_hub_download(repo_id=repo_id, filename=filename)
73 checkpoint = torch.load(checkpoint_path, map_location=device)
74
75 # Get config
76 config = checkpoint.get('config', {
77 'latent_dim': 128, 'n_mels': 64, 'n_fft': 1024,
78 'hop_length': 256, 'sample_rate': 22050, 'h': 64, 'w': 87
79 })
80
81 # Create and load model
82 model = MeowVAE(config['h'], config['w'], config['latent_dim']).to(device)
83 model.load_state_dict(checkpoint['model_state_dict'])
84 model.eval()
85
86 return model, config, checkpoint.get('mel_min', -80), checkpoint.get('mel_max', 0), device
87
88
89# ============================================
90# GENERATE MEOWS
91# ============================================
92def mel_to_audio(mel_db, config):
93 """Convert mel spectrogram to audio"""
94 mel = librosa.db_to_power(mel_db)
95 audio = librosa.feature.inverse.mel_to_audio(
96 mel, sr=config['sample_rate'],
97 n_fft=config['n_fft'],
98 hop_length=config['hop_length']
99 )
100 return librosa.util.normalize(audio)
101
102
103def generate_meow(model, config, mel_min, mel_max, device, temperature=0.8):
104 """Generate a single meow"""
105 with torch.no_grad():
106 z = torch.randn(1, config['latent_dim']).to(device) * temperature
107 mel_norm = model.decode(z).squeeze().cpu().numpy()
108 mel_db = mel_norm * (mel_max - mel_min) + mel_min
109 audio = mel_to_audio(mel_db, config)
110 return audio
111
112
113def generate_interpolation(model, config, mel_min, mel_max, device, steps=7, temperature=0.8):
114 """Generate interpolation between two random points"""
115 audios = []
116 with torch.no_grad():
117 z1 = torch.randn(1, config['latent_dim']).to(device) * temperature
118 z2 = torch.randn(1, config['latent_dim']).to(device) * temperature
119
120 for alpha in np.linspace(0, 1, steps):
121 z = z1 * (1 - alpha) + z2 * alpha
122 mel_norm = model.decode(z).squeeze().cpu().numpy()
123 mel_db = mel_norm * (mel_max - mel_min) + mel_min
124 audios.append(mel_to_audio(mel_db, config))
125
126 return np.concatenate(audios)
127
128
129# ============================================
130# EXAMPLE USAGE
131# ============================================
132if __name__ == "__main__":
133 # Load model
134 model, config, mel_min, mel_max, device = load_model()
135
136 # Generate random meows
137 for i in range(5):
138 audio = generate_meow(model, config, mel_min, mel_max, device, temperature=0.8)
139 sf.write(f'meow_{i+1}.wav', audio, config['sample_rate'])
140 print(f"Generated meow_{i+1}.wav")
141
142 # Generate interpolation
143 interp = generate_interpolation(model, config, mel_min, mel_max, device)
144 sf.write('meow_interpolation.wav', interp, config['sample_rate'])
145 print("Generated meow_interpolation.wav")| Temperature | Effect | Use Case |
|---|---|---|
| 0.3 - 0.5 | Conservative, similar meows | Consistent output |
| 0.6 - 0.8 | Balanced variety | Recommended |
| 0.9 - 1.2 | More variety | Creative exploration |
| 1.3+ | Wild, experimental | Sound design |
1# Conservative - similar to training data
2audio_low = generate_meow(model, config, mel_min, mel_max, device, temperature=0.4)
3
4# Balanced - recommended
5audio_mid = generate_meow(model, config, mel_min, mel_max, device, temperature=0.8)
6
7# Creative - more variety
8audio_high = generate_meow(model, config, mel_min, mel_max, device, temperature=1.2)| Component | Details |
|---|---|
| Type | Variational Autoencoder (VAE) |
| Encoder | 4-layer CNN with BatchNorm + LeakyReLU |
| Decoder | 4-layer Transposed CNN with BatchNorm + ReLU |
| Latent Dimension | 128 |
| Parameters | ~2.5M |
| Parameter | Value |
|---|---|
| Sample Rate | 22,050 Hz |
| Segment Length | 1.0 second |
| N_FFT | 1024 |
| Hop Length | 256 |
| N_Mels | 64 |
| Mel Spectrogram Shape | 64 × 87 |
| Parameter | Value |
|---|---|
| Dataset | liladhii/cat-meow-sounds |
| Optimizer | Adam |
| Learning Rate | 0.0005 |
| Scheduler | CosineAnnealingWarmRestarts |
| Batch Size | 32 |
| Loss | MSE Reconstruction + β-KL Divergence |
| β (KL weight) | 0.0001 |
| Checkpoint | Epoch | Loss | File Size |
|---|---|---|---|
meowVAE03-335K.pth | 300 | TBD | ~38 MB |
1def generate_variations(model, config, mel_min, mel_max, device,
2 num_variations=5, variation_strength=0.3):
3 """Generate variations around a base latent point"""
4 base_z = torch.randn(1, config['latent_dim']).to(device) * 0.8
5
6 audios = []
7 with torch.no_grad():
8 for i in range(num_variations):
9 z = base_z + torch.randn_like(base_z) * variation_strength
10 mel_norm = model.decode(z).squeeze().cpu().numpy()
11 mel_db = mel_norm * (mel_max - mel_min) + mel_min
12 audios.append(mel_to_audio(mel_db, config))
13
14 return audios1def generate_long_sequence(model, config, mel_min, mel_max, device,
2 duration_seconds=30, temperature=0.8):
3 """Generate extended meow sequence with smooth transitions"""
4 segment_duration = 1.0
5 num_segments = int(duration_seconds / segment_duration) + 1
6
7 # Create keypoints in latent space
8 num_keypoints = num_segments // 3 + 2
9 keypoints = [torch.randn(1, config['latent_dim']).to(device) * temperature
10 for _ in range(num_keypoints)]
11
12 audios = []
13 with torch.no_grad():
14 for i in range(num_segments):
15 # Interpolate between keypoints
16 t = i / (num_segments - 1) * (len(keypoints) - 1)
17 idx = int(t)
18 alpha = t - idx
19 idx2 = min(idx + 1, len(keypoints) - 1)
20
21 z = keypoints[idx] * (1 - alpha) + keypoints[idx2] * alpha
22 mel_norm = model.decode(z).squeeze().cpu().numpy()
23 mel_db = mel_norm * (mel_max - mel_min) + mel_min
24 audios.append(mel_to_audio(mel_db, config))
25
26 # Concatenate with crossfade
27 return np.concatenate(audios)[:int(duration_seconds * config['sample_rate'])]1def explore_latent_dimension(model, config, mel_min, mel_max, device,
2 dimension=0, num_steps=10):
3 """Explore a single latent dimension"""
4 base_z = torch.zeros(1, config['latent_dim']).to(device)
5
6 audios = []
7 with torch.no_grad():
8 for val in np.linspace(-2, 2, num_steps):
9 z = base_z.clone()
10 z[0, dimension] = val
11 mel_norm = model.decode(z).squeeze().cpu().numpy()
12 mel_db = mel_norm * (mel_max - mel_min) + mel_min
13 audios.append(mel_to_audio(mel_db, config))
14
15 return audios1@misc{cat-meow-generator-2026,
2 author = {liladhiee},
3 title = {Cat Meow AI Generator},
4 year = {2026},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/liladhii/meowVAE03-335K}
7}