0. 安装 tflite-runtime

ref: https://tensorflow.google.cn/lite/guide/python

1
pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_armv7l.whl

1. tensorflow官方示例

tensorflow 提供了一个示例, 基于picamera的。

ref: https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/raspberry_pi/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 1. Clone
git clone https://github.com/tensorflow/examples --depth 1

# 2. 进入文件夹
cd examples/lite/examples/object_detection/raspberry_pi

# 文件夹里总共5个文件
# README.md #
# annotation.py # 用于绘制方框、标签
# detect_picamera.py # 主程序
# download.sh # 下载 python 依赖包、已训练的模型
# requirements.txt #


# 3. 下载已训练好的模型
bash download.sh /tmp
# - 下载 python 依赖包: numpy picamera Pillow
# - 下载 coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip, 里面有两个文件:detect.tflite, labelmap.txt,这个label文件有乱码
# - 下载正确的label文件: https://dl.google.com/coral/canned_models/coco_labels.txt

# 4. 运行程序
python3 detect_picamera.py --model /tmp/detect.tflite --labels /tmp/coco_labels.txt

2. 使用 opencv 调用 usb camera

阅读全文 »

问题

在vscode中运行python时,相对路径有点迷惑,总是配置不好,导致在pycharm中可以顺利运行,到vscode里就找不到文件了。

这里修改vscode的设置:将’python的运行目录’ 设置成 ‘python文件当前的目录’。

VSCode 设置

打开 setting.json, 加入:

1
2
3
{
"python.terminal.executeInFileDir": true,
}
阅读全文 »

0.1 树莓派GPIO定义

ref: https://www.raspberrypi.org/documentation/usage/gpio/

0.2 L298N端口定义

名称 符号 备注
电源 VCC 驱动电源,接+5V~+35V
GND 接地
5V 逻辑控制电源,5V 注1
控制端 ENA、ENB 两路 注2
IN1IN2、IN3IN4 高电平有效,接树莓派
输出端 OUT1~OUT4 接电机

注1:当驱动电压过高时(>12V),逻辑控制电源单独接5V电源。 一般悬空即可。
注2:使能端直接跳线与5V连接。这个5V是驱动电源经过78M05模块输出的。

阅读全文 »

1. 硬件

  • 1.1 台达PLC

    • 型号: DVP-40EH00T2
  • 1.2 信号模块

    • 型号: DVP-04AD-H2
  • 1.3 参考文献

    • 台达PLC手册: DELTA_IA-PLC_DVP-EH3_I_TSE_20201022.pdf
    • 台达特殊模块手册: DVP-PLC应用技术手册(特殊模块篇)(326P).pdf
阅读全文 »

1. 硬件

  • 1.1 台达PLC

型号: DVP-40EH00T2

  • 1.2 驱动器

型号: 雷赛 M542

端子名称及说明如下(仅参考,以说明书为准):

名称 符号 备注
24V电源 DC+、DC- 接DC24V电源
电机接口 A+、A-、B+、B- 接电机
使能端子 PUL+、PUL- 5v
脉冲端子 DIR+、DIR- 5V
转向端子 EN+、EN- 5V

注:

  • 使能端这里用不到,可以悬空

  • 脉冲和转向电压要求是5V,接24V需要串一个2K电阻。

  • 1.3 电机
    型号: 57BYG250C

阅读全文 »

dlib安装

目前dlib在pypi中只支持到python36.

python37下的安装网上搜了一下满地都是坑。

终于在github中找到了一个编译好的安装包,记录一下。

下载后直接pip安装即可:

1
pip install dlib-19.17.0-cp37-cp37m-win_amd64.whl

在win10、python3.7.9上使用没有问题。

1. 升级 HEXO

  • 打开package.json, 修改 dependencies 项:
1
"hexo": "^5.0.0",
  • 更新
1
npm update

2. 改变一:通过npm安装主题

阅读全文 »

准备

  • LED灯,3mm无边LED灯 暖白色
  • 背光固件:DC87出厂默认没有背光,需要刷固件,关键词搜”信必成m20双模”

焊灯

DC87的灯位最上面一排没有预留焊锡,其他的预留了焊锡。

可以先加热后直接把led戳进去;或者用吸锡器先把预留的焊锡全部吸掉。

我这里直接加热后戳进去的,个别的需要补一点焊锡防止虚焊。

阅读全文 »

鼠标一直用的地狱狂蛇 Abyssus。

最早是2010款的磨砂版,当时还是蓝色的led灯,3500DPI,底部有两个调节开关。
用了三年多,左键双击了。当时还觉得挺可惜的。

后面买了两个2014款的,一个公司用,一个家用。
这款led灯被改成了绿色,1800DPI,调节开关也被减配了。
用了没多久,家里的鼠标中键就不是很灵了;最近公司的也出现了这个现象。

阅读全文 »

投稿模板要用 els-cas-templates, ctex编译不过去,错误如下:

error: Environment graphicalabstract undefined

原因不用想,肯定是ctex内置的latex(miktex)版本太老了。

1. 试着更新一下miktex。

miktex 官网: https://miktex.org/

最新版是: MiKTeX 20.6 (6/28/2020), 大概230M。

https://miktex.org/download/ctan/systems/win32/miktex/setup/windows-x64/basic-miktex-20.6.29-x64.exe

(最近miktex的版本号也改成了 年.月 的形式,之前是 2.9.x 的格式。)

  • 先把ctex安装目录内的 miktex 文件夹重命名成 miktex-old (保险起见,后面没问题再删)。
  • 安装MiKTeX 20.6到这个ctex默认的目录下。
  • 安装完,打开winedit,应该是能自动找到新的latex的;不行的话,检查一下路径。
阅读全文 »

Pycharm的文本对比功能强大,比VS Code好用的多。

  • 在工程里的文件树上,选中两个文件,然后Ctrl+D(或者右键->Compare)即可。
  • 但是要比较工程以外的文件,或者没打开Pycharm的时候想对比文件时,比较麻烦。毕竟Pycharm又不能秒开。

这里尝试下更方便的用法。

预期功能: 选中两个文件,然后右键“diff with pycharm”。

0. Pycharm CLI

在官网查到Pycharm支持命令行了,支持打开、对比、合并等一些命令。
https://www.jetbrains.com/help/pycharm/working-with-the-ide-features-from-command-line.html

基本用法如下:

1
2
3
4
5
pycharm.bat <file / folder>       # 打开文件或目录
pycharm.bat diff <file> <file> # 对比两个文件
...
...

我们这里只用到 diff 命令。

方法1. 改注册表添加到右键菜单(失败)

先尝试修改注册表,把diff命令添加到右键菜单。

但是注册表里好像不支持把两个或多个文件作为参数传入。

下面的设置,只能分别打开两个pycharm程序,实现不了打开一个pycharm,传入两个文件名

1
2
3
4
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\diff with pycharm\command]
@="C:\\Users\\xxxx\\scoop\\apps\\PyCharm-Professional\\current\\IDE\\bin\\pycharm.bat diff \"%1\""

试了把 %1 改成 %*, %V, 都不行。。。

阅读全文 »

1.安装

可在应用商店安装,也可以scoop安装。

1
scoop install windows-terminal

2. 配置文件

在设置里直接打开的是个人配置:setting.json

按下alt再打开是默认配置文件:default.json

直接默认文件的内容全部拷贝到个人配置里。

简单的改一下powershell的设置,主题、字体、启动目录。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"profiles":
[
{
"guid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}",
"name": "Windows PowerShell",
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"icon": "ms-appx:///ProfileIcons/{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}.png",
"colorScheme": "Campbell",
"antialiasingMode": "grayscale",
"closeOnExit": "graceful",
"cursorShape": "bar",
"fontFace": "JetBrains Mono",
"fontSize": 11,
"hidden": false,
"historySize": 9001,
"padding": "8, 8, 8, 8",
"snapOnInput": true,
"altGrAliasing": true,
"startingDirectory": "%USERPROFILE%",
"useAcrylic": false
},
]

阅读全文 »

1. Jetbrains Mono 字体

Jetbrains 推出了一款新字体: Jetbrains Mono,还不错。

  • 支持连字
  • 不含中文字符
  • 含 powerline 字符

官网的更新比Github慢

2. VSCode 设置

编辑器和终端都可以设置,打开 setting.json, 加入:

1
2
3
4
5
6
{
"editor.fontFamily": "'JetBrains Mono', 'Courier New', monospace",
"editor.fontLigatures": true,

"terminal.integrated.fontFamily": "JetBrains Mono",
}

默认的0是中间带点的0,要改为带斜杆的0,改成下面的:

1
2
3
4
{
"editor.fontLigatures": "'calt' off, 'zero' on", // 关闭连字
"editor.fontLigatures": "'calt' on, 'zero' on", // 开启连字
}

3. Jetbrains Mono Nerd-Fonts 版

https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/JetBrainsMono/

1
2
3
4
5
aria2c https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Regular/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Regular.ttf

aria2c https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Italic/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Italic.ttf

aria2c https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Bold/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Bold.ttf
1
2
3
4
5
aria2c https://ghproxy.net/https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Regular/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Regular.ttf

aria2c https://ghproxy.net/https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Italic/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Italic.ttf

aria2c https://ghproxy.net/https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/JetBrainsMono/Ligatures/Bold/complete/JetBrains%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible%20Bold.ttf

VS Code 编辑器和终端都可以设置,打开 setting.json, 加入:

1
2
3
{
"editor.fontFamily": "'JetBrainsMono Nerd Font Mono', 'Courier New', monospace",
}

1. 硬件

  • 1.1 步进电机

一般4线制:A+、A-、B+、B-

  • 1.2 驱动器

驱动器一般有总线控制和脉冲控制两种方法,这里用的脉冲控制。

端子名称及说明如下(仅参考,以说明书为准):

名称 符号 备注
24V电源 DC+、DC- 接DC24V电源
电机接口 A+、A-、B+、B- 接电机
总线接口 CANH、CANL
脉冲接口 DIR、PUL、GND、EN
  • 1.3 控制器
    这里用YF-19控制器,实验用。
阅读全文 »

(书房里)

妈妈:我睡在这个床上的时候,老是害怕空调会掉下来。

悠悠:你是不是还害怕天花板会掉下来。。。

1. zsh 安装

ref: https://synocommunity.com/

先从套件中心中安装zsh 。

  • 登录DSM,找到 套件中心设置, 将 信任层级 设为 Synology Inc. 和信任的发行者.

  • 套件来源 选项卡中, 增加一项:

  • 返回 套件中心, 左侧可以看到 社群 选项卡, 打开后可以看到里面有 Z shell (with modules), 安装套件.

1
2
3
4
5
6
7
8
# 显示当前 shell 类型
echo $SHELL

# 显示可使用的 shell
cat /etc/shells

# 显示 zsh 安装路径
which zsh

2. oh-my-zsh 安装

ref: https://ohmyz.sh/
ref: https://gitee.com/mirrors/oh-my-zsh.git

  • 需要先安装 git. (在套件中心里有)

  • 用 wget 安装。

    1
    2
    3
    4
    $ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

    # gitee 镜像
    $ sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"
  • 简单配置一下,打开配置文件 nano ~/.zshrc

    1
    2
    3
    4
    5
    # 主题
    ZSH_THEME="ys"

    # 插件
    plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
  • 下载插件

    1
    2
    3
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • 加载配置文件, source ~/.zshrc

阅读全文 »

1. 硬件

  • 1.1 直流电机

一般是8线制:

名称 符号 备注
电机电源 U、V、W
霍尔开关电源 REF+、REF- DC5V, 接控制器或5V电源
霍尔开关信号 HU、HV、HW
  • 1.2 控制器

控制器种类太多,部分端子名称及说明如下(仅参考,以说明书为准):

名称 符号 备注
24V电源 DC+、DC- 接DC24V电源
电机电源 U、V、W
霍尔开关电源 5V+, GND
霍尔开关信号 HU、HV、HW
使能 RUN / EN 低电平启动,断开停止
正、反转 REV / FR 低电平反转,断开正转
调速 SPD / SV 0-5V电压调速
刹车 BK 高电平刹车
转速输出(脉冲) PLS 5V脉冲信号
转速输出(开漏) PG 需在5V与PG间加2K-10K上拉电阻
阅读全文 »

0. 官方文档

Next 介绍了两种方案: mathjax / katex 。

https://theme-next.js.org/docs/third-party-services/math-equations

这里用的是 mathjax。

1. mathjax配置

1.1 正文 Front-matter

1
2
3
4
5
---
title: Hexo中的数学公式
date: 2020-04-25 01:46:39
mathjax: true
---

1.2 Next主题配置

1
2
3
4
5
6
7
8
9
10
11
math:
# Default (true) will load mathjax / katex script on demand.
# That is it only render those page which has `mathjax: true` in Front-matter.
# If you set it to false, it will load mathjax / katex srcipt EVERY PAGE.
per_page: true

# hexo-renderer-pandoc (or hexo-renderer-kramed) required for full MathJax support.
mathjax:
enable: true
# See: https://mhchem.github.io/MathJax-mhchem/
mhchem: false

1.3 安装插件(貌似可以不装,默认的也能用)

先卸载 hexo-renderer-marked, 再安装 hexo-renderer-pandoc

1
2
npm un hexo-renderer-marked
npm i hexo-renderer-pandoc
阅读全文 »

回归问题常用的评估指标

回归问题常用的评估指标包括:MAE, MAPE, MSE, RMSE, R2_Score等。

这些评价指标基本都在 sklearn 包中都封装好了,可直接调用。

安装 sklearn, 完整的名字是 scikit-learn

1
2
pip install -U scikit-learn
# 现在最新版是 V0.22.2.post1
metric formula method
MAE $\frac{1}{n} \sum_{i=1}^n \vert y_i - \hat{y}_i \vert$ sklearn.metrics.mean_absolute_error
MAPE $\frac{1}{n} \sum_{i=1}^n \frac{\vert y_i - \hat{y}_i \vert }{\vert y_i \vert}$ sklearn.metrics.mean_absolute_percentage_error
MSE $\frac{1}{n} \sum_{i=1}^n (y_i - \hat{y}_i)^2$ sklearn.metrics.mean_squared_error
RMSE $\sqrt{\frac{1}{n} \sum_{i=1}^n (y_i - \hat{y}_i)^2}$ sklearn.metrics.mean_squared_error
R2 Score $1 - \dfrac{\sum_{i=1}^n (y_i - \hat{y}_i)^2} {\sum_{i=1}^n (y_i - \bar{y})^2}$ sklearn.metrics.r2_score

注:

  • MAPE 在V0.22.2中还不能直接调用,预计会在V0.23中发布;
  • RMSE 可以调用 mean_squared_error 方法实现, 设置 squared=False 即可;
    • rmse_score = mean_squared_error(y_test, y_pred, squared=False)
阅读全文 »

1. 安装虚拟屏幕

我的树莓派系统是 buster lite 版,没有界面,所以先要安装 xvfb

1
sudo apt install xvfb

2. 安装 firefox

1
2
3
4
sudo apt install firefox-esr

firefox-esr -v # 安装完可以检测一下版本
# Mozilla Firefox 68.7.0esr
阅读全文 »