achieve compatibility with tensorflow 1.0rc1
@@ -28,6 +28,10 @@ _GRAPH_LEARNING_PHASES = {}
# Change its value via `manual_variable_initialization(value)`.
_MANUAL_VAR_INIT = False
+# These two integers contain the tensorflow version for coping with API breaks.
+tf_major_version = int(tf.__version__.split('.')[0])
+tf_minor_version = int(tf.__version__.split('.')[1])
+
def clear_session():
"""Destroys the current TF graph and creates a new one.
@@ -240,6 +244,11 @@ def variable(value, dtype=None, name=None):
sparse_coo = value.tocoo()
indices = np.concatenate((np.expand_dims(sparse_coo.row, 1),
np.expand_dims(sparse_coo.col, 1)), 1)
+ if tf_major_version >= 1:
+ v = tf.SparseTensor(indices=indices,
+ values=sparse_coo.data,
+ dense_shape=sparse_coo.shape)
+ else:
v = tf.SparseTensor(indices=indices,
values=sparse_coo.data,
shape=sparse_coo.shape)
@@ -1429,6 +1438,9 @@ def concatenate(tensors, axis=-1):
if py_all([is_sparse(x) for x in tensors]):
return tf.sparse_concat(axis, tensors)
+ else:
+ if tf_major_version >= 1:
+ return tf.concat([to_dense(x) for x in tensors], axis)
else:
try:
return tf.concat_v2([to_dense(x) for x in tensors], axis)
@@ -3061,6 +3073,10 @@ def ctc_decode(y_pred, input_length, greedy=True, beam_width=100,
sequence_length=input_length, beam_width=beam_width,
top_paths=top_paths)
+ if tf_major_version >= 1:
+ decoded_dense = [tf.sparse_to_dense(st.indices, st.dense_shape, st.values, default_value=-1)
+ for st in decoded]
+ else:
decoded_dense = [tf.sparse_to_dense(st.indices, st.shape, st.values, default_value=-1)
for st in decoded]
