Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在不使用后端函数的情况下在keras中编写自定义函数?_Python_Keras - Fatal编程技术网

Python 如何在不使用后端函数的情况下在keras中编写自定义函数?

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使用以下格式:

我想获得keras层的输出,它是图像的张量,将其转换为numpy数组,并在其上应用自定义函数,而不使用后端函数,然后将输出返回到模型。所以应该是这样的:

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”输入一个值