在构建这样的CNN模型时:
# 构建模型的函数
def create_model(features):
with C.layers.default_options(init=C.glorot_uniform(), activation=C.LeakyReLU):
h = features
h = C.layers.Convolution2D(filter_shape=(5,5),
num_filters=8,
strides=(2,2),
pad=True, name='first_conv')(h)
h = C.layers.Convolution2D(filter_shape=(5,5),
num_filters=16,
strides=(2,2),
pad=True, name='second_conv')(h)
r = C.layers.Dense(num_output_classes, activation=None, name='classify')(h)
return r
# 创建模型
z = create_model(x)
# 打印不同组件的输出形状/参数
print("第一个卷积层的输出形状:", z.first_conv.shape)
print("最后一个全连接层的偏置值:", z.classify.b.value)
我遇到了以下错误:
AttributeError Traceback (most recent call last) in () 1 # Create the model —-> 2 z = create_model(x) 3 4 # Print the output shapes / parameters of different components 5 print(“Output Shape of the first convolution layer:”, z.first_conv.shape)
in create_model(features) 2 3 def create_model(features): —-> 4 with C.layers.default_options(init=C.glorot_uniform(), activation=C.LeakyReLU): 5 h = features 6 h = C.layers.Convolution2D(filter_shape=(5,5),
AttributeError: module ‘cntk’ has no attribute ‘LeakyReLU’
我是深度学习的新手,所以可能忽略了一些简单的问题。任何帮助都非常感谢。谢谢!
回答:
尝试使用C.leaky_relu
:
>>> C.leaky_relu([[-1, -0.5, 0, 1, 2]]).eval()array([[-0.01 , -0.005, 0. , 1. , 2. ]], dtype=float32)