Upload folder using huggingface_hub
Browse files- config.json +28 -0
- convert_to_hf.py +99 -0
- model.safetensors +3 -0
- preprocessor_config.json +25 -0
config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "crepe",
|
| 3 |
+
"architecture": "CREPE-full",
|
| 4 |
+
"base_model": "marl/crepe (Kim et al. 2018)",
|
| 5 |
+
"library": "torchcrepe",
|
| 6 |
+
"library_version": "0.0.24",
|
| 7 |
+
"input_sample_rate": 16000,
|
| 8 |
+
"input_window_size": 1024,
|
| 9 |
+
"num_output_bins": 360,
|
| 10 |
+
"bin_resolution_cents": 20,
|
| 11 |
+
"pitch_range_hz": {
|
| 12 |
+
"min": 32.7,
|
| 13 |
+
"max": 1975.5
|
| 14 |
+
},
|
| 15 |
+
"model_size": "full",
|
| 16 |
+
"num_parameters": 22244000,
|
| 17 |
+
"finetuned_from": "torchcrepe pretrained CREPE-full",
|
| 18 |
+
"finetuning_datasets": [
|
| 19 |
+
"MOSA",
|
| 20 |
+
"MusicNet (Option B Solo Violin)"
|
| 21 |
+
],
|
| 22 |
+
"target_domain": "violin (monophonic)",
|
| 23 |
+
"metrics": {
|
| 24 |
+
"Bach10_RPA": 0.982,
|
| 25 |
+
"MOSA_test_RPA": 0.862,
|
| 26 |
+
"MusicNet_test_RPA": 0.309
|
| 27 |
+
}
|
| 28 |
+
}
|
convert_to_hf.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import torch
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
# Load best.pt
|
| 6 |
+
print("Loading best.pt ...")
|
| 7 |
+
state = torch.load("best.pt", map_location="cpu", weights_only=False)
|
| 8 |
+
|
| 9 |
+
# Extract state_dict
|
| 10 |
+
if isinstance(state, dict):
|
| 11 |
+
if "model" in state:
|
| 12 |
+
state_dict = state["model"]
|
| 13 |
+
print(" found state_dict under 'model'")
|
| 14 |
+
elif "state_dict" in state:
|
| 15 |
+
state_dict = state["state_dict"]
|
| 16 |
+
print(" found state_dict under 'state_dict'")
|
| 17 |
+
else:
|
| 18 |
+
state_dict = state
|
| 19 |
+
print(" treating dict as state_dict")
|
| 20 |
+
else:
|
| 21 |
+
state_dict = state
|
| 22 |
+
print(f" {len(state_dict)} tensors")
|
| 23 |
+
|
| 24 |
+
# Save safetensors
|
| 25 |
+
try:
|
| 26 |
+
from safetensors.torch import save_file
|
| 27 |
+
except ImportError:
|
| 28 |
+
import subprocess
|
| 29 |
+
subprocess.check_call(["pip3", "install", "safetensors"])
|
| 30 |
+
from safetensors.torch import save_file
|
| 31 |
+
|
| 32 |
+
state_dict = {k: v.contiguous() for k, v in state_dict.items()}
|
| 33 |
+
save_file(state_dict, "model.safetensors")
|
| 34 |
+
print(f"OK saved model.safetensors")
|
| 35 |
+
|
| 36 |
+
# config.json
|
| 37 |
+
config = {
|
| 38 |
+
"model_type": "crepe",
|
| 39 |
+
"architecture": "CREPE-full",
|
| 40 |
+
"base_model": "marl/crepe (Kim et al. 2018)",
|
| 41 |
+
"library": "torchcrepe",
|
| 42 |
+
"library_version": "0.0.24",
|
| 43 |
+
"input_sample_rate": 16000,
|
| 44 |
+
"input_window_size": 1024,
|
| 45 |
+
"num_output_bins": 360,
|
| 46 |
+
"bin_resolution_cents": 20,
|
| 47 |
+
"pitch_range_hz": {"min": 32.7, "max": 1975.5},
|
| 48 |
+
"model_size": "full",
|
| 49 |
+
"num_parameters": 22244000,
|
| 50 |
+
"finetuned_from": "torchcrepe pretrained CREPE-full",
|
| 51 |
+
"finetuning_datasets": ["MOSA", "MusicNet (Option B Solo Violin)"],
|
| 52 |
+
"target_domain": "violin (monophonic)",
|
| 53 |
+
"metrics": {
|
| 54 |
+
"Bach10_RPA": 0.982,
|
| 55 |
+
"MOSA_test_RPA": 0.862,
|
| 56 |
+
"MusicNet_test_RPA": 0.309
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
with open("config.json", "w") as f:
|
| 60 |
+
json.dump(config, f, indent=2, ensure_ascii=False)
|
| 61 |
+
print("OK saved config.json")
|
| 62 |
+
|
| 63 |
+
# preprocessor_config.json
|
| 64 |
+
preprocessor = {
|
| 65 |
+
"feature_extractor_type": "CrepeFrameExtractor",
|
| 66 |
+
"sampling_rate": 16000,
|
| 67 |
+
"channels": 1,
|
| 68 |
+
"window_size_samples": 1024,
|
| 69 |
+
"hop_size_samples": 160,
|
| 70 |
+
"hop_size_ms": 10,
|
| 71 |
+
"window_size_ms": 64,
|
| 72 |
+
"normalization": "z_score",
|
| 73 |
+
"normalize_per_frame": True,
|
| 74 |
+
"epsilon": 1e-6,
|
| 75 |
+
"expected_format": "wav",
|
| 76 |
+
"expected_sample_rate": 16000,
|
| 77 |
+
"expected_channels": "mono",
|
| 78 |
+
"resample_if_needed": True,
|
| 79 |
+
"decoder": {
|
| 80 |
+
"method": "weighted_argmax",
|
| 81 |
+
"neighborhood_size": 9,
|
| 82 |
+
"smoothing": {
|
| 83 |
+
"periodicity_median_filter": 3,
|
| 84 |
+
"pitch_mean_filter": 3
|
| 85 |
+
},
|
| 86 |
+
"voicing_threshold": 0.21
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
with open("preprocessor_config.json", "w") as f:
|
| 90 |
+
json.dump(preprocessor, f, indent=2, ensure_ascii=False)
|
| 91 |
+
print("OK saved preprocessor_config.json")
|
| 92 |
+
|
| 93 |
+
print("\nDone! Files created:")
|
| 94 |
+
for f in ["model.safetensors", "config.json", "preprocessor_config.json"]:
|
| 95 |
+
size = Path(f).stat().st_size
|
| 96 |
+
if size > 1024 * 1024:
|
| 97 |
+
print(f" {f}: {size/1024/1024:.1f} MB")
|
| 98 |
+
else:
|
| 99 |
+
print(f" {f}: {size} bytes")
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f5ebae0cd5aeff1735bf248d78fecca99a31a8dc8c6b97c8c0d418a63e3a2534
|
| 3 |
+
size 88981056
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"feature_extractor_type": "CrepeFrameExtractor",
|
| 3 |
+
"sampling_rate": 16000,
|
| 4 |
+
"channels": 1,
|
| 5 |
+
"window_size_samples": 1024,
|
| 6 |
+
"hop_size_samples": 160,
|
| 7 |
+
"hop_size_ms": 10,
|
| 8 |
+
"window_size_ms": 64,
|
| 9 |
+
"normalization": "z_score",
|
| 10 |
+
"normalize_per_frame": true,
|
| 11 |
+
"epsilon": 1e-06,
|
| 12 |
+
"expected_format": "wav",
|
| 13 |
+
"expected_sample_rate": 16000,
|
| 14 |
+
"expected_channels": "mono",
|
| 15 |
+
"resample_if_needed": true,
|
| 16 |
+
"decoder": {
|
| 17 |
+
"method": "weighted_argmax",
|
| 18 |
+
"neighborhood_size": 9,
|
| 19 |
+
"smoothing": {
|
| 20 |
+
"periodicity_median_filter": 3,
|
| 21 |
+
"pitch_mean_filter": 3
|
| 22 |
+
},
|
| 23 |
+
"voicing_threshold": 0.21
|
| 24 |
+
}
|
| 25 |
+
}
|