• mask-rcnn代码解读(七):display(self)函数的解析


    如和将class中定义的变量打印或读取出来,受maskrcnn的config.py的启示,我将对该函数进行解释。

    我将介绍该函数前,需要对一些名词进行解释,如下:

    ①Ipython:ipython是一个python的交互式shell,比默认的python shell好用得多,支持变量自动补全,自动缩进,支持bash shell命令,内置了许多很有用的功能和函数。学习ipython将会让我们以一种更高的效率来使用python。同时它也是利用Python进行科学计算和交互可视化的一个最佳的平台。

    ②dir():函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。如下返回属性变量:

     

    ③.startswith():此函数判断一个文本是否以某个或几个字符开始,结果以True或者False返回。

    text='welcome to qttc blog'
    print text.startswith('w')      # True
    print text.startswith('wel')    # True
    print text.startswith('c')      # False
    print text.startswith('')       # True

    顺道介绍endswith():此函数判断一个文本是否以某个或几个字符结束,结果以True或者False返回。

    text='welcome to qttc blog'
    print text.endswith('g')        # True
    print text.endswith('go')       # False
    print text.endswith('og')       # True
    print text.endswith('')         # True
    print text.endswith('g ')       # False

    ④getattr(self, a):返回一个对象属性值,即变量的值

    def display(self):
    """Display Configuration values."""
    print(" Configurations:")
    for a in dir(self): # dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表
    if not a.startswith("__") and not callable(getattr(self, a)): # getattr() 函数用于返回一个对象属性值
    print("{:30} {}".format(a, getattr(self, a)))
    print(" ")

    在maskrcnn中,执行此代码运行结果为:





  • 相关阅读:
    .net framework缓存遍历
    R语言中统计数据框所有项中的并集
    R语言中在数据框中批量替换指定项
    R语言中 %in%用法
    windows中如何查看端口占用情况、端口是否开启
    R语言中rbind函数和cbind的用法
    linux系统shell实现统计 plink文件基因频率
    linux 系统中实现列转行 及 行转列
    linux系统中向行末添加换行符
    R语言中实现方差和标准差
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/12057510.html
Copyright © 2020-2023  润新知