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

Commit 15045e7

Browse files
authored
Merge pull request #98 from didi/compat
Compat tf v1.x version
2 parents c85dc76 + dfede30 commit 15045e7

File tree

190 files changed

+478
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+478
-496
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ services:
66
before_install:
77
- export DELTA_PATH=`pwd`; echo $DELTA_PATH
88
- export DOCKER_DELTA="/home/gitlab-runner/delta"; echo $DOCKER_DELTA
9-
- docker pull zh794390558/delta:1.14.0-ci-cpu-py3
10-
- docker run -it -d --name travis_con --user root -v ${DELTA_PATH}:${DOCKER_DELTA} zh794390558/delta:1.14.0-ci-cpu-py3 bash
9+
- export CI_IMAGE=zh794390558/delta:2.0.0-ci-cpu-py3
10+
- docker pull ${CI_IMAGE}
11+
- docker run -it -d --name travis_con --user root -v ${DELTA_PATH}:${DOCKER_DELTA} ${CI_IMAGE} bash
1112
- docker exec travis_con bash -c "gcc -v && g++ -v"
1213
- docker exec travis_con bash -c "cd ${DOCKER_DELTA}; source env.sh"
1314
- docker exec travis_con bash -c "cd ${DOCKER_DELTA}/tools; touch test.done"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ To verify the installation, run:
7878

7979
```shell
8080
# Activate conda environment
81-
conda activate delta-py3.6-tf1.14
81+
conda activate delta-py3.6-tf2.0.0
8282
# Or use the following command if your conda version is < 4.6
83-
# source activate delta-py3.6-tf1.14
83+
# source activate delta-py3.6-tf2.0.0
8484

8585
# Add DELTA enviornment
8686
source env.sh

delta/data/feat/speech_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import os
1818

1919
import numpy as np
20-
import tensorflow as tf
20+
import delta.compat as tf
2121
from absl import logging
2222

2323
from delta.data.feat import speech_ops

delta/data/feat/speech_feature_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import librosa
2121
import numpy as np
22-
import tensorflow as tf
22+
import delta.compat as tf
2323
from absl import logging
2424

2525
from delta.data.feat import speech_ops

delta/data/feat/speech_ops.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
from absl import logging
1919

2020
#pylint: disable=no-name-in-module
21-
import tensorflow as tf
22-
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
21+
import delta.compat as tf
22+
from tensorflow.python.ops import gen_audio_ops as audio_ops
2323

2424
from delta import utils
25+
from delta.utils.hparam import HParams
2526
from delta.layers.ops import py_x_ops
2627

2728

@@ -36,7 +37,7 @@ def speech_params(sr=16000,
3637
cmvn=False,
3738
cmvn_path=''):
3839
''' speech feat params '''
39-
p = tf.contrib.training.HParams()
40+
p = HParams()
4041
p.add_hparam("audio_sample_rate", sr)
4142
if dither:
4243
p.add_hparam("audio_dither", 1.0 / np.iinfo(np.int16).max)
@@ -68,7 +69,7 @@ def read_wav(wavfile, params):
6869
'''
6970
contents = tf.read_file(wavfile)
7071
#pylint: disable=no-member
71-
waveforms = contrib_audio.decode_wav(
72+
waveforms = tf.audio.decode_wav(
7273
contents,
7374
desired_channels=params.audio_desired_channels,
7475
desired_samples=params.audio_desired_samples,
@@ -103,7 +104,7 @@ def powspec_feat(samples,
103104
del preemph
104105

105106
#pylint: disable=no-member
106-
feat = contrib_audio.audio_spectrogram(
107+
feat = audio_ops.audio_spectrogram(
107108
samples,
108109
window_size=winlen * sr,
109110
stride=winstep * sr,
@@ -303,7 +304,7 @@ def _loop_body(time, inputs, output_tas):
303304
loop_vars = (time, waveforms, output_tas)
304305

305306
parallel_iterations = 10
306-
shape_invariants = tf.contrib.framework.nest.map_structure(
307+
shape_invariants = tf.nest.map_structure(
307308
lambda t: tf.TensorShape(None), loop_vars)
308309

309310
(time, inputs, output_tas) = tf.while_loop(
@@ -361,7 +362,7 @@ def _loop_body(time, end_time, context, left_context, right_context,
361362
loop_vars = (time, T, context, left_context, right_context, output_tas)
362363

363364
parallel_iterations = 10
364-
shape_invariants = tf.contrib.framework.nest.map_structure(
365+
shape_invariants = tf.nest.map_structure(
365366
lambda t: tf.TensorShape(None), loop_vars)
366367

367368
(time, end_time, context, left_context, right_context,

delta/data/feat/speech_ops_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import os
1818
from pathlib import Path
1919
import numpy as np
20-
import tensorflow as tf
20+
import delta.compat as tf
2121
from absl import logging
2222

2323
from delta.data.feat.speech_feature import load_wav

delta/data/feat/tf_speech_feature.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import functools
1818

1919
import numpy as np
20-
import tensorflow as tf
20+
import delta.compat as tf
2121
import scipy.signal
2222
#pylint: disable=ungrouped-imports,no-name-in-module
23-
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
2423

2524
from delta import utils
25+
from delta.utils.hparam import HParams
2626

2727

2828
def add_delta_deltas(filterbanks, name=None):
@@ -61,7 +61,7 @@ def compute_mel_filterbank_features(waveforms,
6161
frame_step=10,
6262
fft_length=None,
6363
window_fn=functools.partial(
64-
tf.contrib.signal.hann_window,
64+
tf.signal.hann_window,
6565
periodic=True),
6666
lower_edge_hertz=80.0,
6767
upper_edge_hertz=7600.0,
@@ -109,7 +109,7 @@ def compute_mel_filterbank_features(waveforms,
109109
if fft_length is None:
110110
fft_length = int(2**(np.ceil(np.log2(frame_length))))
111111

112-
stfts = tf.contrib.signal.stft(
112+
stfts = tf.signal.stft(
113113
waveforms,
114114
frame_length=frame_length,
115115
frame_step=frame_step,
@@ -130,7 +130,7 @@ def compute_mel_filterbank_features(waveforms,
130130
# Warp the linear-scale, magnitude spectrograms into the mel-scale.
131131
num_spectrogram_bins = magnitude_spectrograms.shape[-1].value
132132
linear_to_mel_weight_matrix = (
133-
tf.contrib.signal.linear_to_mel_weight_matrix(num_mel_bins,
133+
tf.signal.linear_to_mel_weight_matrix(num_mel_bins,
134134
num_spectrogram_bins,
135135
sample_rate,
136136
lower_edge_hertz,
@@ -153,7 +153,7 @@ def read_wav(wavfile, params):
153153
''' samples of shape [nsample] '''
154154
contents = tf.read_file(wavfile)
155155
#pylint: disable=no-member
156-
waveforms = contrib_audio.decode_wav(
156+
waveforms = tf.audio.decode_wav(
157157
contents,
158158
desired_channels=params.audio_channels,
159159
#desired_samples=params.audio_sample_rate,
@@ -176,7 +176,7 @@ def speech_params(sr=16000,
176176
cmvn=False,
177177
cmvn_path=''):
178178
''' feat params '''
179-
p = tf.contrib.training.HParams()
179+
p = HParams()
180180
p.add_hparam("audio_sample_rate", sr)
181181
p.add_hparam("audio_channels", 1)
182182
p.add_hparam("audio_preemphasis", 0.97)

delta/data/feat/tf_speech_feature_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import os
1818
from pathlib import Path
1919

20-
import tensorflow as tf
20+
import delta.compat as tf
2121
from absl import logging
2222

2323
from delta.data.feat.speech_feature import load_wav

delta/data/frontend/analyfiltbank.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616

17-
import tensorflow as tf
17+
import delta.compat as tf
1818

1919
from delta.layers.ops import py_x_ops
2020
from delta.utils.hparam import HParams
@@ -67,7 +67,7 @@ def call(self, audio_data, sample_rate):
6767
if sample_rate == None:
6868
sample_rate = tf.constant(p.sample_rate, dtype=float)
6969

70-
assert_op = tf.compat.v1.assert_equal(
70+
assert_op = tf.assert_equal(
7171
tf.constant(p.sample_rate), tf.cast(sample_rate, dtype=float))
7272
with tf.control_dependencies([assert_op]):
7373

delta/data/frontend/analyfiltbank_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616

17-
import tensorflow as tf
17+
import delta.compat as tf
1818
import os
1919
from pathlib import Path
2020
from delta.data.frontend.read_wav import ReadWav

0 commit comments

Comments
 (0)