将脚本转换为TF2

时间:2019-11-29 02:29:07

标签: tensorflow machine-learning neural-network tensorflow2.0

我曾经使用过自动更新脚本,但是仍然遇到一些问题。该区域似乎是导致问题的部分,我们将不胜感激。

已发出错误:“ AttributeError:'BatchDataset'对象没有属性'output_types'”

# network parameters
n_hidden_1 = 50
n_hidden_2 = 25


ds_train = tf.data.Dataset.from_tensor_slices((X_placeholder, Y_placeholder)).shuffle(buffer_size=round(len(X_train) * 0.3)).batch(batch_size_placeholder)

ds_test = tf.data.Dataset.from_tensor_slices((X_placeholder, Y_placeholder)).batch(batch_size_placeholder)

ds_iter = tf.compat.v1.data.make_one_shot_iterator(ds_train.output_types, ds_train.output_shapes)

next_x, next_y = ds_iter.get_next()

train_init_op = ds_iter.make_initializer(ds_train)
test_init_op = ds_iter.make_initializer(ds_test)

1 个答案:

答案 0 :(得分:0)

替换:

ds_train.output_types

具有:

tf.compat.v1.data.get_output_types(ds_train)

类似地,您可能需要tf.compat.v1.data.get_output_shapes(ds_train)