【報錯相關】TypeError: softmax() got an unexpected keyword argument 'axis'


出現這個問題,有幾種解決辦法,可以調低一下keras的版本,比如:

pip install keras==2.1

不過還有個更方便的方法,從錯誤可知softmax中不包含axis這個參數,那么把axis參數替換成dim就可以了。源代碼是這樣的:

def softmax(x, axis=-1):
    """Softmax of a tensor.

    # Arguments
        x: A tensor or variable.
        axis: The dimension softmax would be performed on.
            The default is -1 which indicates the last dimension.

    # Returns
        A tensor.
    """
    return tf.nn.softmax(x, axis=axis)

更改成這樣:

def softmax(x, axis=-1):
    """Softmax of a tensor.

    # Arguments
        x: A tensor or variable.
        axis: The dimension softmax would be performed on.
            The default is -1 which indicates the last dimension.

    # Returns
        A tensor.
    """
    return tf.nn.softmax(x, dim=axis)

就是改了最后一行。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM