获取 Keras model.summary() 作为表

2024-06-19

我在 Keras 中创建了相当大的模型,我正在用 LaTeX 写一篇关于它的文章。为了很好地描述 LaTeX 中的 keras 模型,我想用它创建一个 LaTeX 表。我可以手动实现它,但我想知道是否有任何“更好”的方法来实现这一点。

我四处寻找,发现了一些帖子,例如Keras model.summary( ) 有一个不错的输出吗? https://stackoverflow.com/questions/56360776/is-there-a-nice-output-of-keras-model-summary通过绘制图像来解决。然而我想把它作为文本数据(是的,拥有MRE https://stackoverflow.com/help/minimal-reproducible-example:) ),表格看起来更好并且格式也更好。如果有类似的事情,最好的选择是:statsmodels 总结到 Latex https://stackoverflow.com/questions/30011618/statsmodels-summary-to-latex。但是我无法找到任何转换方法model.summary()输出到表格表示。

我在想是否有一种方法可以将其转换为 pandas 数据帧,然后可以使用df.to_latex()。我尝试过这样做model.to_json(),但此函数不会返回有关输出形状的任何信息model.summary()印刷。这是我的尝试:

df = pd.DataFrame(model.to_json())
df2 = pd.DataFrame(df.loc["layers","config"])
#for example select filters, need to do it like this as it is not always contained
filters = ["-" if "filters" not in x else x["filters"] for x in df2.loc[:,"config"]]

The model.to_json()为我的模型返回以下 json:

{"class_name": "Model", "config": {"name": "Discriminator", "layers": [{"name": "input_3", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 256, 256, 1], "dtype": "float32", "sparse": false, "name": "input_3"}, "inbound_nodes": []}, {"name": "input_4", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 256, 256, 1], "dtype": "float32", "sparse": false, "name": "input_4"}, "inbound_nodes": []}, {"name": "concatenate_2", "class_name": "Concatenate", "config": {"name": "concatenate_2", "trainable": true, "dtype": "float32", "axis": -1}, "inbound_nodes": [[["input_3", 0, 0, {}], ["input_4", 0, 0, {}]]]}, {"name": "conv2d_6", "class_name": "Conv2D", "config": {"name": "conv2d_6", "trainable": true, "dtype": "float32", "filters": 8, "kernel_size": [4, 4], "strides": [2, 2], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["concatenate_2", 0, 0, {}]]]}, {"name": "leaky_re_lu_5", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_5", "trainable": true, "dtype": "float32", "alpha": 0.20000000298023224}, "inbound_nodes": [[["conv2d_6", 0, 0, {}]]]}, {"name": "conv2d_7", "class_name": "Conv2D", "config": {"name": "conv2d_7", "trainable": true, "dtype": "float32", "filters": 16, "kernel_size": [4, 4], "strides": [2, 2], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["leaky_re_lu_5", 0, 0, {}]]]}, {"name": "leaky_re_lu_6", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_6", "trainable": true, "dtype": "float32", "alpha": 0.20000000298023224}, "inbound_nodes": [[["conv2d_7", 0, 0, {}]]]}, {"name": "batch_normalization_4", "class_name": "BatchNormalization", "config": {"name": "batch_normalization_4", "trainable": true, "dtype": "float32", "axis": -1, "momentum": 0.8, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"class_name": "Zeros", "config": {}}, "gamma_initializer": {"class_name": "Ones", "config": {}}, "moving_mean_initializer": {"class_name": "Zeros", "config": {}}, "moving_variance_initializer": {"class_name": "Ones", "config": {}}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null}, "inbound_nodes": [[["leaky_re_lu_6", 0, 0, {}]]]}, {"name": "conv2d_8", "class_name": "Conv2D", "config": {"name": "conv2d_8", "trainable": true, "dtype": "float32", "filters": 32, "kernel_size": [4, 4], "strides": [2, 2], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["batch_normalization_4", 0, 0, {}]]]}, {"name": "leaky_re_lu_7", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_7", "trainable": true, "dtype": "float32", "alpha": 0.20000000298023224}, "inbound_nodes": [[["conv2d_8", 0, 0, {}]]]}, {"name": "batch_normalization_5", "class_name": "BatchNormalization", "config": {"name": "batch_normalization_5", "trainable": true, "dtype": "float32", "axis": -1, "momentum": 0.8, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"class_name": "Zeros", "config": {}}, "gamma_initializer": {"class_name": "Ones", "config": {}}, "moving_mean_initializer": {"class_name": "Zeros", "config": {}}, "moving_variance_initializer": {"class_name": "Ones", "config": {}}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null}, "inbound_nodes": [[["leaky_re_lu_7", 0, 0, {}]]]}, {"name": "conv2d_9", "class_name": "Conv2D", "config": {"name": "conv2d_9", "trainable": true, "dtype": "float32", "filters": 64, "kernel_size": [4, 4], "strides": [2, 2], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["batch_normalization_5", 0, 0, {}]]]}, {"name": "leaky_re_lu_8", "class_name": "LeakyReLU", "config": {"name": "leaky_re_lu_8", "trainable": true, "dtype": "float32", "alpha": 0.20000000298023224}, "inbound_nodes": [[["conv2d_9", 0, 0, {}]]]}, {"name": "batch_normalization_6", "class_name": "BatchNormalization", "config": {"name": "batch_normalization_6", "trainable": true, "dtype": "float32", "axis": -1, "momentum": 0.8, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"class_name": "Zeros", "config": {}}, "gamma_initializer": {"class_name": "Ones", "config": {}}, "moving_mean_initializer": {"class_name": "Zeros", "config": {}}, "moving_variance_initializer": {"class_name": "Ones", "config": {}}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null}, "inbound_nodes": [[["leaky_re_lu_8", 0, 0, {}]]]}, {"name": "conv2d_10", "class_name": "Conv2D", "config": {"name": "conv2d_10", "trainable": true, "dtype": "float32", "filters": 1, "kernel_size": [4, 4], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "inbound_nodes": [[["batch_normalization_6", 0, 0, {}]]]}], "input_layers": [["input_3", 0, 0], ["input_4", 0, 0]], "output_layers": [["conv2d_10", 0, 0]]}, "keras_version": "2.3.1", "backend": "tensorflow"}

虽然我想要model.summary()- 类似信息:

Model: "Discriminator"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_3 (InputLayer)            (None, 256, 256, 1)  0                                            
__________________________________________________________________________________________________
input_4 (InputLayer)            (None, 256, 256, 1)  0                                            
...

如果我将摘要输出转换为字符串,也许有一些好方法(Keras model.summary() 对象转字符串 https://stackoverflow.com/q/41665799/3157428)并解析字符串输出?


我编写了一个方法来修改 model.summary() 输出,以便可以将其复制到乳胶并且看起来与原始版本相同(除了行之间的间距有点小)。

def m2tex(model):
    stringlist = []
    model.summary(line_length=70, print_fn=lambda x: stringlist.append(x))
    del stringlist[1:-4:2]
    del stringlist[-1]
    for ix in range(1,len(stringlist)-3):
        tmp = stringlist[ix]
        stringlist[ix] = tmp[0:31]+"& "+tmp[31:59]+"& "+tmp[59:]+"\\\\ \hline"
    stringlist[0] = "Model: test \\\\ \hline"
    stringlist[1] = stringlist[1]+" \hline"
    stringlist[-4] = stringlist[-4]+" \hline"
    stringlist[-3] = stringlist[-3]+" \\\\"
    stringlist[-2] = stringlist[-2]+" \\\\"
    stringlist[-1] = stringlist[-1]+" \\\\ \hline"
    prefix = ["\\begin{table}[]", "\\begin{tabular}{lll}"]
    suffix = ["\end{tabular}", "\caption{Model summary for test.}", "\label{tab:model-summary}" , "\end{table}"]
    stringlist = prefix + stringlist + suffix 
    out_str = " \n".join(stringlist)
    out_str = out_str.replace("_", "\_")
    out_str = out_str.replace("#", "\#")
    print(out_str)

正如你所看到的,它很丑陋,但对我有用。 如果图层名称很长,则可能需要相应地增加 line_length=70 参数和第 8 行中的索引。

输出示例如下:

\begin{table}[] 
\begin{tabular}{lll} 
Model: test \\ \hline 
Layer (type)                   & Output Shape                & Param \#    \\ \hline \hline 
input\_1 (InputLayer)           & [(None, 28, 28, 1)]         & 0          \\ \hline 
dropout (Dropout)              & (None, 28, 28, 1)           & 0          \\ \hline 
conv2d (Conv2D)                & (None, 26, 26, 8)           & 80         \\ \hline 
dropout\_1 (Dropout)            & (None, 26, 26, 8)           & 0          \\ \hline 
conv2d\_1 (Conv2D)              & (None, 24, 24, 8)           & 584        \\ \hline 
dropout\_2 (Dropout)            & (None, 24, 24, 8)           & 0          \\ \hline 
max\_pooling2d (MaxPooling2D)   & (None, 12, 12, 8)           & 0          \\ \hline 
conv2d\_2 (Conv2D)              & (None, 10, 10, 10)          & 730        \\ \hline 
dropout\_3 (Dropout)            & (None, 10, 10, 10)          & 0          \\ \hline 
conv2d\_3 (Conv2D)              & (None, 8, 8, 10)            & 910        \\ \hline 
dropout\_4 (Dropout)            & (None, 8, 8, 10)            & 0          \\ \hline 
max\_pooling2d\_1 (MaxPooling2D) & (None, 4, 4, 10)            & 0          \\ \hline 
flatten (Flatten)              & (None, 160)                 & 0          \\ \hline 
dense (Dense)                  & (None, 16)                  & 2576       \\ \hline 
dropout\_5 (Dropout)            & (None, 16)                  & 0          \\ \hline 
dense\_1 (Dense)                & (None, 10)                  & 170        \\ \hline \hline 
Total params: 5,050 \\ 
Trainable params: 5,050 \\ 
Non-trainable params: 0 \\ \hline 
\end{tabular} 
\caption{Model summary for test.} 
\label{tab:model-summary} 
\end{table} 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取 Keras model.summary() 作为表 的相关文章

  • 利用 Python f 字符串和 Yaml 文件?

    如果我有一个 yaml 文件 其中包含一个带有括号符号 的字符串 与 python f 字符串配合使用 那么如何在此处利用 f 字符串插值 以这个简单的 yaml 文件为例 tmp yaml k1 val1 k2 val2 as well
  • 在 python 中更改函数的 __qualname__ 时会发生什么?

    为了能够pickle嵌套函数 用于多重处理 我用装饰器装饰了嵌套函数 def globalize one func def wrapper one args kwargs return func args kwargs setattr mo
  • Selenium AttributeError:列表对象没有属性 find_element_by_xpath

    我正在尝试从网站上抓取一些营养数据 到目前为止一切似乎都进展顺利 直到我遇到格式略有不同的页面 使用 selenium 和这样的行 返回一个空列表 values browser find elements by class name siz
  • 如何使用类似 KDnuggets 风格的 PDF 绘制比较箱线图

    在经历了解 KDnuggets 文章中的箱线图 https www kdnuggets com 2019 11 understanding boxplots html 我找到了带有概率密度函数的箱线图的详细图 pdf 我正在尝试绘制比较箱线
  • 根据 cron 规范计算下一个计划时间

    在给定当前时间和 cron 规范的情况下 计算事件下一次运行时间的有效方法是什么 我正在寻找 每分钟循环检查是否符合规范 以外的东西 规格示例可能是 每月1日 15日15 01 每小时整点的 10 20 30 40 50 分钟 Python
  • Python setup.py 运行 shell 脚本

    我需要在创建 Python 包时在 sdist 阶段运行我自己的脚本 我写了以下脚本 你知道更好的方法吗 您能否推荐更好的一个或链接到 setuptools 的官方文档 其中已解释了这一时刻 import subprocess import
  • Python 中的文字可以被覆盖吗?

    找不到更好的方式来表达标题 请随时更正 我对 Python 还很陌生 目前正在尝试该语言 我注意到所有内置类型都不能与其他成员一起扩展 例如 我想添加一个each方法到list类型 但那是不可能的 我意识到它是出于效率原因而设计的 并且大多
  • 转换为 Base 64 时,TypeError: 'str' 不支持缓冲区接口 [重复]

    这个问题在这里已经有答案了 im Image open filePath load image self msg str bytearray list im getdata convert image data to string enco
  • 如何设置appache2的WSGI与python 3.7一起使用?

    我使用的是 ubuntu 16 04 并安装了 python 3 7 并使用以下说明将其设置为默认值 无法在 ubuntu 中将默认 python 版本设置为 python3 https stackoverflow com question
  • 限制并行工作的线程数量

    我正在创建一个函数 将文件从本地计算机复制到远程创建线程以并行执行 sftp def copyToServer does copy file given host name and credentials for i in hostsLis
  • 无法保存自定义子类模型

    灵感来自tf keras Model 子类化 https www tensorflow org guide keras model subclassing我创建了自定义模型 我可以训练它并获得成功的结果 但是我无法保存它 我使用 pytho
  • 使用 spaCy 添加多个 EntityRuler(ValueError:'entity_ruler' 已存在于管道中)

    下列link https stackoverflow com questions 57477852 spacy matcher with entities spanning more than a single token展示如何在实体跨越
  • zsh:当我尝试在 venv 中运行应用程序时,中止 python 错误

    我使用以下命令设置 Python 3 6pyenv这样我将来就可以管理多个Python版本 例如3 7和3 8 我没有使用 Homebrew 安装 Python 因为它改变了系统版本 这是我第一次使用zshshell 因为它是 Catali
  • 如何在不重复代码的情况下定义 randint 元组?

    我经常使用 randint 元组来表示颜色值等 a b c randint 0 255 randint 0 255 randint 0 255 当我认为必须有更好的方法时 有吗 使用numpy 1 import numpy as np tu
  • python 中是否可以有受保护的类变量或方法? [复制]

    这个问题在这里已经有答案了 python 中是否可以有受保护的类变量或方法 我可以看一下这种用法的示例吗 最简洁的答案是不 有一些约定和良好的风格允许您指示某人不应修改这些变量或从类外部调用这些方法 但没有办法严格执行这一点 Python
  • 聚类算法采用哪种编程结构

    我正在尝试实现以下 分裂 聚类算法 下面是该算法的简短形式 完整的描述可用here https dl dropboxusercontent com u 540963 diana pdf 从样本 x i 1 n 开始 将其视为由 n 个数据点
  • Python:如何即时生成代码?

    我遇到了一个问题 我必须动态生成程序然后执行它 我们怎样才能做到这一点 您可以使用 eval 函数从字符串执行代码 一个例子是 import math test r dir math eval test Output doc name pa
  • Flask 从线程中删除会话变量

    我尝试实施投票系统 它的工作原理是这样的 如果用户对帖子进行投票 我会在会话变量中记录其临时状态 已投票 已加星标等 如果当前用户在我将结果保存到临时表之前尚未投票 用户可以在 5 分钟内更改投票 5 分钟后 结果将使用线程永久写入数据库
  • 单元测试期间的 Python 日志捕获

    我正在尝试捕获在 python 单元测试过程中创建的日志 并在此处看到了代码 https stackoverflow com a 1049375 576333 https stackoverflow com a 1049375 576333
  • Pandas 如何删除包含所需字符串的行

    我想删除包含所需字符串的所有行 假设我有以下数据框 A B C 1 a x w g n 3 l p j p v 我想删除包含字符串的所有行p 我已经搜索过它 但大多数答案都是基于列名称 就我而言 我不会知道它可以出现在任何列中 输出数据帧应

随机推荐

  • 如何使用 Android 处理在 Google Cardboard 设备中显示立体图像?

    处理的目的是使使用 Java 绘图变得更加容易 Android 的处理功能具有桌面版的强大功能以及来自传感器的信息 将这些东西放在一起 显示立体图像并像 Oculus Rift 或 Google Cardboard 一样在其周围移动不是很容
  • Java 唤醒休眠线程

    我阅读了其他帖子 但没有找到我正在寻找的确切答案 所以我希望有人能给出一些澄清 我有一个将运行一段时间的程序 我有一些在后台运行的线程来执行各种任务 为了简单起见 让我们考虑 3 个线程 ThreadA每 10 秒执行一次任务 其中Thre
  • DispatcherTimer 未按时执行

    我正在使用 c 中的 DispatchTimer 编写一个时钟应用程序 但由于某些原因 我的时钟似乎时不时地跳过 1 秒 例如 52 秒 gt 54 秒 跳过 53 秒 在我看来 计时器并不是每秒都执行一次 DispatcherTimer
  • 为什么需要设置WORKON_HOME环境变量?

    我已经有一段时间没有使用 python 虚拟环境了 但我也安装了虚拟环境包装器 我的问题是 在文档页面中它说要这样做 export WORKON HOME Envs mkdir p WORKON HOME source usr local
  • C 中的变量定义是什么意思[重复]

    这个问题在这里已经有答案了 你们能告诉我 这在 C 中意味着什么吗 define Privileged Data Privileged Data static int dVariable 编译器对变量进行寻址有特殊意义吗 这只是一个宏Pri
  • 如何在 UITableView 中显示零行的表格

    我正在动态地将内容加载到 UITableView 中 如果有数据 表格需要显示数据 如果没有数据 表格应显示普通页面 但在我的应用程序中 表格显示带有两条分隔线的普通页面 我需要删除此分隔线并显示纯白色页面 请建议 任何帮助 将不胜感激 如
  • MongoRepository动态查询

    我有以下问题 假设我有以下模型对象 class Person String id String firstName String lastName Map
  • Laravel 验证规则仅针对字母

    我正在尝试添加验证规则以仅接受信件 我正在使用regex规则 但它仍然不起作用 下面是我的代码 Validate request input this gt validate request name gt required regex p
  • MVC 重定向到没有控制器的视图

    希望应该是一个简单的 我创建了一个通用错误视图 当整个站点的操作方法内发生异常时 我想显示该视图 我创建了一个部分页面 所有导航都位于其中 因此我不需要在此视图上使用控制器 那么如何从控制器内的操作方法重定向到它 像这样的东西 HttpPo
  • TFS 2015:上传自定义流程模板时出现版本错误

    我已经创建了一个基于敏捷流程的定制流程 并且已经完成了本文中提到的所有规定步骤 TFS 2015不会上传自定义流程模板 https stackoverflow com questions 31999557 tfs 2015 wont upl
  • MySQL 错误 1172 - 结果包含多行

    在存储过程中运行查询时 我从 MySQL 收到此错误 错误代码 1172 结果包含多行 我理解错误 我正在做一个SELECT INTO var list 因此查询需要返回单行 当我使用LIMIT 1 or SELECT DISTINCT 错
  • Google 电子表格中的换行符未在 Google 图表中输出

    这段代码工作完美 除了一个小格式问题 我找不到简单的方法来修复 作为数据源的谷歌电子表格在列中有换行符 然而 在表中 它们看起来好像只是由空格格式化的 我尝试在数据表中使用allowHthml选项 将换行符转换为标签 但这会删除所有格式并使
  • Mac OS X 上的 /proc/self/cmdline / GetCommandLine 等效项是什么?

    如何在不使用 argc argv 的情况下访问 Mac OS X 上的命令行 在 Linux 上 我会简单地阅读 proc self cmdline or use GetCommandLine在 Windows 上 但我找不到 Mac OS
  • 如何在 MATLAB 中绘制纹理映射三角形?

    我有一个三角形 u v 图像中的坐标 我想在 3D 坐标处绘制这个三角形 X Y Z 与图像中的三角形进行纹理映射 Here u v X Y Z都是具有三个元素的向量 代表三角形的三个角 我有一个非常丑陋 缓慢且令人不满意的解决方案 其中我
  • 支持通过 OAuth 进行 Facebook/Twitter 身份验证的 CAS 服务器

    我正在寻找一个支持 Facebook Twitter 通过 OAuth 进行单点登录身份验证的 CAS 服务器 我检查过 JASIG CAS 服务器 但它看起来不支持它们 我的 java web 应用程序基于 Spring Security
  • JMeter - 资源字符串未找到错误

    我正在使用 JMeter 3 2 r1790748 并在日志中收到以下消息 2017 08 25 11 41 52 208 WARN o a j u JMeterUtils ERROR Resource string not found m
  • 在 MathJax 中对齐多个方程

    有没有办法使用 MathJax 对齐多个方程 使赤道位于彼此下方 For example 2x 4 6 2x 10 x 5 Use the aligned环境和 symbol e g begin aligned 2x 4 6 2x 10 x
  • 我的机器密钥是自动生成的还是隔离的?

    我正在尝试分享 ASPXAUTHASP NET MVC 4 应用程序 在 IIS 7 5 中 和使用的服务之间的 cookieHttpListener在同一主机上 浏览器正确地向两者呈现 cookie 但我的服务收到System Web H
  • React/Redux bundle.js 太大

    我有一个小型的 React 项目 Webpack生成的bundle js大小为6 3Mb 如何将大小减小到 github webpack config js module exports devtool inline source map
  • 获取 Keras model.summary() 作为表

    我在 Keras 中创建了相当大的模型 我正在用 LaTeX 写一篇关于它的文章 为了很好地描述 LaTeX 中的 keras 模型 我想用它创建一个 LaTeX 表 我可以手动实现它 但我想知道是否有任何 更好 的方法来实现这一点 我四处