Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit 31dfebc

Browse files
authored
Merge pull request #255 from Delta-ML/nwe
gcompiler install
2 parents 9e87500 + 9eee269 commit 31dfebc

File tree

24 files changed

+737
-120
lines changed

24 files changed

+737
-120
lines changed

delta/data/frontend/fbank_pitch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ def params(cls, config=None):
197197
hparams.add_hparam('delta_pitch_scale', delta_pitch_scale)
198198
hparams.add_hparam('delta_pitch_noise_stddev', delta_pitch_noise_stddev)
199199
hparams.add_hparam('normalization_left_context', normalization_left_context)
200-
hparams.add_hparam('normalization_right_context', normalization_right_context)
200+
hparams.add_hparam('normalization_right_context',
201+
normalization_right_context)
201202
hparams.add_hparam('delta_window', delta_window)
202203
hparams.add_hparam('delay', delay)
203204
hparams.add_hparam('add_pov_feature', add_pov_feature)
204-
hparams.add_hparam('add_normalized_log_pitch',
205-
add_normalized_log_pitch)
205+
hparams.add_hparam('add_normalized_log_pitch', add_normalized_log_pitch)
206206
hparams.add_hparam('add_delta_pitch', add_delta_pitch)
207207
hparams.add_hparam('add_raw_log_pitch', add_raw_log_pitch)
208208

delta/data/frontend/mel_spectrum.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def params(cls, config=None):
100100
hparams.add_hparam('filterbank_channel_count', filterbank_channel_count)
101101
hparams.add_hparam('sample_rate', sample_rate)
102102

103-
104103
return hparams
105104

106105
def call(self, audio_data, sample_rate):
@@ -130,11 +129,11 @@ def call(self, audio_data, sample_rate):
130129
sample_rate = tf.cast(sample_rate, dtype=tf.int32)
131130

132131
mel_spectrum = py_x_ops.mel_spectrum(
133-
spectrum,
134-
sample_rate,
135-
upper_frequency_limit=p.upper_frequency_limit,
136-
lower_frequency_limit=p.lower_frequency_limit,
137-
filterbank_channel_count=p.filterbank_channel_count)
132+
spectrum,
133+
sample_rate,
134+
upper_frequency_limit=p.upper_frequency_limit,
135+
lower_frequency_limit=p.lower_frequency_limit,
136+
filterbank_channel_count=p.filterbank_channel_count)
138137

139138
mel_spectrum_out = tf.squeeze(mel_spectrum, axis=0)
140139

delta/data/frontend/mel_spectrum_test.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
# ==============================================================================
1616
"""The model tests MelSpectrum FE."""
1717

18-
1918
from pathlib import Path
2019
import delta.compat as tf
2120
from core.ops import PACKAGE_OPS_DIR
2221
from delta.data.frontend.read_wav import ReadWav
2322
from delta.data.frontend.mel_spectrum import MelSpectrum
2423

24+
2525
class MelSpectrumTest(tf.test.TestCase):
2626
"""
2727
MelSpectrum extraction test.
2828
"""
29+
2930
def test_mel_spectrum(self):
3031
# 16kHz test
3132
wav_path_16k = str(Path(PACKAGE_OPS_DIR).joinpath('data/sm1_cln.wav'))
@@ -35,19 +36,24 @@ def test_mel_spectrum(self):
3536
read_wav = ReadWav.params().instantiate()
3637
input_data, sample_rate = read_wav(wav_path_16k)
3738
print(sample_rate.eval())
38-
config = {'type': 'MelSpectrum', 'window_type': 'hann',
39-
'upper_frequency_limit': 7600, 'filterbank_channel_count': 80,
40-
'lower_frequency_limit': 80, 'dither': 0.0,
41-
'window_length': 0.025, 'frame_length': 0.010,
42-
'remove_dc_offset': False, 'preEph_coeff': 0.0,
43-
'output_type': 3, 'sample_rate': 16000}
39+
config = {
40+
'type': 'MelSpectrum',
41+
'window_type': 'hann',
42+
'upper_frequency_limit': 7600,
43+
'filterbank_channel_count': 80,
44+
'lower_frequency_limit': 80,
45+
'dither': 0.0,
46+
'window_length': 0.025,
47+
'frame_length': 0.010,
48+
'remove_dc_offset': False,
49+
'preEph_coeff': 0.0,
50+
'output_type': 3,
51+
'sample_rate': 16000
52+
}
4453
mel_spectrum = MelSpectrum.params(config).instantiate()
4554
mel_spectrum_test = mel_spectrum(input_data, sample_rate)
4655
print(mel_spectrum_test.eval()[0:2, 0:10])
4756

4857

4958
if __name__ == '__main__':
5059
tf.test.main()
51-
52-
53-

delta/data/frontend/pitch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ def params(cls, config=None):
179179
hparams.add_hparam('delta_pitch_scale', delta_pitch_scale)
180180
hparams.add_hparam('delta_pitch_noise_stddev', delta_pitch_noise_stddev)
181181
hparams.add_hparam('normalization_left_context', normalization_left_context)
182-
hparams.add_hparam('normalization_right_context', normalization_right_context)
182+
hparams.add_hparam('normalization_right_context',
183+
normalization_right_context)
183184
hparams.add_hparam('delta_window', delta_window)
184185
hparams.add_hparam('delay', delay)
185186
hparams.add_hparam('add_pov_feature', add_pov_feature)
186-
hparams.add_hparam('add_normalized_log_pitch',
187-
add_normalized_log_pitch)
187+
hparams.add_hparam('add_normalized_log_pitch', add_normalized_log_pitch)
188188
hparams.add_hparam('add_delta_pitch', add_delta_pitch)
189189
hparams.add_hparam('add_raw_log_pitch', add_raw_log_pitch)
190190

delta/data/frontend/pitch_test.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@ def test_spectrum(self):
4343

4444
self.assertEqual(tf.rank(pitch_test).eval(), 2)
4545

46-
output_true = np.array(
47-
[
48-
[0.03881124, 0.3000031, - 0.02324523],
49-
[0.006756478, 0.3000097, 0.01047742],
50-
[0.02455365, 0.3000154, 0.00695902],
51-
[0.02453586, 0.3000221, 0.008448198],
52-
[0.03455311, 0.3000307, - 0.07547269],
53-
[0.04293294, 0.3000422, - 0.04193667]
54-
]
55-
)
46+
output_true = np.array([[0.03881124, 0.3000031, -0.02324523],
47+
[0.006756478, 0.3000097, 0.01047742],
48+
[0.02455365, 0.3000154, 0.00695902],
49+
[0.02453586, 0.3000221, 0.008448198],
50+
[0.03455311, 0.3000307, -0.07547269],
51+
[0.04293294, 0.3000422, -0.04193667]])
5652

5753
# self.assertAllClose(
5854
# pitch_test.eval()[0:6, :], output_true, rtol=1e-05, atol=1e-05)

delta/data/preprocess/text_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def char_cut_tf(input_str):
100100
def load_textline_dataset(paths, column_num):
101101
"""Load raw data for text task."""
102102
ds = tf.data.TextLineDataset(paths)
103-
ds = ds.map(
104-
lambda x: tf.squeeze(tf.strings.split(x, sep="\t", result_type="RaggedTensor"), axis = 0))
103+
ds = ds.map(lambda x: tf.squeeze(
104+
tf.strings.split(x, sep="\t", result_type="RaggedTensor"), axis=0))
105105
ds = ds.filter(lambda line: tf.equal(tf.size(line), column_num))
106106
ds_list = []
107107
for i in range(column_num):

deltann/api/c_api.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ limitations under the License.
1818
#include <string>
1919
#include <vector>
2020

21+
#include <string.h>
2122
#include "api/c_api.h"
2223
#include "core/config.h"
2324
#include "core/runtime.h"
24-
#include <string.h>
2525
#include "json/json.h"
2626

2727
#ifdef __cplusplus
2828
extern "C" {
2929
#endif // __cplusplus
3030

3131
using delta::RuntimeConfig;
32-
//using delta::Config;
32+
// using delta::Config;
3333
using delta::core::In;
3434
using delta::core::Runtime;
3535

@@ -70,42 +70,42 @@ DeltaStatus DeltaSetInputs(InferHandel inf, Input* inputs, int num) {
7070
DeltaStatus DeltaSetJsonInputs(InferHandel inf, const char* inputs) {
7171
// only support int input now
7272
// TODO: support int, string, float
73-
//std::string yaml = yaml_file;
74-
//Config* conf = new Config(yaml_file);
73+
// std::string yaml = yaml_file;
74+
// Config* conf = new Config(yaml_file);
7575
Runtime* rt = static_cast<Runtime*>(inf);
7676
bool bRet = false;
7777

7878
Json::Reader reader;
7979
Json::Value root;
80-
Json::Value::Members keys;
80+
Json::Value::Members keys;
8181

8282
bRet = reader.parse(inputs, root);
8383
if (false == bRet) {
8484
LOG_FATAL << "error: input_json parse failed.\n";
8585
return DeltaStatus::kDeltaError;
8686
}
87-
keys = root.getMemberNames();
87+
keys = root.getMemberNames();
8888
int idx = 0;
8989
int num = keys.size();
9090
Input* ins = new Input[num]();
9191
std::vector<In> insVec;
92-
for (Json::Value::Members::iterator iterKey = keys.begin(); iterKey != keys.end(); iterKey++)
93-
{
94-
std::string strKey = *iterKey;
95-
Json::Value val_array = root[*iterKey];
96-
int iSize = val_array.size();
92+
for (Json::Value::Members::iterator iterKey = keys.begin();
93+
iterKey != keys.end(); iterKey++) {
94+
std::string strKey = *iterKey;
95+
Json::Value val_array = root[*iterKey];
96+
int iSize = val_array.size();
9797
int* input_val = new int[iSize]();
98-
for ( int nIndex = 0;nIndex < iSize;++ nIndex ) {
98+
for (int nIndex = 0; nIndex < iSize; ++nIndex) {
9999
input_val[nIndex] = val_array[nIndex].asInt();
100100
}
101101
ins[idx].ptr = reinterpret_cast<void*>(input_val);
102102
ins[idx].nelms = iSize;
103-
//ins[idx].shape = (*conf).config()["model"]["graphs"][0]["inputs"][idx]["shape"].as<std::vector<int>>().data();
103+
// ins[idx].shape =
104+
// (*conf).config()["model"]["graphs"][0]["inputs"][idx]["shape"].as<std::vector<int>>().data();
104105
ins[idx].input_name = strKey.c_str();
105106
ins[idx].graph_name = "default";
106-
insVec.push_back(In(ins[idx].graph_name, ins[idx].input_name,
107-
ins[idx].ptr,
108-
ins[idx].nelms));
107+
insVec.push_back(In(ins[idx].graph_name, ins[idx].input_name, ins[idx].ptr,
108+
ins[idx].nelms));
109109
idx += 1;
110110
}
111111
LOG_INFO << "ins size:" << insVec.size();

deltann/api/c_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ DELTA_CAPI_EXPORT extern InferHandel DeltaCreate(ModelHandel model);
4848
// set input
4949
DELTA_CAPI_EXPORT extern DeltaStatus DeltaSetInputs(InferHandel inf, Input* in,
5050
int elem_num);
51-
DELTA_CAPI_EXPORT extern DeltaStatus DeltaSetJsonInputs(InferHandel inf,
52-
const char* inputs);
51+
DELTA_CAPI_EXPORT extern DeltaStatus DeltaSetJsonInputs(InferHandel inf,
52+
const char* inputs);
5353

5454
// run
5555
DELTA_CAPI_EXPORT extern DeltaStatus DeltaRun(InferHandel inf);

deltann/core/runtime.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ DeltaStatus Runtime::set_inputs(const std::vector<In>& ins) {
151151
<< in._shape;
152152
input.set_shape(in._shape);
153153
}
154-
if (input.dtype() != DataType::DELTA_CHAR){
154+
if (input.dtype() != DataType::DELTA_CHAR) {
155155
LOG_INFO << "Handle not char type input!";
156156
DELTA_CHECK_EQ(in._nelms, input.nelms()) << in._nelms << ":"
157157
<< input.nelms();
158-
} else {
159-
// If string shape is [1], the memory layout is bytes, not equal 1, so do not check
158+
} else {
159+
// If string shape is [1], the memory layout is bytes, not equal 1, so
160+
// do not check
160161
LOG_INFO << "Handle char type input!";
161-
}
162+
}
162163

163164
InputData input_data(input);
164165
input_data.copy_from(in._ptr, in._nelms);

deltann/examples/text_conf_json/test_conf_json.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ limitations under the License.
2424

2525
using namespace std;
2626

27-
#include "api/c_api.h"
2827
#include <iostream>
28+
#include "api/c_api.h"
2929

3030
float time_run(InferHandel inf) {
3131
struct timespec start, end;
@@ -36,13 +36,13 @@ float time_run(InferHandel inf) {
3636
(end.tv_nsec - start.tv_nsec) / 1000000000.0;
3737
}
3838

39-
string write_Json(){
39+
string write_Json() {
4040
Json::Value root;
4141
Json::Value input_idx;
4242
Json::Value input_pad;
4343
Json::Value input_seg;
4444

45-
for(int i=0; i<512; i++){
45+
for (int i = 0; i < 512; i++) {
4646
input_idx[i] = 0;
4747
}
4848
input_idx[0] = 102;
@@ -53,7 +53,7 @@ string write_Json(){
5353
input_idx[5] = 1963;
5454
input_idx[6] = 4639;
5555

56-
for(int i=0; i<512; i++){
56+
for (int i = 0; i < 512; i++) {
5757
input_pad[i] = 0;
5858
}
5959
input_pad[0] = 1;
@@ -64,7 +64,7 @@ string write_Json(){
6464
input_pad[5] = 1;
6565
input_pad[6] = 1;
6666

67-
for(int i=0; i<512; i++){
67+
for (int i = 0; i < 512; i++) {
6868
input_seg[i] = 0;
6969
}
7070
input_seg[0] = 0;
@@ -73,7 +73,7 @@ string write_Json(){
7373
input_seg[3] = 0;
7474
input_seg[4] = 0;
7575
input_seg[5] = 1;
76-
input_seg[6] = 1;
76+
input_seg[6] = 1;
7777

7878
root["input_ids"] = input_idx;
7979
root["input_mask"] = input_pad;
@@ -84,7 +84,6 @@ string write_Json(){
8484
return out;
8585
}
8686

87-
8887
int main(int argc, char** argv) {
8988
// const char* yaml_file = "model.yaml";
9089
const char* yaml_file = argv[1];
@@ -93,7 +92,7 @@ int main(int argc, char** argv) {
9392
ModelHandel model = DeltaLoadModel(yaml_file);
9493
InferHandel inf = DeltaCreate(model);
9594
DeltaSetJsonInputs(inf, input_json.c_str());
96-
cout<<"finish parse"<<endl;
95+
cout << "finish parse" << endl;
9796

9897
// DeltaRun(inf);
9998
float dur = time_run(inf);

0 commit comments

Comments
 (0)