Python【print】常用颜色(复制用)

Python基础教程:print输出带颜色的方法详解 显示方式: 0(默认值)、1(高亮)、22(非粗体)、4(下划线)、24(非下划线)、 5(闪烁)、25(非闪烁)、7(反显)、27(非反显)前景色: 30(黑色)、31(红色)、32(绿色)、 33(黄色)、34(蓝色)、35(洋 红)、36(青色)、37(白色)背景色: 40(黑色)、41(红色)、42(绿色)、 43(黄色)、44(蓝色)、45(洋 红)、46(青色)、47(白色)对于结尾部分,其实也可以省略,但是为了书写规范,建议\033[***开头,\033[0m结尾。 阅读详情

字体颜色

yellow = lambda x: print(f'\033[93m{x}\033[0m')
e = 'color'
# yellow
print('\033[033m', e, '\033[0m', sep='')
# blue
print('\033[034m', e, '\033[0m')
# purple
print('\033[035m  \033[0m')
# 蓝绿色
print('\033[036m %s \033[0m' % e)
# gray
print('\033[037m%r\033[0m' % e)
# red
print('\033[031m{}\033[0m'.format(e))

背景填充

# background
print('\033[0;7m')
print('\033[0m')
# background yellow
'\033[033;7m{}\033[0m'.format(args)

下划线

# underline
print('\033[0;4m')
print('\033[0m')

文本高亮

w = '比赛'
t = '比赛开始没多久就结束了比赛,现在没有比赛'

def replace_color(text, word):
    new_word = '\033[031m' + word + '\033[0m'  # red
    len_w = len(word)
    len_t = len(text)
    for i in range(len_t - len_w, -1, -1):
        if text[i: i + len_w] == word:
            text = text[:i] + new_word + text[i + len_w:]
    return text

print(t)
print(replace_color(t, w))

写模块

def _wrap_colour(colour, *args):
    for a in args:
        print(colour + '{}'.format(a) + '\033[0m')

def blue(*args): _wrap_colour('\033[94m', *args)
def bold(*args): _wrap_colour('\033[1m', *args)
def cyan(*args): _wrap_colour('\033[96m', *args)
def darkcyan(*args): _wrap_colour('\033[36m', *args)
def green(*args): _wrap_colour('\033[92m', *args)
def pink(*args): _wrap_colour('\033[95m', *args)
def purple(*args): _wrap_colour('\033[035m', *args)
def red(*args): _wrap_colour('\033[91m', *args)
def underline(*args): _wrap_colour('\033[4m', *args)
def yellow(*args): _wrap_colour('\033[93m', *args)

if __name__ == '__main__':
    blue('blue')
    bold('bold')
    cyan('cyan')
    darkcyan('darkcyan')
    green('green')
    pink('pink')
    purple('purple')
    red('r', 'e', 'd')
    underline('underline')
    yellow('yellow')

写类

END = '\033[0m'


class Color:
    @staticmethod
    def _wrap_colour(colour, args, prints, sep):
        if prints:
            for a in args:
                print(colour + '{}'.format(a) + END)  # Linux系统会报错
        return colour + sep.join('{}'.format(a) for a in args) + END

    @classmethod
    def background(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[0;7m', args, prints, sep)

    @classmethod
    def background_yellow(cls, *args, prints=False, sep=' '):
        return cls._wrap_colour('\033[033;7m', args, prints, sep)

    @classmethod
    def blue(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[94m', args, prints, sep)

    @classmethod
    def cyan(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[96m', args, prints, sep)

    @classmethod
    def dark_blue(cls, *args, prints=False, sep=' '):
        return cls._wrap_colour('\033[34m', args, prints, sep)

    @classmethod
    def dark_cyan(cls, *args, prints=False, sep=' '):
        return cls._wrap_colour('\033[36m', args, prints, sep)

    @classmethod
    def dark_red(cls, *args, prints=False, sep=' '):
        return cls._wrap_colour('\033[031m', args, prints, sep)

    @classmethod
    def pink(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[95m', args, prints, sep)

    @classmethod
    def red(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[91m', args, prints, sep)

    @classmethod
    def yellow(cls, *args, prints=True, sep=' '):
        return cls._wrap_colour('\033[93m', args, prints, sep)

    @classmethod
    def highlight(cls, text, word):
        highlight_word = cls.background_yellow(word)
        len_w = len(word)
        len_t = len(text)
        for i in range(len_t - len_w, -1, -1):
            if text[i: i + len_w] == word:
                text = text[:i] + highlight_word + text[i + len_w:]
        print(text)

    @classmethod
    def hot(cls, value, half=.5):
        return cls.dark_blue(value) if value < half else cls.dark_red(value)

    @classmethod
    def bar(cls, value, maximum=1, label='') -> str:
        """单柱"""
        length = int(value / maximum * 100)
        if label:
            print(cls.background(label.ljust(length, ' '), prints=False) + cls.hot(value, maximum / 2))
        return '#' * length

    @classmethod
    def bars(cls, values, labels=None) -> None:
        """条形图(https://blog.youkuaiyun.com/Yellow_python/article/details/121498190)"""
        labels = labels or (str(i) for i in range(len(values)))
        maximum = max(values)
        for value, label in zip(values, labels):
            cls.bar(value, maximum, label)


if __name__ == '__main__':
    _c = Color()
    Color.blue('blue')
    Color.cyan('cyan')
    print(_c.dark_blue('dark', 'blue'))
    print(_c.dark_cyan('dark', 'cyan'))
    print(_c.dark_red('dark', 'red'))
    Color.pink('pink')
    Color.red('r', 'e', 'd')
    _c.yellow('yellow')
    _c.background('background', prints=False)
    print(_c.highlight('一片一片又一片', '一片'))
    _c.bar(30, 100, 'boy')
    _c.bar(.7, 1, 'girl')
    print(_c.bar(50, 100), 50)
    _c.bars([1, 2, 3, 4, 5], ['HIVE', 'Flink', 'Spark', 'scikit-learn', 'TensorFlow'])
    print(_c.bar(.5, 1), .5)
    _c.bars([1, 2, 3, 4])

写类(彩印+计时器)

可放到site-packages,方便调用,路径如下
Windows10(base):anaconda\Lib\site-packages
CentOS7(base):miniconda3/lib/python3.9/site-packages
CentOS7(虚拟环境):miniconda3/envs/虚拟环境/lib/python3.*/site-packages

"""
https://blog.youkuaiyun.com/Yellow_python/article/details/80723272
"""
from time import time, strftime, sleep
from datetime import date, timedelta
from platform import system

END = '\033[0m'


class Color:
    @staticmethod
    def _wrap_colour(colour, args, prints, sep) -> str:
        if prints:
            for a in args:
                print(colour + f'{a}' + END)  # Linux上会报错
        return colour + sep.join(f'{a}' for a in args) + END

    @classmethod
    def background(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[0;7m', args, prints, sep)

    @classmethod
    def background_yellow(cls, *args, prints=False, sep=' ') -> str:
        return cls._wrap_colour('\033[033;7m', args, prints, sep)

    @classmethod
    def blue(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[94m', args, prints, sep)

    @classmethod
    def cyan(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[96m', args, prints, sep)

    @classmethod
    def dark_blue(cls, *args, prints=False, sep=' ') -> str:
        return cls._wrap_colour('\033[34m', args, prints, sep)

    @classmethod
    def dark_cyan(cls, *args, prints=False, sep=' ') -> str:
        return cls._wrap_colour('\033[36m', args, prints, sep)

    @classmethod
    def dark_red(cls, *args, prints=False, sep=' ') -> str:
        return cls._wrap_colour('\033[031m', args, prints, sep)

    @classmethod
    def pink(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[95m', args, prints, sep)

    @classmethod
    def red(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[91m', args, prints, sep)

    @classmethod
    def yellow(cls, *args, prints=True, sep=' ') -> str:
        return cls._wrap_colour('\033[93m', args, prints, sep)

    @classmethod
    def highlight(cls, text, word) -> None:
        """文本高亮"""
        highlight_word = cls.background_yellow(word)
        len_w = len(word)
        len_t = len(text)
        for i in range(len_t - len_w, -1, -1):
            if text[i: i + len_w] == word:
                text = text[:i] + highlight_word + text[i + len_w:]
        print(text)

    @classmethod
    def hot(cls, value, half=.5) -> str:
        """小于半数打印蓝色,大于半数打印红色"""
        return cls.dark_blue(value) if value < half else cls.dark_red(value)

    @classmethod
    def bar(cls, value, maximum=1, label='') -> str:
        """单柱"""
        length = int(value / maximum * 100)
        if label:
            print(cls.background(label.ljust(length, ' '), prints=False) + cls.hot(value, maximum / 2))
        return '#' * length

    @classmethod
    def bars(cls, values, labels=None) -> None:
        """条形图:https://blog.youkuaiyun.com/Yellow_python/article/details/121498190"""
        labels = labels or (str(i) for i in range(len(values)))
        maximum = max(values)
        for value, label in zip(values, labels):
            cls.bar(value, maximum, label)


class _Timer:
    def __init__(self):
        self.t = time()

    def __del__(self):
        if self.__str__():
            print('结束时间:' + strftime('%Y-%m-%d %H:%M:%S'))
            print('运行时间:' + str(self))

    def __str__(self):
        t = self.second
        if t < .5:
            return ''
        elif t < 60:
            return '%.2fs' % t
        elif t < 3600:
            return '%.2fmin' % (t / 60)
        else:
            return '%.2fh' % (t / 3600)

    @property
    def second(self) -> float:
        """程序运行秒数"""
        return time() - self.t


_timer = _Timer()


class Timer(Color):
    def __init__(self):
        self.t = _timer
        self.system = system()

    def __str__(self):
        return str(self.t)

    @staticmethod
    def sleep(secs=1) -> None:
        sleep(secs)

    @property
    def second(self) -> float:
        """程序运行秒数"""
        return self.t.second

    @property
    def now(self) -> str:
        return strftime('%Y-%m-%d %H:%M:%S')

    @property
    def today(self) -> str:
        return strftime('%Y-%m-%d')

    @property
    def yesterday(self) -> str:
        y = date.today() - timedelta(days=1)
        return y.strftime('%Y-%m-%d')

    @property
    def last_month(self) -> str:
        """上个月,格式YYYY-MM"""
        today = date.today()
        last_day_of_last_month = today - timedelta(days=today.day)
        return last_day_of_last_month.strftime('%Y-%m')

    def debug(self, text) -> None:
        """仅在Windows上打印"""
        if self.system == 'Windows':
            self.yellow(text)

    def write_log(self, text, prefix='') -> None:
        with open(prefix + self.today + '.log', 'a', encoding='utf-8') as f:
            f.write(f'{text}\n')


if __name__ == '__main__':
    _t = Timer()
    _t.debug(_t.system)
    _t.write_log(_t.system)
    print(_t.t)
    Timer.blue('blue')
    Timer.cyan('cyan')
    print(_t.dark_blue('dark', 'blue'))
    print(_t.dark_cyan('dark', 'cyan'))
    print(_t.dark_red('dark', 'red'))
    Color.pink('pink')
    Color.red('r', 'e', 'd')
    _t.yellow('yellow')
    _t.background('background', prints=False)
    print(_t.now)
    print(_t.today)
    print(_t.yesterday)
    print(_t.last_month)
    _t.highlight('一片一片又一片', '一片')
    _t.bar(30, 100, 'boy')
    _t.bar(.7, 1, 'girl')
    print(_t.bar(50, 100), 50)
    print(_t.bar(.5, 1), .5)
    _t.bars([1, 2, 3, 4, 5], ['HIVE', 'Flink', 'Spark', 'scikit-learn', 'TensorFlow'])
    _t.bars([1, 2, 3, 4])
    print(_t)
    _t.sleep(1)
    print(_t)

Python自动复制Excel指定列:告别复制粘贴失效,实现批量搬数 在Excel日常操作中,复制粘贴失效、无法粘贴、响应缓慢等问题频繁困扰着办公人员,尤其是面对几千行数据跨表搬运时,手工操作不仅效率低下,还容易因剪贴板异常或单元格格式冲突导致数据错乱。Python凭借其轻量级的openpyxl库,绕开系统剪贴板,直接在内存中完成单元格数据的读取与写入,从根本上规避了复制粘贴失灵的风险。本文从Excel复制粘贴的常见痛点切入,介绍如何用Python实现单列、多列乃至批量文件的自动搬运,涵盖环境搭建、核心代码设计、空值过滤、按表头定位列等工程实践技巧,并针对文件路径、数据覆盖、 阅读详情

相关推荐

SolidWorks颜色库扩展:RAL标准色导入与工程应用指南

在工程设计与制造领域,颜色标准化是确保产品视觉一致性和跨部门沟通准确性的关键技术。其核心原理在于通过统一的数字色彩模型(如RGB、Lab)定义颜色,并建立行业公认的编码体系(如RAL色号),从而实现从设计软件到物理生产的色彩无损传递。这项技术的价值在于消除主观描述带来的歧义,保障供应链各环节对色彩的共同理解,对于提升设计专业性、避免生产色差至关重要。其典型应用场景包括工业产品外观设计、工程图纸标注、以及跨企业协作时的色彩规范。本文聚焦于如何在主流三维CAD软件SolidWorks中,通过获取RAL颜色数据、

weixin_33816300的博客 402

python用print输出不同颜色字体

前言 为了使python输出更加醒目,学了下用print输出不同颜色字体 1.格式 # 格式: #   设置颜色开始 :\033[显示方式;前景色;背景色m # 说明: # 前景色 背景色 颜色 # --------------------------------------- # 30 40 黑色 # 31 41 红色 # ...

BH.百行的博客 2万+

别再手动查颜色代码了!用Python Matplotlib的colormaps和named colors快速搞定配色

本文深入探讨了Python Matplotlib在数据可视化中的高级配色技巧,包括命名颜色字典、色彩映射(colormap)和色彩循环的灵活应用。通过RGB和HEX颜色代码的动态调用与预览技术,帮助开发者快速创建专业级配色方案,提升图表的美观度和信息传达效率。

dhc65376的博客 502

python print字体颜色 print背景颜色

# -*- coding:utf-8 -*- print("\033[1;30m 字体颜色:白色\033[0m") print("\033[1;31m 字体颜色:红色\033[0m") print("\033[1;32m 字体颜色:深黄色\033[0m") print("\033[1;33m 字体颜色:浅黄色\033[0m") print("\033[1;34m 字体颜色:蓝色\033[0m")...

沉默的鹏先生 2万+

在python终端中打印颜色的3中方式(python3经典编程案例)

在 Python 中有几种方法可以将彩色文本输出到终端。

数据知道的博客 2万+

python中print输出如何加颜色

1.格式如下: \033[显示方式;字体色;背景色m…\033[0m 看不懂没关系先看后面 2.举例如下: print("\033[1;30;43m 这是一段有颜色的文本\033[0m") 3.效果如下 4.参数说明如下 (1)显示方式 0 终端默认设置 1 高亮显示 4 使用下划线 5 闪烁 7 反白显示 8 不可见 (2)字体色与背景色 字体色 背景色 颜色描述 30 40 黑色 31 41 红色 32 42 绿色 33 43 黃色 34 44 蓝色 35 45 紫红色 36 46 青蓝色 37 47 白色

python print在cmd更换颜色

python相关学习资料:https://edu.51cto.com/video/4645.htmlhttps://edu.51cto.com/video/4102.htmlhttps://edu.51cto.com/video/1158.htmlPython Print在CMD更换颜色 在Python编程中,我们经...

weixin_40590055的博客 307

树莓派作为Modbus服务器:pymodbus配置全记录

手把手教你用树莓派部署Modbus服务器,核心基于pymodbus实现数据通信与设备控制,涵盖配置步骤与常见问题,适合工业自动化场景应用。

weixin_42510201的博客 758

pythonprint颜色_Python中print字体颜色的设置

GS LiveMgr心跳管理类struct LiveMgr { private: int m_nCount; ///< 管理数量 std::vector m_vecChannels; ///< 所 ...Altium designer中级篇-名称决定多边形连接样式在工作中积累了诸多小技巧,可以让工作变的更简单,就比如这个多边形铺铜,与大部分规则的不同之处在于,通过更改多边形的名称,就能达到控制多边...

weixin_39625337的博客 498

Trae CN 使用入门指南

【代码】Trae CN 使用入门指南。

weixin_42551921的博客 8775

多元相关性分析_PAST:最简便易用的统计学分析软件教程目录

欢迎来到PAST的世界!本教程并不是将PAST的所有功能均进行详细介绍,而只是挑选与生物、医学、微生物研究相关的统计学分析内容进行讲述。根据PAST内各项分析的标签分类,将该教程具体设置如下:PAST软件介绍PAST的基本信息数据的输入和修改数据的转换和标准化图像绘制 (Plot标签)点线图和直方图散点图条形图和箱须图饼图堆叠条形图三元相图气泡图单变量统计学分析 (Univariate标...

weixin_39605706的博客 3159

python print美化

我整理的一些关于【CI】的项目学习资料(附讲解~~)和大家一起分享、学习一下:https://edu.51cto.com/surl=iqhDF2Python Print 美化指南 在 Python 编程中,打印输出是与用户交互的基础之一。虽然 Python 的 print() 函数很简单,但有时我们需要更美观、更具可读性...

weixin_37072485的博客 220

模型剪枝实战 | Torch-Pruning 库在YOLOv8上的应用指南

本文详细介绍了如何使用Torch-Pruning库对YOLOv8模型进行结构化剪枝,以实现模型“瘦身”。通过DepGraph(依赖图)技术自动处理层间依赖,确保剪枝安全。文章提供了从环境搭建、核心原理理解到完整剪枝流程的实战指南,并强调了剪枝后的微调与性能评估,帮助开发者在保持精度的同时显著提升模型推理速度。

weixin_29046035的博客 505

Python-print骚操作之不一样的打印风格

字符生成器,拿走直接用:http://www.patorjk.com/software/taag/,输入生成后直接复制就可,简单好用,值得拥有。样式设置之后对后面的所有输出都产生影响,需要取消时进行重置操作。字体颜色和背景颜色设置对照此表。

北冥有鱼的博客 520

机器学习ROC曲线中的阈值thresholds

在ROC曲线上的不同点对应于不同的阈值。根据任务的具体要求,可以选择合适的阈值,以达到平衡召回率和误报率,或者根据具体应用场景调整模型的工作点。,表示样本属于正例的概率。这个概率值可以被截断为二元分类的决策,通过选择一个阈值来决定样本是被分类为正例还是负例。通过改变阈值,可以得到不同的真正例率(TPR)和假正例率(FPR),从而绘制出ROC曲线。总体来说,ROC曲线提供了模型在不同阈值下的性能综合情况,帮助分析模型的分类能力。通常来说,随着阈值的增加,TPR会减小,而FPR会增加。ROC曲线的绘制涉及。

行子的博客 3657

R语言机器学习算法实战系列(五)GBM算法分类器+SHAP值 (Gradient Boosting Machines)

本文介绍了如何使用R语言实现梯度提升机(GBM)模型,并通过乳腺癌数据集进行预测。GBM是一种集成学习算法,通过逐步添加决策树模型来纠正前一个模型的错误,从而提高预测准确性。文章详细阐述了GBM的算法原理,包括初始化模型、计算残差、构建决策树、更新模型等步骤。接着,文章提供了从数据下载、加载R包、数据预处理、数据切割、特征选择、参数设置、模型构建、预测测试数据、模型评估、特征重要性分析、SHAP值解释到模型保存的完整教程。数据集包含569份恶性和良性肿瘤样本的32类指标,通过80%的训练集和20%的测试集进

专注生信领域 1344

手写 Python 进度条:从 print 原理到工程实战

在命令行与批处理脚本中,终端输出是否立即刷新、是否换行,直接影响进度条等交互反馈的实现。理解 stdout 缓冲、回车符 \r 与 flush=True 的作用,是掌握 Python 终端输出控制的基础。通过合理的格式化、刷新频率控制与生成器封装,开发者无需第三方依赖即可打造实时、可读的进度显示,大幅提升长时间任务的可观测性。该技巧广泛应用于数据处理、爬虫、批量文件迁移等场景;若追求更丰富的嵌套与自动适配,则可选用 tqdm,而手写方案在无依赖环境与精细控制上依然不可替代。

weixin_34416754的博客 290

VisionPro - 基础 - 模板匹配技术-Search/PMAlign/PatMax(6)-纹理屏蔽和重叠匹配

Note:对已经有了,1已经训练好的模板,2一组使能的自由度,3一个待测的实时图片,PatMax 就能模板匹配的给出变化的最佳描述。对一些综合的模板,这三个输入值往往是一起影响最后的变换结果信息。例如,如果我们训练了一个圆形的模板,然后搜索一个角度自由度包括一个圆,那么将会有无限个可能的角度满足要求。这些组合的模板匹配,被官方名为:退化系统,a degenerate system的结果被叫做a degenerate result 退化结果4.2 退化系统例子。

山云的专栏 1535

python语句print(type)的输出结果是_Python语句print(type({ }))的输出结果是( )。_学小易找答案...

【其它】【单选题】(5分)不等式 成立是不等式 成立的( ) (5.0分)【多选题】自由变换命令可以对形状工具进行那些编辑?【单选题】( )是不等长编码【判断题】在Python中,可以用else作为变量名【其它】listening comprehension 本周听英语听力教程2的Unit 10【单选题】已知集合A={x〡-2≤x≤3,x∈Z},B={y〡y= -3,x∈A}, C=A∩B,则集合...

weixin_39846664的博客 6353

如何免费快速的部署一个自用免VIP的自动追剧工具!NAS新玩法!豆瓣与迅雷结合,轻松实现自动下载电影自动追剧功能(支持Windows,群晖nas,飞牛nas,软路由,服务器等Docker快速部署)

追剧党狂喜!豆瓣追剧神器,自动添加云盘,自动下载,微信通知,一键搞定!

XiaoqiangClub的博客 4590

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Python基础篇(二):print()函数、input()函数、条件语句if

为了方便理解,以后的用法教程大多都是直接在python代码中展示,教程内容就是注释,可以直接复制代码在自己的编辑软件中运行看执行结果,自己多敲几遍理解更容易,看得多不如敲得多1.print()函数print()函数是输出打印的意思。''' 1.直接打印数值 ''' print(123) print("abc") print(True) ''' 2.直接打印变量 ''' name="mclegen...

mclegend的博客 1835

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

python rich_Python - rich 库讲解

近期我写下了两篇关于日志输出附带高亮颜色的博文:有效的使用工具为的是在我们开发的过程中,能快速定位我们需要关注的内容,也感谢那些第三方库或者插件的开发者们。这篇博文主要是想介绍 rich 这个第三方库的使用,那为何会提到之前写的关于日志输出的呢?原因是 rich 也是颜色输出日志的第三方库。安装python3 -m pip install rich复制代码使用以下测试皆采用 python3 med...

weixin_39966922的博客 2879

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Python基础自学实用笔记 (一):1、print函数 2、列表 3、模块

自学来源:B站小甲鱼零基础学Python,挺好的有兴趣的可以自己花个三四天去看看 #大全菜鸟教程:https://www.runoob.com/python/python-built-in-functions.html 1.print函数 print(1,2,3,sep=” ”,end=” ”) 2.列表 注意项: 以下 a 为一个列表 1.可用逻辑运算符进行比较 2.可用“+”进行列表间的拼接,但尽量使用extend方法 3.可用“”进行元素的多次复制,和字符串的复制相同 4.可用 in 或者 not i

JunfuChang 722

Flet 扩展控件 MaterialPicker:在 Python 中实现 Material 调色板颜色选择

MaterialPicker 是 Flet 官方扩展包 `flet-color-pickers` 提供的 Material 调色板选择器,用于让用户从 Material Design 标准色板中快速挑选主色(primary color)与对应的深浅阴影色(shade),并可选地展示每个色阶的标签。本文基于 [MaterialPicker 官方文档](https://link.gitcode.com

gitblog_00274的博客 725

Detectron2 DensePose query_db 数据集查询与可视化工具完全指南:print 与 show 双模式实战

`query_db` 是 Detectron2 项目中 DensePose 子项目自带的一个命令行工具,用于从 DensePose 数据集中**打印(print)或可视化(show)** 数据集条目:print 模式把选中条目以结构化文本输出到标准输出,show 模式则把标注的边界框、分割掩码、密集对应点等叠加渲染到图像上。本文以 [TOOL_QUERY_DB.md](https://link.g

gitblog_00170的博客 1015

MXNet 神经网络可视化实战:使用 mx.viz.plot_network 与 print_summary 绘制计算图

本文基于 Apache MXNet 仓库中的可视化(Visualization)文档与实现,系统讲解如何用 `mx.viz.plot_network` 将神经网络以计算图(Computation Graph)的形式可视化。计算图由节点(node)与边(edge)组成,能直观展示哪些节点是输入、计算从哪里开始、哪些节点是输出。读完本文,你将掌握 `plot_network` 与 `print_sum

gitblog_00764的博客 456
上一篇: scrapy 简明开发步骤
下一篇: Python 任意字典生成 SQL(insert 语句)
小基基o_O
博客等级 码龄9年 4414粉丝 467原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小基基o_O

您的鼓励是我创作的巨大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值