【问题标题】:"AttributeError:" After converting script to TF2"AttributeError:" 将脚本转换为 TF2 后
【发布时间】:2020-03-24 15:43:26
【问题描述】:

我习惯了自动更新脚本,但仍然遇到一些问题。这个区域似乎是导致问题的部分,任何帮助将不胜感激。

发出错误:“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)

【问题讨论】:

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


    【解决方案1】:

    替换:

    ds_train.output_types
    

    与:

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

    同样你可能需要tf.compat.v1.data.get_output_shapes(ds_train)

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2019-06-23
      • 2011-02-19
      • 2022-06-15
      相关资源
      最近更新 更多