Keras:具有多个参数的Lambda图层函数 [英] Keras: Lambda layer function with multiple parameters

查看:107
本文介绍了Keras:具有多个参数的Lambda图层函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Keras中编写一个Lambda层,该层调用函数connection,该层运行循环for i in range(0,k),其中将k作为函数connection(x,k)的输入.现在,当我尝试在Functional API中调用该函数时,我尝试使用:

I am trying to write a Lambda layer in Keras which calls a function connection, that runs a loop for i in range(0,k) where k is fed in as an input to the function, connection(x,k). Now, when I try to call the function in the Functional API, I tried using:

k = 5
y = Lambda(connection)(x)

y = Lambda(connection)(x,k)

但是这些方法都不起作用.如何在不将k的值分配为全局参数的情况下提供它?

But neither of those approaches worked. How can I feed in the value of k without assigning it as a global parameter?

推荐答案

只需使用

y = Lambda(connection)((x,k)) 

然后使用连接方法中的var [0],var [1]

and then var[0], var[1] in connection method

这篇关于Keras:具有多个参数的Lambda图层函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆