0%

参考C++版Determining object color with OpenCV
参考python多边形形状及颜色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# coding=utf-8
# 导入一些python包
from scipy.spatial import distance as dist
from collections import OrderedDict
import numpy as np
import cv2

# 创建一个颜色标签类
class ColorLabeler:
def __init__(self):
# 初始化一个颜色词典
colors = OrderedDict({
"red": (255, 0, 0),
"green": (0, 255, 0),
"blue": (0, 0, 255)})

# 为LAB图像分配空间
self.lab = np.zeros((len(colors), 1, 3), dtype="uint8")
self.colorNames = []

# 循环 遍历颜色词典
for (i, (name, rgb)) in enumerate(colors.items()):
# 进行参数更新
self.lab[i] = rgb
self.colorNames.append(name)

# 进行颜色空间的变换
self.lab = cv2.cvtColor(self.lab, cv2.COLOR_RGB2LAB)

def label(self, image, c):
# 根据轮廓构造一个mask,然后计算mask区域的平均值
mask = np.zeros(image.shape[:2], dtype="uint8")
cv2.drawContours(mask, [c], -1, 255, -1)
mask = cv2.erode(mask, None, iterations=2)
mean = cv2.mean(image, mask=mask)[:3]

# 初始化最小距离
minDist = (np.inf, None)

# 遍历已知的LAB颜色值
for (i, row) in enumerate(self.lab):
# 计算当前l*a*b*颜色值与图像平均值之间的距离
d = dist.euclidean(row[0], mean)

# 如果当前的距离小于最小的距离,则进行变量更新
if d < minDist[0]:
minDist = (d, i)

# 返回最小距离对应的颜色值
return self.colorNames[minDist[1]]

approxPolyDP 多边形逼近

参数1是源图像的某个轮廓;参数2(epsilon)是一个距离值,表示多边形的轮廓接近实际轮廓的程度,值越小,越精确;参数3表示是否闭合。

contourArea 区域面积

double contourArea(InputArray contour, bool oriented = false);

contour,输入的二维点集(轮廓顶点),可以是 vector 或 Mat 类型。
oriented,面向区域标识符。有默认值 false。若为 true,该函数返回一个带符号的面积值,正负取决于轮廓的方向(顺时针还是逆时针)。若为 false,表示以绝对值返回。

arcLength 曲线长度

arcLength 函数用于计算封闭轮廓的周长或曲线的长度。

double arcLength(InputArray curve, bool closed);

curve,输入的二维点集(轮廓顶点),可以是 vector 或 Mat 类型。
closed,用于指示曲线是否封闭。

关于冷启动

启动 WPF 应用程序所需的时间可能存在极大差异。冷启动发生在系统重启后第一次启动应用程序时,或启动应用程序、将其关闭,然后在很长一段时间后再次启动应用程序时。 应用程序启动时,如果所需的页面(代码、静态数据、注册表等)不在 Windows 内存管理器的待机列表中,会发生页面错误。 需要磁盘访问权限,以便将这些页面加载到内存中。

当已将主要公共语言运行时 (CLR) 组件的大多数页面加载到内存中时,则发生热启动,这样可节省宝贵的磁盘访问时间。 这就是为什么再次运行托管的应用程序时,该程序的启动速度更快的原因。

QQs: 冷启动是关于app资源从硬盘到内存的访问权的unefficient

使用初始屏幕增强体验

在app启动就绪之前,渲染一个初始屏幕以安慰等待用户

添加图像资源(BMP、GIF、JPEG、PNG 或 TIFF 格式)到项目,在解决方案资源管理器中打开图像Properties—>Build Action选择SplashScreen

I/O

重新启动后,立即启动 WPF 应用程序,并决定用于显示的时间。 如果应用程序的所有后续启动(热启动)相较之下快很多,则冷启动问题很可能是 I/O 所致。

模块加载

进程资源管理器 Procexp.exe
命令行工具 tasklist /M (显示进程调用的dll)

CSS Modules:CSS Modules将CSS文件的类名作为局部作用域进行处理,以避免全局命名冲突,同时方便了在组件中使用CSS。在React中,您可以使用Webpack和css-loader来加载CSS Modules。

Styled Components:Styled Components是一个CSS样式解决方案,它通过将CSS作为模板字符串嵌入到JavaScript中来直接在组件中定义样式,从而使组件的样式与其它代码逻辑紧密耦合。

CSS-in-JS:CSS-in-JS是使用JavaScript来动态地管理CSS样式的方法。这种方法的好处是可以通过JavaScript组合样式,动态修改样式以及动态响应用户交互。

Jenkins的Master/Slave相当于Server和agent的概念,Master提供web接口让用户来管理Job和Slave,Job可以运行在Master本机或者被分配到Slave上运行。一个Master可以关联多个Slave用来为不同的Job或相同的Job的不同配置来服务。

其显而易见的意义在于使用同一个管理界面调用不同的开发环境

新建节点

在开发环境上安装一个jenkins作为slave
在服务器jenkins上添加slave node: Dashboard > Manage Jenkins > Manage Nodes and Clouds
jenkins slave new node.png
create后进行slave node配置

  • Remote root directory 这个是slave上的jenkins工作目录,job会在此拉取项目并构建
  • Labels 标签 将多个slave标记为一组 用于创建job时选择宜用的slave
    jenkins slave configure.png
    如果需要调用slave机器上应用,可能需要设置环境变量,如使用某路径下的签名软件对构建的程序打签名,路径变量在此处
    调用git拉取代码也要指定路径,否则会在master上看到无法定位到git
    jenkins slave environment.png

保存后会提供 连接命令,需要在slave端执行

使用slave构建

plantuml
preview in vscode:

  • 安装PlantUML插件 PlantUML Previewer插件
  • 配置 PlantUML Server
    按Alt + D打开PlantUML Preview
    generate through Hexo

    流程图

1
2
3
4
5
6
7
8
9
start
if(account cache exist?) then (no)
:return null;
stop
else (yes)
:start silent request;
:get result or exceptions;
:return result;
stop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
start
:declare timer; CancellationTokenSource;
:declare TaskComplationSource;
if(account cache exist?) then (no)
:return null;
stop
else (yes)
:declare silentRequestTask,
input cancellation token;
:parallel execuate silentRequestTask
and TaskComplationSource.Task;
fork
:execuate silentRequestTask;
fork again
:TaskComplationSource.Task;
end fork
:when any task returns;
if(silentRequestTask complete?) then(yes)
:get result or exceptions;
:return result;
:release timer;
:close error dialog if opened;
stop
else (no)
:throw OperationCancelException;
:set isAuthenticationCancel flag to true;
:return null;
stop

时序图

1
2
3
4
5
6
Main -> PubClientApplication
Main -> Timer
Loop loop description
FileDialog -> FileManager: exportFile selectPath
FileManager -> FileManager: CopyFileTo(exportFile, selectPath)
end

思维导图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@startmindmap
*[#409EFF] vue3-auth
**[#79bbff] 登陆认证
***_ 登陆和登出
***_ 用户注册
***_ 用户状态和信息保存
**[#79bbff] 权限鉴定
***_ 用户权限获取
***_ 页面访问权限(菜单权限)
***_ 页面功能权限(按钮权限)
**[#79bbff] 角色管理
***_ 角色新增
***_ 角色修改
***_ 角色删除
***_ 角色绑定权限
***_ 角色绑定维度
**[#79bbff] 用户管理
***_ 用户新增
***_ 用户修改
***_ 用户删除
@endmindmap

神经网络

神经网络15分钟入门

v2-0ced86f32dfa241fc9de10421edbd9b4_720w.webp
如图所示两层神经网络
隐藏层 H = W1X+b1
输出层 Y = W2
H+b2

CNN

Convolutional Neural Networks 卷积神经网络

原理

Stable Diffusion is a latent text-to-image diffusion model. Thanks to a generous compute donation from Stability AI and support from LAION, we were able to train a Latent Diffusion Model on 512x512 images from a subset of the LAION-5B database. Similar to Google’s Imagen, this model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and runs on a GPU with at least 10GB VRAM.

QQs按:Stable Diffusion并非特定程序,而是一种文生图扩散模型,所谓扩散模型大致是将语意或原图,人为加入随机种子并采样,从局部要素发散以匹配学习过的素材特征,从而生成完整图像。Stability AI是推出Stable Diffusion模型的创业公司,LAION(Large-scale Artificial Intelligence Open Network)是一家非营利组织,成员来自世界各地,旨在向公众提供大规模机器学习模型、数据集和相关代码。这里需要指出的是,由于训练素材大多是512x512的小尺寸图像,使用文生图不宜创建太大尺寸,否则会被算法认为是多图拼接,欲生成大尺寸图像应由计算结果通过高清插值插件扩充。

通俗理解扩散模型

大白话讲解扩散模型

webui

Stable Diffusion Webui 为方便调用模型接口制作了图形化的交互界面

env requirement:

  • Python3.10

    models

  • GFPGAN 腾讯开源的人像修复算法
  • VAE (Variational Auto-Encoder 变分自编码器) 修复图片中的某些部分,例如修复人脸图片中的眼睛,或者可以理解为一种滤镜
  • LoRA (Low-Rank Adaptation of Large Language Models) 自然语言处理大模型的低秩(Low-Rank)适应性版本(Adaptation)
  • DeepBooru

LoRA

什么是LoRA模型
自然语言大模型参数庞大(如GPT参数量超过千亿),训练成本太高,因此LoRA采用了一个办法,仅训练低秩矩阵(low rank matrics),使用时将LoRA模型的参数注入(inject)SD模型,从而改变SD模型的生成风格,或者为SD模型添加新的人物/IP。

vas

tags

korean doll

nagetive prompt

paintings, sketchers, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans

troubleshooting

not enough GPU memory

1
2
3
4
5
6
7
8
@echo off

set PYTHON=
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS= --lowvram --no-half --precision full --no-half-vae --opt-sub-quad-attention --opt-split-attention-v1 --autolaunch

call webui.bat

No python at “D:\Program Files\Anaconda3\env\py310\Python.exe”
删除项目env下除Libs外的所有文件 重新执行webui.bat

资源

Stable Diffusion 提示词入门指南
基础模型库:C站 Huggingface 出自魔法学院文章

ComfyUI

recommended Python3.12!
对Stable Diffusion相关工具链的进一步封装,提供工作流编辑。

GitHub

1
git clone https://github.com/comfyanonymous/ComfyUI.git

编辑extramodelpaths.yaml文件以访问Stable Diffusion Webui项目目录下的模型
1
2
3
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126
pip install -r requirements.txt
python main.py --listen=127.0.0.1 --port=8188

其中torch 2.5GB下载较久 源地址 https://download.pytorch.org/whl/cu126/torch-2.6.0%2Bcu126-cp312-cp312-win_amd64.whl 下载后本地安装命令如
1
pip install D:\Download\torch-2.6.0+cu126-cp312-cp312-win_amd64.whl

修改haggingface.io使用国内镜像:D:\Software\Anaconda3\envs\py312\Lib\site-packages\huggingface_hub__init
.py脚本末尾添加
1
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

ComfyUI中文手册

SD3 SD3.5 Flux.1

checkpoints

可见载入我们的大模型的label写的是checkpoints, 即所谓大模型放在model/checkpoints目录, checkpoints常见于RPG游戏被认为是存档点,对于训练复杂的模型,也需要记录阶段性的实验结果,以方便之后的运算基于此进行。
Keras Docs对checkpoints的解释 from《理解checkpoints》

  • The architecture of the model, allowing you to re-create the model
  • The weights of the model
  • The training configuration (loss, optimizer, epochs, and other meta-information)
  • The state of the optimizer, allowing to resume training exactly where you left off.

checkpoints是基础模型的参数定制

controlnet

others

清华大学第六弹:AIGC发展研究3.0

安装Anaconda后 默认只能在conda prompt中使用,若在cmd控制台使用conda命令
需要将Anaconda/Scripts/目录加入环境变量

可以形如下添加源的命令

1
2
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

或编辑用户目录下的.condarc文件 如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
channels:
- defaults
auto_activate_base: true
anaconda_upload: false
show_channel_urls: true
defaults_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

清理环境缓存
1
conda clean -i

显示channels
1
conda show channels

创建指定python版本的虚拟环境

1
conda create -n py310 python=3.10.6

TroubleShooting CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/nux-64

错误原因 D:\Anaconda3\DLLs_ssl.pyd会寻找依赖库OpenSSL DLLs,由于项目目录下未找到,它会去默认目录C:\Windows\System32查找,默认目录下存在该库,但是别的应用安装的,版本不一致,所以出现上述错误。

解决方法:从目录D:\Anaconda3\Library\bin下复制libcrypto-1_1-x64.和libssl-1_1-x64.到D:\Anaconda3\DLLs,这样就会在项目目录下直接查找到该库了。 参考CSDN Blog

激活虚拟环境

列出环境

1
conda env list

激活
1
conda activate py310

TroubleShooting Your shell has not been properly configured to use ‘conda activate’. If using ‘conda activate’ from a batch script, change your invocation to ‘CALL conda.bat activate’.

管理员权限打开命令行 conda init cmd.exe, 同理powershell bash等终端,重启命令行即可执行activate命令

安装、更新、卸载包

1
2
3
4
5
6
conda install pandas
conda update pandas
conda remove pandas

conda env list
conda env remove -n py310 #清除所有