1.获取运行状态

获取群晖运行状态用到的命令如下表:

命令 说明
top 获取CPU使用率
cat /sys/class/hwmon/hwmon0/temp1_input 获取CPU温度
free 获取RAM使用率
df 获取DISK使用率
ifconfig 获取IP地址
  • 1.1 获取CPU温度:
    1
    2
    3
    $ cat /sys/class/hwmon/hwmon0/temp1_input
    36000
    # 实际温度需要除以1000
阅读全文 »

runcat-pyqt5-win V2

之前撸了一个 runcat-pyqt5-win,可以在windows任务栏养猫,用奔跑的猫来显示当前系统资源(CPU)的占用情况。

原来的功能比较简单,这次增加了右键菜单:

  • 可切换图标类型: [cat, mario]
  • 可切换监控类型: [cpu, memory, gpu(nVidia)]
  • 增加了退出按钮

运行效果

阅读全文 »

keras调用tensorborad时报错:
AttributeError: 'Model' object has no attribute '_get_distribution_strategy'

软件版本:

  • python: 3.7.4
  • keras: 2.3.1
  • tensorboard: 2.1.0
  • tensorflow: 2.1.0

解决办法A:

The changes introduced in 06d8f77 are not compatible with standalone Keras (they are compatible with tf.Keras). a keras.Model does not have a _get_distribution_strategy method, which is now assumed for the Tensorboard callback.

  • 直接修改tensorflow/python/keras/callbacks.py文件,如下图。
阅读全文 »

1. 创建需要展示的数据

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
import itertools

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

# === define paras ==================
para_names = ['layer_n', 'activition', 'seed']

layer_n = [1, 2, 3, 4, 5, 6]
activition = ['tanh', 'sigmod', 'relu']
seed = [11, 17, 19]

# 创建 dataframe
df = pd.DataFrame([], columns=para_names)
for values in itertools.product(layer_n, activition, seed):
newline = pd.DataFrame(list(values), index=para_names)
df = df.append(newline.T, ignore_index=True)

# 伪造一些训练结果,方便展示
# activ_2_num = pd.factorize(df['activition'])[0].astype('int') # 激活函数是字符类型,将其映射成整数形
activ_dict = {'tanh': 2, 'sigmod': 4, 'relu': 6} # 也可以直接定义字典,然后replace
df['results'] = df['layer_n'] + df['activition'].replace(activ_dict) + df['seed'] * 0.1 + np.random.random((54,))
df['results'] = df['results'].astype('float') # 转换成浮点类型
print(df.head())

输出:

  layer_n activition seed   results
0       1       tanh   11  4.261361
1       1       tanh   17  4.822595
2       1       tanh   19  4.929088
3       1     sigmod   11  6.698047
4       1     sigmod   17  7.020531
阅读全文 »

悠悠:我又听不到你说话了,我的耳朵又听不到说话了。

妈妈:怎么了?耳朵哪不舒服了?

悠悠:你不说表扬的话,我都听不到。

妈妈:[捂脸][捂脸][捂脸][捂脸]

1.获取运行状态

获取树莓派运行状态用到的命令如下表:

命令 说明
vcgencmd measure_temp 获取CPU温度
top 获取CPU使用率
free 获取RAM使用率
df 获取DISK使用率
ifconfig 获取IP地址
  • 1.1 获取CPU温度:
    1
    2
    3
    $ vcgencmd measure_temp
    temp=40.8C
    # 直接返回温度,只要把 temp= 去掉就行
阅读全文 »

pip3 安装、配置

群晖默认不支持 apt-get 之类的命令,使用 wget 下载 get-pip.py 安装 pip。

1
2
3
4
5
6
7
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'

python3 /tmp/get-pip.py
# 权限不够的话,加上 --user
# python3 /tmp/get-pip.py --user

rm /tmp/get-pip.py

安装之后提示 pip3 的安装目录(一般是 /homes/USERNAME/.local/bin)不在系统的环境变量里。
每次要先跳到安装目录里。

1
2
3
cd .local/bin
./pip3 -V
./pip3 list
阅读全文 »

国内

  • 腾讯 DNS (DNSPod)

    1
    2
    3
    119.29.29.29

    182.254.116.116
  • 114DNS

    1
    2
    3
    114.114.114.114

    114.114.115.115
  • 清华大学 TUNA 协会

    1
    101.6.6.6

国外

  • Google Public DNS

    1
    2
    3
    8.8.8.8

    8.8.4.4
  • Cloudflare DNS

    1
    2
    3
    1.1.1.1

    1.0.0.1

keras,tensorflow设置随机种子,保证结果可复现

ref: https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development

ref: https://tensorflow.google.cn/api_docs/python/tf/random/set_seed

1
2
3
4
5
6
7
8
np.random.seed(42)

# tensorflow V1.x
tf.set_random_seed(1234)

# tensorflow V2.x
# For Tensorflow 2.0 tf.random.set_random_seed(seed) changed to tf.random.set_seed(seed).
tf.random.set_seed(1234)

准备

  • 需要两个 github 仓库:
    • 一个用于发布页面: XXXXXX.github.io
    • 一个用于放源码: hexo-source (可设为隐私仓库)

1. 创建 hexo-source 仓库

  • 在hexo的根目录下( ~/hexo)运行:
    1
    2
    3
    4
    5
    6
    7
    8
    cd hexo

    git init
    git add .
    git commit -m "first commit"
    git remote add origin https://github.com/XXXXXX/hexo-source.git

    git push -u origin master

2. Github Actions 设置

  • 运行 ssh-keygen 生成一对密钥。

    1
    ssh-keygen
  • 打开 XXXXXX.github.io 仓库设置,在 Deploye keys 选项中,添加公钥~/.ssh/id_rsa.pub的内容。

  • 打开 hexo-source 仓库设置,在 Secrets 选项中,新建 repo secret: 名称设为GITHUB_ACTION, 内容为~/.ssh/id_rsa的内容。

阅读全文 »

1. 创建eps图片

  • 从png图片转换: texlive中自带了一个命令: bmeps

    1
    bmeps img.png img.eps
  • 从python创建, 调用matplotlib能直接存为eps格式,可直接保存一份eps的

    1
    plt.savefig('fig1.eps', dpi=300)
  • PPT转为png、eps的方法

    • ppt导出png: 默认dpi较低,需要在注册表改一下dpi=300。
    • ppt导出eps: 先另存为pdf,再用adobe acrobat转为eps。

2. 去除eps图片的空白

阅读全文 »

在 win10 下尝试过的 latex 环境有以下三种:

  • texlive + texstudio
  • ctex (集成 miktex + winedt, 以及中文支持)
  • miktex + texstudio / (vscode + latex workshop)

1. texlive + texstudio

这个是最常用的配置方法,建议新手从这个开始使用。
优点:基本适用于所有的场景(中文除外),一劳永逸;
缺点:默认不支持中文,安装包巨大。

  • texlive 安装: 可以在线安装,也可以离线安装(推荐,安装包3.2G),安装后6G的空间。

  • texstudio 安装:下载安装包(~89M),正常的安装方法即可。

  • texstudio 默认的配置就基本够用,不要乱改。

    • 中文,字体,字号
    • 高级配置:行号、空白等

ps: texstudio的提示、警告、错误信息非常明确,出现问题先看提示。

阅读全文 »

1. scipy中值滤波

使用scipy中的signal.medfilt对数组进行中值滤波。

方法: scipy.signal.medfilt

  • 滤波器的kernel_size必须是奇数
  • 输出数组的size与输入的数组一致
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import scipy.signal as signal
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

n = 51
y = np.sin(np.linspace(0, 10, n)) + np.random.rand(n)
y_med = signal.medfilt(y, kernel_size=5)

plt.figure()
plt.plot(y, 'r--', label='y')
plt.plot(y_med, 'b-.', label='y_med')
plt.legend()
plt.show()

signal.medfilt还可以对矩阵(图像)进行滤波处理,以消除噪音。

ref: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html

阅读全文 »

1. 创建一个神经网络模型

比如用cnn在mnist数据集上训练,关于模型建立和训练的代码这里不写了。。。

在程序开头加入超参数的定义:建议至少包括参数名称、类型、和初始值。

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
#########################
# filename: mnist_cnn.py
#########################

import argparse

# -------parser paras--------------------
parser = argparse.ArgumentParser(description='Trains a simple CNN on MNIST dataset')
parser.add_argument('--layer_n', type=int, default=1)
parser.add_argument('--activition', type=str, default='tanh')
parser.add_argument('--seed', type=int, default=11)

args = parser.parse_args()
print(args.__dict__)

seed = args.seed
layer_n = args.layer_n
activition = args.activition

# --- CNN model ----
# balabala ...

# --- train ----
# balabala ...

阅读全文 »

首先定义超参数的名称和取值范围,
然后调用itertools.product,可以生成所有超参数的排列组合。

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
import itertools
import subprocess

# === define paras ==================
para_names = ['layer_n', 'activition', 'seed']

layer_n = [1, 2, 3, 4, 5, 6]
activition = ['tanh', 'sigmod', 'relu']
seed = [11, 17, 19]

# calc cases number
i = 1
nums = sum(1 for _ in itertools.product(layer_n, activition, seed))
print(f'==== we have {nums} cases in total', '===' * 3)

# === run all case ===========
for values in itertools.product(layer_n, activition, seed):
print(f' *** {i} / {nums} ', '***' * 3)

cmd = f'python mnist_cnn.py'
for p, v in zip(para_names, values):
cmd += f' --{p}={v}'
print(cmd)

# p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
# print(p.stdout.read().decode('utf8'))

i += 1



输出:

==== we have 54 cases in total =========
 *** 1 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=11
 *** 2 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=17
 *** 3 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=19
 *** 4 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=sigmod --seed=11
 *** 5 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=sigmod --seed=17
 *** 6 / 54  *********
 
 ...

 *** 53 / 54  *********
python mnist_cnn.py --layer_n=6 --activition=relu --seed=17
 *** 54 / 54  *********
python mnist_cnn.py --layer_n=6 --activition=relu --seed=19

1. 混淆矩阵(confusion matrix)介绍

在基于深度学习的分类识别领域中,经常采用统计学中的混淆矩阵(confusion matrix)来评价分类器的性能。

它是一种特定的二维矩阵:

  • 列代表预测的类别;行代表实际的类别。
  • 对角线上的值表示预测正确的数量/比例;非对角线元素是预测错误的部分。

混淆矩阵的对角线值越高越好,表明许多正确的预测。

特别是在各分类数据的数量不平衡的情况下,混淆矩阵可以直观的显示分类模型对应各个类别的准确率。

ref: https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html

2. 混淆矩阵示列

  • 数据集: MNIST
  • tensorflow,keras,
  • 神经网络:CNN

依赖:kerasmatplotlibnumpyseaborntensorflowsklearn

阅读全文 »

Jupyter Lab 是 Jupyter Notebook 的下一代升级版,界面相对更友好,功能也更强大,更像一个IDE了。

可以到这个页面 https://jupyter.org/try 试用一下。

0. 安装jupyterlab

1
pip install jupyterlab

1. jupyterlab的三种打开方式(windows)

阅读全文 »

ref: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import numpy as np
import matplotlib.pyplot as plt


x = np.arange(0, 10.0, 0.1)
y = np.arange(0, 10.0, 0.1)
X, Y = np.meshgrid(x, y) # 生成x-y网格图
Z = X**1.5 + Y**1.5

plt.figure()
CS = plt.contour(X, Y, Z, levels=6) # 设置距离
plt.clabel(CS, inline=1, fontsize=10, fmt='%d ℃') # 设置标签
plt.savefig('Temp.png', dpi=300, bbox_inches='tight')
plt.show()
阅读全文 »

准备

  • 需要两个 github 仓库:
    • 一个用于发布页面: shenbo.github.io
    • 一个用于放源码: hexo-source
  • Travis CI 账户 (https://www.travis-ci.org/)

1. 创建 hexo-source 仓库

  • 在hexo的根目录下( ~/hexo)运行:
    1
    2
    3
    4
    5
    6
    7
    8
    cd hexo

    git init
    git add .
    git commit -m "first commit"
    git remote add origin https://github.com/shenbo/hexo-source.git

    git push -u origin master

2. Travis CI 与 Github 设置

2.1 打开 Github 个人设置,创建授权 tokens

2.2 设置 Travis CI 与 Github 绑定

  • 将 Travis 账号 与 Github绑定,激活 hexo-source仓库的开关
  • 打开仓库设置,在 Environment Variables 选项中新建 github_token 项,将刚刚获得的token填进去
  • 其他默认选项不用管
阅读全文 »