pytorch调用inception-v3报错:

1
2
3
4
5
6
7
error:
train_model(model, criterion, optimizer, scheduler, num_epochs)
37 outputs = model(inputs)
---> 38 _, preds = torch.max(outputs, 1)
39 loss = criterion(outputs, labels)
TypeError: max() received an invalid combination of arguments - got (InceptionOutputs, int), but expected one of: ...

软件版本:

  • python: 3.7.7
  • pytorch: 1.4.0
  • torchvision: 0.5.0

解决办法:

tensorflow gpu 报错:

1
2
3
4
5
... tensorflow/stream_executor/cuda/cuda_blas.cc:238] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
...
... tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
...
... Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.

软件版本:

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

显卡版本:

  • gpu: RTX 2070
  • cuda: 10.1
  • cudnn: 7.8

解决办法:

You may try limiting your gpu memory usage with set_memory_growth option.
See https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth
Put the following snippet on top of your code and execute again

1
2
3
import tensorflow as tf
gpus= tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(gpus[0], True)

妈妈:悠悠,你长大了有什么梦想?想当医生,老师,加油站工作人员,开挖掘机,还是科学家?

悠悠:我想开挖掘机,妈妈,你小时候的梦想是什么?

妈妈:是当一名教师。

悠悠: 爸爸,你小时候的梦想是什么呢 ?

爸爸: 我想当一名修理工,修摩托车,修汽车。。。

悠悠:那你修了吗 ?

爸爸:没有,我没有实现,我现在也不会修车 。

悠悠:我长大了可以帮你实现你的理想,你们也可以帮我实现我的理想 。

爸爸:你的理想是什么?

悠悠:我的理想是开挖掘机呀。。。妈妈只想当一个老师。

爸爸:当老师也很好啊。

悠悠:当老师可以教学生。

爸爸:额… 那你想开挖掘机去挖什么呢?

悠悠:就是把路哪里不平了,就把他挖一下。

爸爸:哦,我知道了,就是把所有路上不平的地方都给他挖平,让别人可以走!

悠悠:对呀~

爸爸:哇,那你这个理想很伟大呀!

悠悠:对呀~。。。你都不知道你要修什么车。

爸爸:。。。

1. 安装 oh-my-posh, posh-git

可以用scoop安装:

1
2
# scoop bucket add extras
scoop install oh-my-posh

新建、修改配置文件,运行:

1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $PROFILE

加入以下内容:

1
2
3
4
5
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
# 如果PowerShell设置里找不到字体,加上下面这一行
# chcp 65001

ref: https://github.com/JanDeDobbeleer/oh-my-posh/

2. 设置字体

然后把字体设置为更纱黑体,就基本看起来比较舒服了。

也可以用其他的字体,去这里找: https://github.com/ryanoasis/nerd-fonts

但是我并不想用这些字体

阅读全文 »

1. 安装 psreadline

ref: https://github.com/PowerShell/PSReadLine

1.1 从 PowerShellGallery 中安装。

依次安装PowerShellGet, PSReadLine

1
2
Install-Module -Name PowerShellGet -Force
Install-Module PSReadLine

安装完就有历史纪录了,关闭后可以保存历史记录。

1.2 查看已安装的模块

1
Get-InstalledModule

2. 智能提示

2.1 将PSReadLine 升级至V2.1(测试版)

安装完之后没有智能提示,按tab键跳出来的命令都很奇怪。(我安的是稳定版,V2.0.2)

发现测试版就加入了类似 fish 的智能提示,版本是V2.1.0-beta2。

ref: https://github.com/PowerShell/PSReadLine/pull/1496

更新一下PSReadLine,用命令行窗口升级:

1
2
# cmd
powershell -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"

或:

1
Update-Module PSReadLine -Force

然后将 PredictionSourceSource 设为 History

1
2
# powershell
Set-PSReadLineOption -PredictionSource History # 默认是 None

2.2 查看 PSReadLine 的设置

1
Get-PSReadLineOption

2.3 修改配置文件

但是似乎窗口关闭后,就失效了。

需要把设置这一行加到配置文件里就好了,新建、修改配置文件,运行:

1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $PROFILE

就能打开配置文件。

在配置里加入这一句。

1
Set-PSReadLineOption -PredictionSource History  # 默认是 None

Done!

1. 安装 PowerShell 5.0 以上版本

2. 用concfg配置主题

ref: https://github.com/lukesampson/concfg

1
2
3
4
5
6
7
8
9
10
11
scoop install concfg

# 设置主题
# concfg import cmd-default # 暗色调
concfg import google-light # 浅色调

# 列出所有预设主题
concfg presets

# 恢复原始设置
concfg clean

3. 安装字体

阅读全文 »

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
阅读全文 »

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文件,如下图。
阅读全文 »

matplotlib绘制等高线

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()
阅读全文 »

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

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

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

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

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 ...

阅读全文 »