Skip to main content

matplotlib 中作图时常遇到中文显示乱码的问题,本文探索一下原因,并在文末给出一个通用的解决方案。

import os
import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.FontManager

matplotlib 中有个字体管理类,可以查询、添加、删除字体,包括系统安装、matplotlib 安装、用户自己安装的 3 类字体。

fm = mpl.font_manager.FontManager()
print(len(fm.ttflist))
print(fm.ttflist[0])
print(len(fm.afmlist))
print(fm.afmlist[0])

print(f"manager 找到了 {len(fm.ttflist)} 个 ttf 字体,{len(fm.afmlist)} 个 afm 字体。")
551
FontEntry(fname='/data/kevin/workspace/venv/venv310/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf', name='DejaVu Sans', style='normal', variant='normal', weight=700, stretch='normal', size='scalable')
138
FontEntry(fname='/data/kevin/workspace/venv/venv310/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/afm/putb8a.afm', name='Utopia', style='normal', variant='normal', weight='bold', stretch='normal', size='scalable')
manager 找到了 551 个 ttf 字体,138 个 afm 字体。

wKevin

熟悉 ViT(Vision Transformer)训练视觉模型的基本原理以及其典型方法(如 MAE,Mask Autoencoding)

文中以下面形式引用 ChatGPT 答复:

  • 提问

ChatGPT 的回答


  • ViT 模型出现的时间、paper、提出人

ViT 模型是由 Anish Athalye、Nicholas Carlini 和 David Wagner 等人于 2020 年在《Advances in Neural Information Processing Systems》会议上发布的论文**《An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale》**中提出的。该论文开创性地将 Transformer 应用于计算机视觉领域,提出了一种名为 Vision Transformer(ViT)的模型,用于图像分类等计算机视觉任务。

paper 链接:http://arxiv.org/abs/2010.11929: v1(2020.10), v2(2021.6)

wKevin

我是从 3 月的 ChatGPT 爆发才开始关注大模型的,经过一番手忙脚乱的注册 openai 的 id、使用其 python sdk 后,这才开始转入对 LLM 的观察和学习上来。

2018 年学过 CNN、RNN 后除了在视觉上做了一些产品外,NLP 基本没接触,所以对 Transformer、ViT 都略过了,忽然被 ChatGPT 刺激了一下,才发现 Transformer 除了 NLP,也已经横扫 CV 了,效果超过 NN。那好吧,赶紧补课,把 LLM 学起来。

wKevin

openAI 提供多种 API:

  1. webAPI: 使用 curl、postman、insomnia 等访问。
  2. python API:pip install openai 即可开始使用,源码在 github上开源,文档没有专门的,但 OpenAI 另外一个开源项目 cookbook 中有很多例子可以参考。
  3. Node.js API: npm install openai 即可开始使用,源码在 github上开源,
  4. .NET API: 貌似开发中……

wKevin

Python 3.11 于 2022.10.24 发布正式版 3.11.0,历经 1 年开发和测试:

  • 2021.10 - 2022.04:发布 7 个 a 版本;
  • 2022.05 - 2022.07:发布 5 个 b 版本;
  • 2022.8.8:rc1
  • 2022.9.12:rc2
  • 2022.10.24:3.11.0

重点新特性:

  • Runtime、解释器
    • Faster Cpython
    • bytecode 中添加偏移量对应关系,以便 traceback 中指明出错位置
  • 语言(语法、词法)
    • 新增“异常组”:ExceptionGroup & try...except*
  • 标准库
    • 新增 tomllib 模块
    • asyncio 模块
      • 新增“任务组”:asyncio.TaskGroup
      • Task 新增 cancelling(), uncancel() 方法
    • inspect 模块
      • 新增 getmembers_static()
    • dataclasses 模块
    • typing 模块
      • 增加 typing.TypeVarTuple
      • 增加 typing.Self
      • 增加 typing.LiteralString
      • 增加 typing.TypedDict

本文来导读一下这个刚刚正式揭开面纱的新版本。

wKevin

局域网内多人之间、个人多台电脑之间 —— 如何快速分享、互传 git 管理的代码?

  • 邮件?
  • ftp?
  • scp [-P <port>] <src-file> <user>@<ip>/<dst-file>
  • python -m http.server
  • npm install http-server -g then http-server <root/dir> [-p <port>] ?

上面都行,但文件要逐个传或打包,然后手工合并……不妨用 git 内置的 server 来处理:

$ git daemon