Fluent Python 01 数据模型与结构

Fluent Python 01 数据模型与结构

Chapter 1 数据模型

Se1 magic method

数据模型在这里的定义是对python框架的描述,他规范了python构建模块的接口;这些接口对应解释器中对一些特殊句法(常用句法)的激活和使用.本章节的核心就在于对这些特殊句法的理解和使用.
特殊方法带来的一些主要交互场景:

  • 迭代
  • 属性访问
  • 集合类
  • 函数和方法的调用
  • 对象的创建和销毁
  • 字符串的表示形式和格式化
  • 上下文管理模块(with模块)

这些特殊方法的存在实际上,是为了让python的解释器调用,除非我们有大量的元编程,否则我们一般不调用他,通过内置的len等函数进行调用的话,他们的速度更快

下面我们通过最典型的__getitem____len__对其有简单的介绍, 并介绍各个魔术方法的使用场景

Se2 using it and show more

最常用也最典型的magic method 不外乎__getitem____len__;

  • len即对当前对象提供对于通用的len()方法的接口,通常用于查看对象的length or size
  • getitem除了提供obj[index]的索引方式的同时,
    • 他也会对python内置的那些迭代方法提供支持for i in range(b)
    • 对于依托于这些迭代的方法也能够得以支持from random import choice
    • 切片操作

Se2.1 overwrite operator


Python01 数据模型和常用数据结构

Python01 数据模型和常用数据结构

个人的《Python Cookbook》 && 《Fluent Python》阅读笔记。

数据模型(Python结构的通用范式)

(Magic method)dunder method:Python特有的双下划线方法,这些方法能够支持Python进行特殊的调用,实现通用方法在新定义的数据结构上的使用,比如最典型的:

  • __len__()后可以支持len(),获得结构的长度
  • __getitem__()后可以支持data[index]来获取相应的元素,切片,等等数组的操作;

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # 也可以支持类似如下的一些操作
    # 从数据结构中随机选出一个items
    from random import choice
    choice(datas)
    # 也可以支持迭代方法和反迭代方法
    for data in datas:
    ...
    for data in reversed(datas):
    ...
    # 也可以支持sort函数

到这里也就说明了,只要我们在数据结构(class)中定义了相应的dunder method,该class就能支持相应的一系列操作,getitems就可以类比为列表,相应的操作都能够在python解释器下自动的赋予支持。

还有一些好用但不常用的方法:

  • __contain__实现的是in ,当没有实现contain的方法的时候会按照顺序在list中进行搜索
  • __abs__
  • __repr__实现的是输出的format设置,也就是print的时候的输出形式
  • __eq__ 实现的是 == 命令,同时in调用的是eq

下面附上一张特殊方法表:


VsCode's Configuration

VsCode's Configuration

Debug

配置Launch.json 能够帮助我们更好的进行debug的操作,有一些比较特别的文件名和相关编码。

  • ${workspaceFolder} 指代当前运行目录
  • ${file}指代当前文件

找到launch文件并打开,自定义JSON:执行工作文件夹下的main.py进行调试。

1
2
3
4
5
6
7
8
9
{
"name": "experiment",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"console": "integratedTerminal",
"args": ["--data_path","${workspaceFolder}/data",
"--mode","0","--resume","false"]
},

默认 JSON:执行当前文件


Vim 00 Basic Opeation

Vim 00 Basic Opeation

this is the Note record the vimtutor (the basic usage of vim.)
@Aiken 2021

delete command

Most of the command can use NUM to repeat it.
d num command means delete num times with args below:
c means del and change mode to insert:


Vim Configuration 03 Spacevim Setup

Vim Configuration 03 Spacevim Setup

@Aiken 2021 this file is use to record how to config out vim’ by spacevim.
I’ll write this doc with three Parts:

  • Install and envs, Plugins(including the LSP), KeyShort
  • Attention: we have much to do if we want to install some other plugins.
    maybe it not a good way to set the vim.

INSTALL SPACEVIM AND CONFIG IT

Install: SpaceVim via the offical websize:

1
2
The COMMAND is like:
curl -sLf https://spacevim.org/cn/install.sh | bash

SS_OD_SoftTeacher

SS_OD_SoftTeacher

@ Article: ICML from Microsoft & Huazhong Keda
@ Code: Github
@ Noteby: Aikenhong
@ Time: 20210914

Abstrast and Intro

in the session we will using describe the main idea of this article.

这篇文章的重点在于Soft Teacher,也就是用pseudo label做为弱标注,逐步提高伪标签的可靠性。

不同于多阶段的方法,端到端的方法再训练中逐步的提升伪标签的质量从而再去benifit目标检测的质量。
这样E2E的框架主要依赖于两部分技术:

  • soft teacher: 每个未标记边界框的分类损失由教师网络产生的分类分数进行加权
  • box jitter 窗口抖动: 选择可靠的伪框来学习框回归

在目标检测上获得SOTA的效果;

Multi-Stage

在半监督的情况下,关注的主要是基于伪标签的方法,是目前的SOTA,以往的方法采用多阶段的方式。

  1. 使用标记数据训练初始检测器
  2. 未标记数据的伪标记,同时基于伪标签进行重新训练

局限:初始少量标注的局限,初始的检测器的伪标签质量

End to End

Soft Teacher基本思路:对未标记的图像进行标记,然后通过标记的几个伪标签训练检测器.


Vim Configuration 02 Nvim的插件配置

Vim Configuration 02 Nvim的插件配置

@Aikenhong 2021

Vim is a important consistant for editing file in shell. It’s Hightly Customized for Everyone, In this part I’ll Show my personal Vim comfigurations

And I’ll Discuss about the diff between Spacevim & Neovim.

Give a conclusion in advance: Recommand Config the Vim for Yourself

  • You only need to config once, then you should save it in the cloud.
  • You will Know all the Keyshot you setting up, and you can customize it as you want.

image-20211014192437083

Based on neovim

基于NeoVim进行配置,不采用SpaveVim的配置文件,这里需要建议采用最新的测试版的NeoVim(>= 0.5),Stable的NVim已经很久没有更新,对一些新的插件缺乏支持。

Install

Installing Neovim Download NeoVim Package and Install from source

or Install from neovim-ppa Like Following:

1
2
3
sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install neovim

Vim Configuration 01 vim的无插件基础设置

Vim Configuration 01 vim的无插件基础设置

该配置笔记于 20230521 重新整理。默认的 Vimrc 位置为 /usr/share/vim/vimrc,也可以在 vim 界面使用 :echo $MYVIMRC 查看当前的配置文件,默认使用的配置文件地址为 ~/.vimrc

参考文献地址:Good VimRC | Backspace | AutoCmd | VIM配置入门
配置文件地址:AikenDotfile,本文这里只介绍部分配置,一些过于常见的配置等等这里就不再介绍,在 dotfile 中对每行配置均有的细致的注释。

基于 VimScript) 该 blog 主要记录基础 vim 的配置文件编写,旨在使用基础 vim 的时候也能有一个较好的代码编辑体验,同时提供部分 keymap 集成一些简单的功能,方便文档编写时候的格式转换等。这个配置文件在后续配置 nvim 的时候部分配置也会沿用。

Vim 的基础配置

自动检测文件修改,以及对多个文件的 workspace 自动切换

1
2
3
" >>0-1 state detection.
set autoread " when file change outside, we will know
set autochdir " change workspace when we swtich file, when we open multi-file in one session.

鼠标和剪切板功能

设置 vim 对鼠标的支持,支持鼠标选择等

1
2
3
4
5
6
" reference the web get the best setting and use it always
" suppose the mouse operation
" but this function not work well in the weterm, we disable this part for work.
set mouse=a
"set selection=exclusive
"set selectmode=mouse,key

设置和系统同步的剪切板,WSL 下的剪切板设置可以参考下面文章 WSL2 clipboard not shared between Linux and Windows || Reddit - Dive into anything

1
2
3
4
5
6
7
8
9
10
11
12
" set the clipboard
set clipboard+=unnamed

" WSL yank support
let s:clip = '/mnt/c/WINDOWS/system32/clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
endif

设置撤销历史记录

多次编辑同一个文件的时候保持 Undo 的历史记录,便于对同一个文件进行编辑。

1
2
3
4
" >>0-2 keep file history
set undofile " keep the undo history in file.
set undodir=~/.vim/.undo//
set history=1000

通过上述命令启用 undofile 的选项,并设置存储目录,这里需要注意的是,存储目录需要手动创建,undo 的历史记录才能生效。


StyleGAN

StyleGAN

StyleGAN V1

@AikenHong 2020 10.8

《A Style-Based Generator Architecture for Generative Adversarial Networks》

继承的文献工作: ProGAN
参考解读:

Contribution(Problem):

  1. 解纠缠:Mapping Network
  2. Noise Generator
  3. AdaIN before all conv

Structure:

image-20210930135938114

image-20210930161258031

Part1:AdaIN