python - 为什么我会收到“IndentationError:预期有缩进块”
问题描述
我为 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
语句体的任何其他部分一样缩进。
推荐阅读
- javascript - 设置 sprite.visible = false 时,Sprite 拒绝变为不可见
- python - 查找列表中字符串的索引号
- python - Python:替代google无法识别为自动测试软件的selenium Webdriver
- html - 我无法设法覆盖 CSS 中的宽度样式
- postgresql - POSTGRES:无法连接到服务器:连接被拒绝(0x0000274D/10061)
- javascript - 如何设置“最大值”HTML中的标签?
- azure - Azure databricks - 无法使用来自 datalake 存储 gen2 服务的 spark 作业读取 .csv 文件
- java - Log4j2 - 如何将消息和日志级别添加到 keyValuePair 值
- button - html.Button 在 Google colaboratory 中不适用于 JupyterDash
- ruby-on-rails - 如何在 Rails 6 中一次运行所有测试,包括系统测试?