我想用自定义keras层操纵前一层的激活.下面的图层只是将数字乘以前一层的激活.
class myLayer(Layer):
def __init__(self, **kwargs):
super(myLayer, self).__init__(**kwargs)
def build(self, input_shape):
self.output_dim = input_shape[0][1]
super(myLayer, self).build(input_shape)
def call(self, inputs, **kwargs):
if not isinstance(inputs, list):
raise ValueError('This layer should be called on a list of inputs.')
mainInput = inputs[0]
nInput = inputs[1]
changed = tf.multiply(mainInput,nInput)
forTest = changed
forTrain = inputs[0]
return K.in_train_phase(forTrain, forTest)
def compute_output_shape(self, input_shape):
print(input_shape)
return (input_shape[0][0], self.output_dim)
Run Code Online (Sandbox Code Playgroud)
我正在创建模型
inputTensor = Input((5,))
out = Dense(units, input_shape=(5,),activation='relu')(inputTensor)
n = K.placeholder(shape=(1,))
auxInput = Input(tensor=n)
out = myLayer()([out, auxInput])
out = …Run Code Online (Sandbox Code Playgroud) 就像在 matlab 中一样,Jupyter 中是否有可能在调试模式下运行函数,其中执行在断点处暂停,而在运行模式下函数会忽略断点?在一个简单的例子中,比如
from IPython.core.debugger import set_trace
def debug(y):
x = 10
x = x + y
set_trace()
for i in range(10):
x = x+i
return x
debug(10)
Run Code Online (Sandbox Code Playgroud)
我们是否有可能调用该函数以使 set_trace 被忽略并且函数正常运行?
我想要这个的原因是,在我的函数中,我放置了很多设置跟踪,当我只想在没有跟踪的情况下运行时,我需要注释所有设置跟踪。有更容易的方法吗?