Python 如何在不使用后端函数的情况下在keras中编写自定义函数?
我想获得keras层的输出,它是图像的张量,将其转换为numpy数组,并在其上应用自定义函数,而不使用后端函数,然后将输出返回到模型。所以应该是这样的:Python 如何在不使用后端函数的情况下在keras中编写自定义函数?,python,keras,Python,Keras,我想获得keras层的输出,它是图像的张量,将其转换为numpy数组,并在其上应用自定义函数,而不使用后端函数,然后将输出返回到模型。所以应该是这样的: def sum(args): # convert args to numpy arrays ??? #calculating sum of all the elements s=np.sum(args) return s 非常感谢您的帮助。您可以使用Tensorflow上的Keras使用以下格式:
def sum(args):
# convert args to numpy arrays
???
#calculating sum of all the elements
s=np.sum(args)
return s
非常感谢您的帮助。您可以使用
Tensorflow
上的Keras
使用以下格式:
x = layers.Conv2D(32, (3, 3), strides=(1, 1),
padding='same', name='conv_1', use_bias=False)(input_image)
x = my_function(x)
x = layers.BatchNormalization(name='norm_1')(x)
它不是那样工作的。我已经试过了。InvalidArgumentError:必须为带有dtype float和shape[?,100][[Node:input_19=placeholder[dtype=DT_float,shape=[?,100],[U device=“/job:localhost/replica:0/任务:0/设备:CPU:0”]()]的占位符张量“input_19”输入一个值