想请教大佬们,tensorflow2.1里怎么自定义一个激活
tensorflow吧
全部回复
仅看楼主
level 1
想请教大佬们,tensorflow2.1里怎么自定义一个激活函数啊?有偿也行,求指点[泪]
2020年04月18日 14点04分 1
level 1
import tensorflow as tf
import numpy as np
#自定义的激活函数
def my_relu(x):
x = np.maximum(x,0)
return x
x = tf.ones([25,125])
class CNN(tf.keras.Model):
def __init__(self):
super().__init__()
self.flatten = tf.keras.layers.Flatten()
#使用自定义激活函数
self.dense1 = tf.keras.layers.Dense(1,activation=my_relu)
def call(self,inputs):
x = self.flatten(inputs)
x = self.dense1(x)
return x
cnn = CNN()
y = cnn(x)
print(y)
2021年03月11日 08点03分 2
1