我为 CNN 定义了一个类,如下所示。然后我执行代码并得到
IndentationError: expected an indented block
。能详细说明一下我错在哪里吗?
class Lenet_like:
"""
Lenet like architecture.
"""
def __init__(self, width, depth, drop, n_classes):
"""
Architecture settings.
Arguments:
- width: int, first layer number of convolution filters.
- depth: int, number of convolution layer in the network.
- drop: float, dropout rate.
- n_classes: int, number of classes in the dataset.
"""
self.width = width
self.depth = depth
self.drop = drop
self.n_classes = n_classes
def __call__(self, X):
"""
Call classifier layers on the inputs.
"""
for k in range(self.depth):
# Apply successive convolutions to the input !
# Use the functional API to do so
X = Conv2D(filters = self.width / (2 ** k), activation = 'relu')(X)
X = MaxPooling2D(strides = (2, 2))(X)
X = Dropout(self.drop)(X)
# Perceptron
# This is the classification head of the classifier
X = Flatten(X)
Y = Dense(units = self.n_classes, activation = 'softmax')(X)
return Y
错误信息:
File "<ipython-input-1-b8f76520d2cf>", line 16
"""
^
IndentationError: expected an indented block
从解析器的角度来看,文档字符串不是注释。这是一个普通的表达式语句,因此必须像
def
语句主体的任何其他部分一样缩进。