From d9eb82a6324bdc3ab7bfd9d38ced92ae7e9693c5 Mon Sep 17 00:00:00 2001 From: zxcd <228587199@qq.com> Date: Thu, 29 Aug 2024 19:35:26 +0800 Subject: [PATCH] fix unit test (#3835) --- tests/unit/asr/deepspeech2_model_test.py | 10 ++++---- .../unit/asr/deepspeech2_online_model_test.py | 24 +++++++++---------- .../unit/server/offline/test_server_client.sh | 2 ++ tests/unit/tts/test_data_table.py | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/unit/asr/deepspeech2_model_test.py b/tests/unit/asr/deepspeech2_model_test.py index 5835445d..fd42192e 100644 --- a/tests/unit/asr/deepspeech2_model_test.py +++ b/tests/unit/asr/deepspeech2_model_test.py @@ -48,7 +48,7 @@ class TestDeepSpeech2Model(unittest.TestCase): num_rnn_layers=3, rnn_size=1024, use_gru=False, - share_rnn_weights=False, ) + rnn_direction="forward", ) loss = model(self.audio, self.audio_len, self.text, self.text_len) self.assertEqual(loss.numel(), 1) @@ -60,7 +60,7 @@ class TestDeepSpeech2Model(unittest.TestCase): num_rnn_layers=3, rnn_size=1024, use_gru=True, - share_rnn_weights=False, ) + rnn_direction="forward", ) loss = model(self.audio, self.audio_len, self.text, self.text_len) self.assertEqual(loss.numel(), 1) @@ -72,7 +72,7 @@ class TestDeepSpeech2Model(unittest.TestCase): num_rnn_layers=3, rnn_size=1024, use_gru=False, - share_rnn_weights=True, ) + rnn_direction="bidirect", ) loss = model(self.audio, self.audio_len, self.text, self.text_len) self.assertEqual(loss.numel(), 1) @@ -84,7 +84,7 @@ class TestDeepSpeech2Model(unittest.TestCase): num_rnn_layers=3, rnn_size=1024, use_gru=True, - share_rnn_weights=True, ) + rnn_direction="bidirect", ) loss = model(self.audio, self.audio_len, self.text, self.text_len) self.assertEqual(loss.numel(), 1) @@ -96,7 +96,7 @@ class TestDeepSpeech2Model(unittest.TestCase): num_rnn_layers=3, rnn_size=1024, use_gru=False, - share_rnn_weights=False, ) + rnn_direction="forward", ) loss = model(self.audio, self.audio_len, self.text, self.text_len) self.assertEqual(loss.numel(), 1) diff --git a/tests/unit/asr/deepspeech2_online_model_test.py b/tests/unit/asr/deepspeech2_online_model_test.py index f23c4926..f7ea87b1 100644 --- a/tests/unit/asr/deepspeech2_online_model_test.py +++ b/tests/unit/asr/deepspeech2_online_model_test.py @@ -19,11 +19,11 @@ import numpy as np import paddle from paddle import inference -from paddlespeech.s2t.models.ds2_online import DeepSpeech2InferModelOnline -from paddlespeech.s2t.models.ds2_online import DeepSpeech2ModelOnline +from paddlespeech.s2t.models.ds2 import DeepSpeech2InferModel +from paddlespeech.s2t.models.ds2 import DeepSpeech2Model -class TestDeepSpeech2ModelOnline(unittest.TestCase): +class TestDeepSpeech2Model(unittest.TestCase): def setUp(self): paddle.set_device('cpu') @@ -45,7 +45,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.text_len = paddle.to_tensor(text_len, dtype='int64') def test_ds2_1(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -58,7 +58,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.assertEqual(loss.numel(), 1) def test_ds2_2(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -71,7 +71,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.assertEqual(loss.numel(), 1) def test_ds2_3(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -84,7 +84,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.assertEqual(loss.numel(), 1) def test_ds2_4(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -97,7 +97,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.assertEqual(loss.numel(), 1) def test_ds2_5(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -110,7 +110,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): self.assertEqual(loss.numel(), 1) def test_ds2_6(self): - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -125,7 +125,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): def test_ds2_7(self): use_gru = False - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -156,7 +156,7 @@ class TestDeepSpeech2ModelOnline(unittest.TestCase): def test_ds2_8(self): use_gru = True - model = DeepSpeech2ModelOnline( + model = DeepSpeech2Model( feat_size=self.feat_dim, dict_size=10, num_conv_layers=2, @@ -191,7 +191,7 @@ class TestDeepSpeech2StaticModelOnline(unittest.TestCase): export_prefix = "exp/deepspeech2_online/checkpoints/test_export" if not os.path.exists(os.path.dirname(export_prefix)): os.makedirs(os.path.dirname(export_prefix), mode=0o755) - infer_model = DeepSpeech2InferModelOnline( + infer_model = DeepSpeech2InferModel( feat_size=161, dict_size=4233, num_conv_layers=2, diff --git a/tests/unit/server/offline/test_server_client.sh b/tests/unit/server/offline/test_server_client.sh index dc52609c..29bdd403 100644 --- a/tests/unit/server/offline/test_server_client.sh +++ b/tests/unit/server/offline/test_server_client.sh @@ -1,5 +1,7 @@ #!/bin/bash # bash test_server_client.sh +## require lsof to get server pid +## apt-get install -y lsof StartService(){ # Start service diff --git a/tests/unit/tts/test_data_table.py b/tests/unit/tts/test_data_table.py index 3ff5bc1a..773942a2 100644 --- a/tests/unit/tts/test_data_table.py +++ b/tests/unit/tts/test_data_table.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from paddlespeech.t2s.datasets.data_tabel import DataTable +from paddlespeech.t2s.datasets.data_table import DataTable def test_audio_dataset():