杂记

1.测试 gpu 可用性

1
2
3
4
5
6
import torch
import os
os.environ['CUDA_VISIBLE_DEVICES']='1'
print(torch.version.cuda)
print(torch.__version__)
print(torch.cuda.is_available())
1
2
3
4
5
import tensorflow as tf
import os
os.environ['CUDA_VISIBLE_DEVICES']='0'
import time
tf.test.is_gpu_available()

1
conda install -c conda-forge librosa
1
2
conda install tensorflow-gpu==1.9.0  # 自动带cudatoolkit
# 版本匹配信息:https://www.tensorflow.org/install/source#common_installation_problems

1
CUDA_VISIBLE_DEVICES="1" python train1.py
1
CUDA_VISIBLE_DEVICES="1" python train1.py timit -gpu 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
a = torch.randn(10000, 1000)
b = torch.randn(1000, 2000)

t0 = time.time()
c = torch.matmul(a, b)
t1 = time.time()
print(a.device, t1 - t0, c.norm(2))

device = torch.device('cuda')
a = a.to(device)
b = b.to(device)

t0 = time.time()
c = torch.matmul(a, b)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))

t0 = time.time()
c = torch.matmul(a, b)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))

2.

1
2
3
4
5
6
7
8
9
10
conda -V 
conda info
conda config --get channels
conda config --show
vim ~/.condarc

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/

conda config --remove-key channels

3. 批处理文件改后缀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
import sys

BASE = "/Users/huangshengjie/Desktop/TEST/" # 所有文件的根目录

for root, dirs, files in os.walk(BASE):
if len(files) > 0: # 如果此目录有文件
for file in files: # 遍历此目录下的每一个文件
if file.find(".WAV") != -1: # 如果文件名中包含c2字样
new_file = file.replace(".WAV", ".wav") # 则将其改成c1
try:
os.chdir(root) # 修改之前将当前工作目录切换到文件所在目录,否则os.rename会失败
os.rename(file, new_file) # 调用操作系统的重命名功能
except OSError as e:
print (e)
quit(2)