搭建python虚拟环境+CUDA+cudnn安装
- 1. 利用conda搭建python3.8环境
* - 搭建结束出现:
- 2. 激活虚拟环境
- 3. 安装需要的包
- 4. CUDA安装
- 5. cuDNN安装(对应版本8.1.1)
- 6. [番外:重新安装了自己的账户安装了python 3.8.8](https://blog.csdn.net/u012080686/article/details/112600252)
- 7. 又又又miniconda 3.8.10
- 8. 2022.09.27重新布置服务器后出现报错问题的解决
1. 利用conda搭建python3.8环境
命令 conda create -n 2021myenv python=3.8
2021myenv 为自定义的虚拟环境名称,3.8为需要的python版本号。
搭建结束出现:
To activate this environment, use conda activate 2021myenv
To deactivate an active environment, use conda deactivate
2. 激活虚拟环境
命令 source activate 2021myenv
即进入虚拟环境:(2021myenv) usr@cygnus:~/python_env$ python
3. 安装需要的包
显示已经安装了什么包:pip list
Successfully installed numpy-1.21.4
Successfully installed joblib-1.1.0
pip install -U git+git://github.com/hypergravity/laspec
Successfully installed laspec-2021.1114.0
Successfully installed torch-1.10.0 typing-extensions-4.0.0
Successfully installed absl-py-1.0.0 astunparse-1.6.3 cachetools-4.2.4 charset-normalizer-2.0.7 flatbuffers-2.0 gast-0.4.0 google-auth-2.3.3 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.41.1 h5py-3.5.0 idna-3.3 keras-2.7.0 keras-preprocessing-1.1.2 libclang-12.0.0 markdown-3.3.4 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.19.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.16.0 tensorboard-2.7.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.7.0 tensorflow-estimator-2.7.0 tensorflow-io-gcs-filesystem-0.22.0 termcolor-1.1.0 urllib3-1.26.7 werkzeug-2.0.2 wrapt-1.13.3
Successfully installed scikit-learn-1.0.1 scipy-1.7.2 sklearn-0.0 threadpoolctl-3.0.0
4. CUDA安装
4.1. cat /proc/version
(Linux查看当前操作系统版本信息)
4.2. cuda 11.2.0下载网址:
https://developer.nvidia.com/cuda-11.2.0-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal
notes: 按照网页的提示信息进行安装。
chmod 755 cuda_11.2.0_460.27.04_linux.run
sh cuda_11.2.0_460.27.04_linux.run
4.3. 注意跳入options进行路径设置。
安装结束提示信息如下:
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /home/liujunhui/cuda_11_2/
Samples: Not Selected
Please make sure that
- PATH includes /home/liujunhui/cuda_11_2/bin
- LD_LIBRARY_PATH includes /home/liujunhui/cuda_11_2/lib64, or, add /home/liujunhui/cuda_11_2/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /home/liujunhui/cuda_11_2/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 460.00 is required for CUDA 11.2 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /tmp/cuda-installer.log
4.4 环境变量的配置
vim .bashrc
source .bashrc
命令行输入 nvcc -V
查看cuda版本,效果如下:
liujunhui@cygnus:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0
5. cuDNN安装(对应版本8.1.1)
参考文章 :https://blog.csdn.net/daydaydreamer/article/details/107172364
5.1 下载
5.2 其实下载了deb文件(图上的文件没有资源)
解压操作
解压后文件存于 cuda 文件夹。
5.3 3 安装配置【替换即可】
cp /home/liujunhui/cuda/include/x86_64-linux-gnu/cudnn*.h /home/liujunhui/cuda_11_2/include/
cp /home/liujunhui/cuda/lib64/x86_64-linux-gnu/libcudnn* /home/liujunhui/cuda_11_2/lib64
chmod 755 ~/cudnn*.h
cat /home/liujunhui/cuda_11_2/include/cudnn_version_v8.h | grep CUDNN_MAJOR -A 2
结果如下:
liujunhui@cygnus:~$ cat /home/liujunhui/cuda_11_2/include/cudnn_version_v8.h | grep CUDNN_MAJOR -A 2
--
参考链接:https://www.pianshen.com/article/99731665661/
https://positive.blog.csdn.net/article/details/118080925
pytorch https://pytorch.org/get-started/cloud-partners/
其他:
查看torch支持的cuda版本:
进入python torch. version torch.version.cuda
所有Cuba下载链接:
https://developer.nvidia.com/cuda-toolkit-archive
cuda 11.2.2
wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_460.32.03_linux.run
wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz
tar -zxf Python-3.8.8.tgz
cd Python-3.8.8
./configure --prefix=/usr/local/python3
./configure --enable-optimizations
make && make install
7. 又又又miniconda 3.8.10
- 下载
到清华镜像源下载miniconda安装程序 https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
挑选合适的下载,例如:
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh
- 安装
bash Miniconda3-py37_4.8.3-Linux-x86_64.sh
遇到Do you accept the license terms? [yes|no]
回车
q键退出阅读license
yes
Miniconda3 will now be installed into this location:
/home/hfy/miniconda3
回车默认
可以选择不初始化,使用conda时需要先source ~/miniconda3/bin/activate
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
启动
source ~/miniconda3/bin/activate
————————————————
参考链接:https://blog.csdn.net/weixin_44387339/article/details/109171325
8. 2022.09.27重新布置服务器后出现报错问题的解决
按照1-5的方法完成程序安装后,出现报错如下:
2022-09-27 10:37:52.398989: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-27 10:37:52.895733: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2022-09-27 10:37:52.908081: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-09-27 10:37:52.908190: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-09-27 10:37:52.978592: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2022-09-27 10:37:55.389742: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-09-27 10:37:55.390086: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-09-27 10:37:55.390125: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
解决方法:
(其实在安装cuda之前,楼主已经安装了tensorflow)解决方法正是重新安装tensorflow,不过是使用conda进行安装,后所有错误消失。
参考文章:https://blog.csdn.net/weixin_41194129/article/details/120215865?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166426390916800192293369%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166426390916800192293369&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-1-120215865-null-null.142v50control,201v3control_1&utm_term=Could%20not%20load%20dynamic%20library%20libnvinfer_plugin.so.7&spm=1018.2226.3001.4187
Original: https://blog.csdn.net/UCAS2019/article/details/121364716
Author: UCAS2019
Title: 搭建python3.8虚拟环境+CUDA 11.2+cudnn 8.1.1安装
相关阅读
Title: 免费将中文视频转换为英文视频并添加中英双语字幕
-
第二步,识别出音频中的中文。这里使用到了百度智能云中的音频文件转写功能。所以首先需要先注册个账号并完成个人认证,百度智能云链接如下:https://cloud.baidu.com/
注意:使用该功能可以通过领取免费资源来获得免费时长,领取的资源有时效和总时长限制,通过https://console.bce.baidu.com/ai/#/ai/speech/overview/index此链接获取:
注册并登录后打开音频文件转写链接:https://cloud.baidu.com/doc/SPEECH/s/Bk5difx04
通过概述的三个接入步骤可以知道主要为: 创建具有音频转写功能的应用→通过该应用的AppID、API Key、Secret Key来获取token→通过token和音频链接创建音频转写任务→查询转写任务的识别结果。
代码如下: -
获取token
import requests
import json
API_key = "你创建应用的API Key"
secret_key = "你创建应用的Secret Key"
access_token_url = f"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API_key}&client_secret={secret_key}"
response = requests.get(access_token_url)
print(response.json())
access_token = response.json()["access_token"]
- 创建音频转写任务(音频可使用百度云对象存储进行音频存储)
post_url = "https://aip.baidubce.com/rpc/2.0/aasr/v1/create"
file_url = "你的音频文件的url"
body = {
"speech_url": file_url,
"format": "mp3",
"pid": 1537,
"rate": 16000,
}
token = {"access_token": access_token}
rep = requests.post(post_url, params=token, data=json.dumps(body))
print(rep.json())
task_id = rep.json()["task_id"]
- 查询转写任务结果
query_url = "https://aip.baidubce.com/rpc/2.0/aasr/v1/query"
query_body = {
"task_ids": [task_id]
}
rep = requests.post(query_url, params=token, data=json.dumps(query_body))
print(json.dumps(rep.json()))
word = rep.json()["tasks_info"]["task_result"]["result"]
- 第四步,根据英文合成英文语音。这里用到有道智云AI开放平台。类似百度智能云平台,这里也需要注册,链接如下:https://ai.youdao.com。首次注册会赠送一些资源的时长,包括语音合成的。
注册并登录后,找到语音合成功能的页面:https://ai.youdao.com/product-tts.s
类似百度平台一样,创建应用并勾选 语音合成:
找到技术文档:产品文档-语音合成TTS服务
把Python3的示例拷下来并修改对应的内容:执行语音合成:
import sys
import uuid
import requests
import hashlib
import time
YOUDAO_URL = 'https://openapi.youdao.com/ttsapi'
APP_KEY = '你的的应用ID'
APP_SECRET = '你的应用密钥'
def encrypt(signStr):
hash_algorithm = hashlib.md5()
hash_algorithm.update(signStr.encode('utf-8'))
return hash_algorithm.hexdigest()
def truncate(q):
if q is None:
return None
size = len(q)
return q if size 20 else q[0:10] + str(size) + q[size - 10:size]
def do_request(data):
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
return requests.post(YOUDAO_URL, data=data, headers=headers)
def connect():
q = "你要合成的英文."
name = "保存的文件名"
data = {}
data['langType'] = 'en'
salt = str(uuid.uuid1())
signStr = APP_KEY + q + salt + APP_SECRET
sign = encrypt(signStr)
data['appKey'] = APP_KEY
data['q'] = q
data['salt'] = salt
data['sign'] = sign
data['speed'] = 1
response = do_request(data)
contentType = response.headers['Content-Type']
if contentType == "audio/mp3":
print("成功")
millis = int(round(time.time() * 1000))
filePath = name + str(millis) + ".mp3"
fo = open(filePath, 'wb')
fo.write(response.content)
fo.close()
else:
print("类型错误", response.content)
if __name__ == '__main__':
connect()
执行完成后将生成mp3文件
Original: https://blog.csdn.net/w77775292/article/details/123079471
Author: leviswong_
Title: 免费将中文视频转换为英文视频并添加中英双语字幕