Keras报错l2_normalize() got an unexpected keyword argument 'axis'

keras.backend.tensorflow_backend.py中出问题的一段

def l2_normalize(x, axis=None):
    """Normalizes a tensor wrt the L2 norm alongside the specified axis.

    # Arguments
        x: Tensor or variable.
        axis: axis along which to perform normalization.

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

return tf.nn.l2_normalize(x, axis=axis)改成 return tf.nn.l2_normalize(x, dim=axis^1)

因为用了异或,用的时候要指定axis的值,不然会报错,

或者也可以在定义的时候干脆把axis默认改成0

def l2_normalize(x, axis=None)改成def l2_normalize(x,axis=0)

改过保存重启IDE并import一下刷新pyc文件

(也不知道是不是我的keras和tensorflow之间版本差异大的原因keras==2.2.0, tensorflow==1.3.0, 不清楚后面的tensorflow版本是不是支持axis参数0.0)

___________________________________________________________________

刚查了一下,是tensorflow官方1.4.1开始弃用dimension,转为axis

阅读更多
换一批

got an unexpected keyword argument

07-27

如题,本来是head first python里面的一道例题,没有给答案,但是给了修改的思路,系统是win,py版本是3.4最新的rnrn要求是:改后print_lol(),改with从句,然后让man_data.txt的内容变成一行一行的列出(现在只有一行)rnrn源码:rn[code=python]rnman=[]rnother=[]rnrntry:rn data=open('sketch.txt')rn for each_line in data:rn try:rn (role,line_spoken)=each_line.split(':',1)rn line_spoken=line_spoken.strip()rn if role=='Man':rn man.append(line_spoken)rn elif role=='Other Man':rn other.append(line_spoken)rn except ValueError:rn passrn data.close()rnrnexcept IOError:rn print('The data file is missing')rnrnimport nesterrnrntry:rn with open('man_data.txt',"w") as man_file:rn nester.print_lol(man, file=man_file)rn with open('other_data.txt',"w") as other_file:rn nester.print_lol(other, file=other_file)rnrnexcept IOError:rn print('File error:'+str(err))rn[/code]rnrnrnrn其中,nester模块内容为:rn[code=python]import sysrndef print_lol(the_list,indent=False,level=0,fh=sys.stdout):rn for each_item in the_list:rn if isinstance(each_item,list):rn print_lol(each_item,indent,level+1,fh)rn else:rn if indent:rn for tab_stop in range(level):rn print('\t',end='',file=fh)rn print(each_item,file=fh)rn[/code]rnrn错误提示:rn[code=python]Traceback (most recent call last):rn File "E:\05.程序\py\44.py", line 28, in rn nester.print_lol(man, file=man_file)rnTypeError: print_lol() got an unexpected keyword argument 'file'[/code]rnrn是print_lol()使用错误吗?因为print_lol()是给了的,我改了with从句的print改成print_lol

没有更多推荐了,返回首页