TensorFlow没有属性“with_dependencies”

时间:2016-06-22 23:55:33

标签: tensorflow

我想使用tf.with_dependencies函数来保存我的RNN状态。出于某种原因,我收到以下错误。

Traceback (most recent call last):
  File "/home/chase/workspace/AudioRNN/audiornn.py", line 56, in <module>
    tf.with_dependencies([expected_output], input_tensor)
AttributeError: module 'tensorflow' has no attribute 'with_dependencies'

我的tensorflow代码的其余部分运行正常。我在eclipse中,我按Ctrl +单击tf.with_dependencies,它将我带到源代码。我注意到tf.group函数也在这个文件中,我可以称之为正常。 tf.with_dependencies有什么问题?我在Ubuntu 16.04上。我正在使用python 3和tensorflow的最新版本。

根据要求,这是dir(tf)的打印件。

AggregationMethod
Assert
AttrValue
ConfigProto
DType
DeviceSpec
Dimension
Event
FIFOQueue
FixedLenFeature
FixedLenSequenceFeature
FixedLengthRecordReader
GPUOptions
GRAPH_DEF_VERSION
GRAPH_DEF_VERSION_MIN_CONSUMER
GRAPH_DEF_VERSION_MIN_PRODUCER
Graph
GraphDef
GraphKeys
GraphOptions
HistogramProto
IdentityReader
IndexedSlices
InteractiveSession
LogMessage
NameAttrList
NoGradient
NodeDef
OpError
Operation
OptimizerOptions
PaddingFIFOQueue
Print
QUANTIZED_DTYPES
QueueBase
RandomShuffleQueue
ReaderBase
RegisterGradient
RegisterShape
RunMetadata
RunOptions
Session
SessionLog
SparseTensor
SparseTensorValue
Summary
TFRecordReader
Tensor
TensorArray
TensorShape
TextLineReader
VarLenFeature
Variable
VariableScope
WholeFileReader
__builtins__
__cached__
__doc__
__file__
__loader__
__name__
__package__
__path__
__spec__
__version__
abs
absolute_import
accumulate_n
acos
add
add_check_numerics_ops
add_n
add_to_collection
all_variables
app
arg_max
arg_min
argmax
argmin
as_dtype
asin
assert_equal
assert_integer
assert_less
assert_less_equal
assert_negative
assert_non_negative
assert_non_positive
assert_positive
assert_proper_iterable
assert_rank
assert_rank_at_least
assert_type
assert_variables_initialized
assign
assign_add
assign_sub
atan
audio_summary
batch_cholesky
batch_cholesky_solve
batch_fft
batch_fft2d
batch_fft3d
batch_ifft
batch_ifft2d
batch_ifft3d
batch_matmul
batch_matrix_band_part
batch_matrix_determinant
batch_matrix_diag
batch_matrix_diag_part
batch_matrix_inverse
batch_matrix_solve
batch_matrix_solve_ls
batch_matrix_triangular_solve
batch_self_adjoint_eig
batch_to_space
bfloat16
bfloat16_ref
bitcast
bool
bool_ref
boolean_mask
bytes
case
cast
ceil
check_numerics
cholesky
cholesky_solve
clip_by_average_norm
clip_by_global_norm
clip_by_norm
clip_by_value
compat
complex
complex128
complex128_ref
complex64
complex64_ref
complex_abs
concat
cond
conj
constant
constant_initializer
contrib
control_dependencies
convert_to_tensor
convert_to_tensor_or_indexed_slices
core
cos
count_up_to
create_partitioned_variables
cross
decode_csv
decode_json_example
decode_raw
delete_session_tensor
depth_to_space
deserialize_many_sparse
device
diag
diag_part
digamma
div
division
double
double_ref
dynamic_partition
dynamic_stitch
edit_distance
equal
erf
erfc
errors
exp
expand_dims
extract_image_patches
fft
fft2d
fft3d
fill
flags
float16
float16_ref
float32
float32_ref
float64
float64_ref
floor
floordiv
foldl
foldr
gather
gather_nd
get_collection
get_collection_ref
get_default_graph
get_default_session
get_seed
get_session_handle
get_session_tensor
get_variable
get_variable_scope
gfile
global_norm
gradients
greater
greater_equal
group
half
half_ref
histogram_fixed_width
histogram_summary
identity
ifft
ifft2d
ifft3d
igamma
igammac
imag
image
image_summary
import_graph_def
initialize_all_tables
initialize_all_variables
initialize_local_variables
initialize_variables
int16
int16_ref
int32
int32_ref
int64
int64_ref
int8
int8_ref
inv
invert_permutation
is_finite
is_inf
is_nan
is_non_decreasing
is_numeric_tensor
is_strictly_increasing
is_variable_initialized
lbeta
less
less_equal
lgamma
lin_space
linspace
list_diff
listdiff
load_file_system_library
load_op_library
local_variables
log
logging
logical_and
logical_not
logical_or
logical_xor
make_template
map_fn
matching_files
matmul
matrix_determinant
matrix_inverse
matrix_solve
matrix_solve_ls
matrix_triangular_solve
maximum
merge_all_summaries
merge_summary
meshgrid
minimum
mod
moving_average_variables
mul
multinomial
name_scope
neg
nn
no_op
no_regularizer
not_equal
one_hot
ones
ones_initializer
ones_like
op_scope
pack
pad
parse_example
parse_single_example
parse_single_sequence_example
placeholder
placeholder_with_default
polygamma
pow
print_function
py_func
python
python_io
qint16
qint16_ref
qint32
qint32_ref
qint8
qint8_ref
quint16
quint16_ref
quint8
quint8_ref
random_crop
random_gamma
random_normal
random_normal_initializer
random_shuffle
random_uniform
random_uniform_initializer
range
rank
read_file
real
reduce_all
reduce_any
reduce_join
reduce_max
reduce_mean
reduce_min
reduce_prod
reduce_sum
register_tensor_conversion_function
report_uninitialized_variables
reset_default_graph
reshape
resource_loader
reverse
reverse_sequence
round
rsqrt
saturate_cast
scalar_mul
scalar_summary
scan
scatter_add
scatter_sub
scatter_update
segment_max
segment_mean
segment_min
segment_prod
segment_sum
select
self_adjoint_eig
serialize_many_sparse
serialize_sparse
set_random_seed
shape
shape_n
sigmoid
sign
sin
size
slice
space_to_batch
space_to_depth
sparse_add
sparse_concat
sparse_fill_empty_rows
sparse_mask
sparse_matmul
sparse_merge
sparse_placeholder
sparse_reduce_sum
sparse_reorder
sparse_reset_shape
sparse_retain
sparse_segment_mean
sparse_segment_mean_grad
sparse_segment_sqrt_n
sparse_segment_sqrt_n_grad
sparse_segment_sum
sparse_softmax
sparse_split
sparse_tensor_dense_matmul
sparse_tensor_to_dense
sparse_to_dense
sparse_to_indicator
split
sqrt
square
squared_difference
squeeze
stop_gradient
string
string_ref
string_to_hash_bucket
string_to_hash_bucket_fast
string_to_hash_bucket_strong
string_to_number
sub
sysconfig
tan
tanh
test
tile
to_bfloat16
to_double
to_float
to_int32
to_int64
trace
train
trainable_variables
transpose
truediv
truncated_normal
truncated_normal_initializer
tuple
uint16
uint16_ref
uint8
uint8_ref
uniform_unit_scaling_initializer
unique
unique_with_counts
unpack
unsorted_segment_sum
user_ops
variable_axis_size_partitioner
variable_op_scope
variable_scope
verify_tensor_all_finite
where
while_loop
zeros
zeros_initializer
zeros_like
zeta

3 个答案:

答案 0 :(得分:5)

TensorFlow API中没有这样的功能。相反,您可以使用with tf.control_dependencies():tf.identity()来达到预期的效果:

with tf.control_dependencies([expected_output]):
  result = tf.identity(input_tensor)

答案 1 :(得分:1)

或尝试: 来自tensorflow.python.ops.control_flow_ops导入with_dependencies

答案 2 :(得分:0)

tf.with_dependencies在2015年底某个地方已弃用。尽管如此,它仍在tf代码it is no longer exported中定义(函数前面没有@tf_export),因此不可用

使用

with tf.control_dependencies([expected_output]):
  result = tf.identity(input_tensor)

正如mrry所建议的,因为它的作用完全相同。