Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding run_cpu.py and run_gpu.py in code #74

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion audioldm2/audiomae_gen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, in_dim, sizes=[256, 128], dropout_rate=0.5):
self.relu = nn.ReLU()
self.dropout = nn.Dropout(dropout_rate)

def forward(self, inputs):
def forward(self, inputs): # 메서드에서는 입력을 각 선형 레이어를 통과시키고 ReLU 활성화 함수 및 드롭아웃을 적용
for linear in self.layers:
inputs = self.dropout(self.relu(linear(inputs)))
return inputs
Expand Down
29 changes: 15 additions & 14 deletions audioldm2/clap/open_clip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"fsd50k_200_class_label": ["train", "test", "valid"],
}


def freeze_batch_norm_2d(module, module_match={}, name=""):
"""
Converts all `BatchNorm2d` and `SyncBatchNorm` layers of provided module into `FrozenBatchNorm2d`. If `module` is
Expand Down Expand Up @@ -216,19 +215,6 @@ def pad_framewise_output(framewise_output, frames_num):
"""(batch_size, frames_num, classes_num)"""


# def process_ipc(index_path, classes_num, filename):
# # load data
# logging.info("Load Data...............")
# ipc = [[] for _ in range(classes_num)]
# with h5py.File(index_path, "r") as f:
# for i in tqdm(range(len(f["target"]))):
# t_class = np.where(f["target"][i])[0]
# for t in t_class:
# ipc[t].append(i)
# print(ipc)
# np.save(filename, ipc)
# logging.info("Load Data Succeed...............")

def save_to_dict(s, o_={}):
sp = s.split(": ")
o_.update({sp[0]: float(sp[1])})
Expand Down Expand Up @@ -352,3 +338,18 @@ def get_optimizer(params, lr, betas, eps, momentum, optimizer_name):
else:
raise ValueError("optimizer name is not correct")
return optimizer



# def process_ipc(index_path, classes_num, filename):
# # load data
# logging.info("Load Data...............")
# ipc = [[] for _ in range(classes_num)]
# with h5py.File(index_path, "r") as f:
# for i in tqdm(range(len(f["target"]))):
# t_class = np.where(f["target"][i])[0]
# for t in t_class:
# ipc[t].append(i)
# print(ipc)
# np.save(filename, ipc)
# logging.info("Load Data Succeed...............")
15 changes: 15 additions & 0 deletions audioldm2/run_cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from diffusers import AudioLDM2Pipeline
import torch
import scipy

repo_id = "cvssp/audioldm2"
pipe = AudioLDM2Pipeline.from_pretrained(repo_id, torch_dtype=torch.float)
pipe = pipe.to("cpu")

#text prompt
prompt = "Techno music with a strong, upbeat tempo and high melodic riffs."
audio = pipe(prompt, num_inference_steps=200, audio_length_in_s=15.0).audios[0]
# audio_length_in_s = 생성 음악 시간.

audiofile_name = "techno.wav"
scipy.io.wavfile.write(audiofile_name, rate=16000, data=audio)
15 changes: 15 additions & 0 deletions audioldm2/run_gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from diffusers import AudioLDM2Pipeline
import torch
import scipy

repo_id = "cvssp/audioldm2"
pipe = AudioLDM2Pipeline.from_pretrained(repo_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")

#text prompt
prompt = "Techno music with a strong, upbeat tempo and high melodic riffs."
audio = pipe(prompt, num_inference_steps=200, audio_length_in_s=10.0).audios[0]
# audio_length_in_s = 생성 음악 시간.

audiofile_name = "techno.wav"
scipy.io.wavfile.write(audiofile_name, rate=16000, data=audio)