【发布时间】:2021-02-22 22:55:25
【问题描述】:
我正在为 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
【问题讨论】:
-
即使是函数中的文档字符串也应该缩进。
标签: python python-3.x conv-neural-network indentation