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分