Handle Stack/pack TF API change in TF 1.0
@@ -783,16 +783,20 @@ def dot(x, y):
(2, 4, 5)
```
"""
+ if hasattr(tf, 'unstack'):
+ unstack = tf.unstack
+ else:
+ unstack = tf.unpack
if ndim(x) is not None and (ndim(x) > 2 or ndim(y) > 2):
x_shape = []
- for i, s in zip(int_shape(x), tf.unpack(tf.shape(x))):
+ for i, s in zip(int_shape(x), unstack(tf.shape(x))):
if i is not None:
x_shape.append(i)
else:
x_shape.append(s)
x_shape = tuple(x_shape)
y_shape = []
- for i, s in zip(int_shape(y), tf.unpack(tf.shape(y))):
+ for i, s in zip(int_shape(y), unstack(tf.shape(y))):
if i is not None:
y_shape.append(i)
else:
@@ -1991,6 +1995,12 @@ def rnn(step_function, inputs, initial_states,
# TODO: remove later.
if hasattr(tf, 'select'):
tf.where = tf.select
+ if hasattr(tf, 'stack'):
+ stack = tf.stack
+ unstack = tf.unstack
+ else:
+ stack = tf.pack
+ unstack = tf.unpack
if unroll:
if not inputs.get_shape()[0]:
@@ -2000,12 +2010,12 @@ def rnn(step_function, inputs, initial_states,
successive_states = []
successive_outputs = []
- input_list = tf.unpack(inputs)
+ input_list = unstack(inputs)
if go_backwards:
input_list.reverse()
if mask is not None:
- mask_list = tf.unpack(mask)
+ mask_list = unstack(mask)
if go_backwards:
mask_list.reverse()
@@ -2070,6 +2080,9 @@ def rnn(step_function, inputs, initial_states,
dtype=inputs.dtype,
size=time_steps,
tensor_array_name='input_ta')
+ if hasattr(input_ta, 'unstack'):
+ input_ta = input_ta.unstack(inputs)
+ else:
input_ta = input_ta.unpack(inputs)
time = tf.constant(0, dtype='int32', name='time')
@@ -2088,6 +2101,9 @@ def rnn(step_function, inputs, initial_states,
dtype=tf.bool,
size=time_steps,
tensor_array_name='mask_ta')
+ if hasattr(mask_ta, 'unstack'):
+ mask_ta = mask_ta.unstack(mask)
+ else:
mask_ta = mask_ta.unpack(mask)
def _step(time, output_ta_t, *states):
@@ -2125,6 +2141,9 @@ def rnn(step_function, inputs, initial_states,
output_ta = final_outputs[1]
new_states = final_outputs[2:]
+ if hasattr(output_ta, 'stack'):
+ outputs = output_ta.stack()
+ else:
outputs = output_ta.pack()
last_output = output_ta.read(last_time - 1)
