定义一个超简单的Keras函数,并调用,输出return值
from keras import backend as K
a=K.constant([1,2,3],dtype="int32")
b=K.constant([2,3,4],dtype="int32")
def lala(aa,bb):
return aa,bb
如果输出写成
print(K.eval(lala(a,b)))
会报错:
Traceback (most recent call last):
File "E:/python_chu_new/projects/a11.py", line 164, in <module>
print(K.eval(lala(a,b)))
File "D:\Anaconda3\envs\NLPenv\lib\site-packages\keras\backend\tensorflow_backend.py", line 673, in eval
return to_dense(x).eval(session=get_session())
AttributeError: 'tuple' object has no attribute 'eval'
正确的写法是:
aaa,bbb=lala(a,b)
print(K.eval(aaa))
print(K.eval(bbb))
输出结果为:
[1 2 3]
[2 3 4]