pytorch - 如何检查一个模块是否嵌套在另一个模块中的某个地方
问题描述
我目前正在使用
def check_is_descendent(root_module: nn.Module, query_module: nn.Module) -> bool:
for m in root_module.modules():
if isinstance(m, query_module):
return True
return False
只是想知道是否有 PyTorch 函数或方法可以做到这一点。
解决方案
推荐阅读
- python - 如何在 pygame 中为矩形分配唯一值?
- node.js - 为什么我在重新加载 Nodejs 服务器时会收到 502?
- java - 读取属性文件时出现 java.nio.file.FileSystemNotFoundException
- javascript - 用 stroke-dasharray 和活动颜色填充划分半圆
- python - 合并列表中随机数的字典
- java - 使用休眠映射 oracle 的类型
- python - 从 SFTP 文件夹中下载最新文件,在 Python 中以昨天的时间戳命名
- python - 如何解决数据集数量少且两个类之间的特征相似/易混淆的分类问题
- python - 使用 imap_tools(或 imaplib),如何通过重复获取整个 imap 数据库来同步 imap 更改而不是轮询?
- javascript - 将每个函数应用于 forEach javascript