unload model after inference
Browse files
app.py
CHANGED
@@ -57,6 +57,7 @@ def inference_gradio(input, model_choice): # input is audio waveform in [T, cha
|
|
57 |
|
58 |
@spaces.GPU(duration=120)
|
59 |
def inference_model(audio_input, h, model):
|
|
|
60 |
model.to(device)
|
61 |
|
62 |
def get_mel(x):
|
@@ -69,12 +70,17 @@ def inference_model(audio_input, h, model):
|
|
69 |
|
70 |
y_g_hat = model(spec_gt)
|
71 |
|
72 |
-
audio_gen = y_g_hat.squeeze()
|
73 |
spec_gen = get_mel(audio_gen.unsqueeze(0))
|
74 |
audio_gen = audio_gen * MAX_WAV_VALUE
|
75 |
-
audio_gen = audio_gen.
|
76 |
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
|
80 |
css = """
|
|
|
57 |
|
58 |
@spaces.GPU(duration=120)
|
59 |
def inference_model(audio_input, h, model):
|
60 |
+
# load model to device
|
61 |
model.to(device)
|
62 |
|
63 |
def get_mel(x):
|
|
|
70 |
|
71 |
y_g_hat = model(spec_gt)
|
72 |
|
73 |
+
audio_gen = y_g_hat.squeeze().cpu()
|
74 |
spec_gen = get_mel(audio_gen.unsqueeze(0))
|
75 |
audio_gen = audio_gen * MAX_WAV_VALUE
|
76 |
+
audio_gen = audio_gen.numpy().astype('int16')
|
77 |
|
78 |
+
# unload to cpu
|
79 |
+
model.to('cpu')
|
80 |
+
# delete gpu tensor
|
81 |
+
del spec_gt, y_g_hat
|
82 |
+
|
83 |
+
return audio_gen, spec_gen[0]
|
84 |
|
85 |
|
86 |
css = """
|