tensorflow版本升级报错+解决方案汇总

【持续更新】那些年de过的tensorflow版本升级报错


最近基于之前的大佬写过的代码,用tensorflow在写一个聊天机器人,因为版本的原因,收集到了很多报错信息,将解决方法汇总了一下,方便以后查看。

  • AttributeError: ‘module’ object hasno attribute ‘histogram_summary’

    解决方法:tf.histogram_summary() 改为: tf.summaries.histogram()

  • ValueError: Only call sigmoid_cross_entropy_with_logits with named arguments (labels=…, logits=…, …)

    解决方法:

    loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(output,Y))

    改为

    loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(labels=output,logits=Y))

  • AttributeError: module ‘tensorflow’ has no attribute ‘batch_matmul’

    解决方法:batch_matmul() 改为 matmul()

  • AttributeError: module ‘tensorflow’ has no attribute ‘pack’

    解决方法:pack() 改为 stack()

  • TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead.

    解决方法:tf.cocat([fw,bw],2) 改为 tf.cocat(2,[fw,bw])

  • Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32

    解决方法:tf.split(axis, num_or_size_splits, value) 改为 tf.split(value, num_or_size_splits, axis)

  • ValueError: Shapes (2, 100, 1) and () are incompatible

    解决方法:concated = tf.concat(1, [indices, sparse_labels]) 改为 concated = tf.concat([indices, sparse_labels], 1)

  • AttributeError: module ‘tensorflow’ has no attribute ‘merge_all_summaries’

    解决方法:summary_op = tf.merge_all_summaries() 改为:summary_op = tf.summary.merge_all()

  • AttributeError: ‘module’ object has no attribute ‘image_summary’

    解决方法:tf.image_summary() 改为 tf.summary.image()

  • AttributeError: 'module’object has no attribute ‘SummaryWriter’

    解决方法:tf.train.SummaryWriter() 改为:tf.summary.FileWriter()

  • AttributeError: ‘module’ object has no attribute ‘rnn_cell’

    解决方法:tf.nn.rnn_cell 改为 tf.contrib.rnn

  • ValueError: Variable Wemb/Adam/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

    解决方法:需要定义scope,报错是在optimizer处提示,但需要在定义模型时增加scope

你可能感兴趣的:(笔记,coding)