TensorFlow报错:TypeError: msr_error() got an unexpected keyword argument 'labels'

TensorFlow报错:TypeError: msr_error() got an unexpected keyword argument ‘labels’

学习莫烦TsnsorFlow教程时,第 20.3 RNN lstm(regression 回归例子) 遇到的一个报错如下:

在这里插入图片描述

TypeError: msr_error() got an unexpected keyword argument ‘labels’

分析

  • msr_error() 函数得到一个意外的关键参数 ‘lables’

  • 通过 help() 查看 tf.contrib.legacy_seq2seq.sequence_loss_by_example 文档

    help(tf.contrib.legacy_seq2seq.sequence_loss_by_example)
    
    Help on function sequence_loss_by_example in module tensorflow.contrib.legacy_seq2seq.python.ops.seq2seq:
    
    sequence_loss_by_example(logits, targets, weights, average_across_timesteps=True, softmax_loss_function=None, name=None)
        Weighted cross-entropy loss for a sequence of logits (per example).
        
        Args:
          logits: List of 2D Tensors of shape [batch_size x num_decoder_symbols].
          targets: List of 1D batch-sized int32 Tensors of the same length as logits.
          weights: List of 1D batch-sized float-Tensors of the same length as logits.
          average_across_timesteps: If set, divide the returned cost by the total
            label weight.
          softmax_loss_function: Function (labels, logits) -> loss-batch to be used
            instead of the standard softmax (the default if this is None). **Note that
            to avoid confusion, it is required for the function to accept named
            arguments.**
          name: Optional name for this operation, default: "sequence_loss_by_example".
        
        Returns:
          1D batch-sized float Tensor: The log-perplexity for each sequence.
        
        Raises:
          ValueError: If len(logits) is different from len(targets) or len(weights).
    
  • softmax_loss_function 参数说明中 Note that to avoid confusion, it is required for the function to accept named arguments,即 注意,为了避免混淆,函数需要接受命名参数

解决方式:定义 msr_error() 函数时,使用 labels,logits 指定,将

def msr_error(self, y_pre, y_target):
    return tf.square(tf.subtract(y_pre, y_target))

改为

def msr_error(self, logits, labels):
    return tf.square(tf.subtract(logits, labels))
  • 9
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值