一、遇到网络连接相关报错
OSError: [Errno 101] Network is unreachable
TypeError: Descriptors cannot not be created directly
1.使用 requests
库来发送网络请求,并通过设置代理来确保所有请求都经过代理服务器
发现行不通
import requests
# 代理服务器的地址和端口
proxy_host = 'your_proxy_host'
proxy_port = 'your_proxy_port'
# 代理认证信息(如果需要)
proxy_username = 'your_proxy_username'
proxy_password = 'your_proxy_password'
# 创建一个代理会话
session = requests.Session()
session.proxies = {
'http': f'http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}',
'https': f'https://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}'
}
# 发送网络请求
response = session.get('https://www.example.com')
# 处理响应
print(response.text)
2.于是找到了包含'http'位置的代码,发现只有一个,它对应着下载一个u2net.pth文件,于是直接在本机上下载,并通过FileZilla放到指定的服务器路径中。
至此,网络问题解决。
二、测试CUDA是否可用
-
检查NVIDIA驱动程序是否正确安装:运行以下命令检查NVIDIA驱动程序是否正确安装并可识别GPU:
nvidia-smi
如果成功运行,将显示与GPU相关的信息。
-
检查CUDA工具包是否安装:运行以下命令检查CUDA是否正确安装:
nvcc --version
如果成功运行,将显示CUDA的版本信息。
-
编写一个简单的CUDA程序进行测试:可以编写一个简单的CUDA程序来验证CUDA是否可用。下面是一个简单的CUDA程序示例:
#include <stdio.h> __global__ void helloCUDA() { printf("Hello CUDA!\n"); } int main() { helloCUDA<<<1, 1>>>(); cudaDeviceSynchronize(); return 0; }
将以上代码保存为
hello.cu
文件,并使用以下命令编译和运行程序:nvcc hello.cu -o hello ./hello
如果输出中显示"Hello CUDA!",则表示CUDA可用。
但上述方法不太准确,可以正常输出但运行代码时会出现
RuntimeError: CUDA error: no kernel image is available for execution on the device
于是又用如下方法测试了一下torch能否正常使用,出现了如下报错,
python
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.zeros(1).cuda()
/home/star/anaconda3/envs/CLIP/lib/python3.7/site-packages/torch/cuda/__init__.py:104: UserWarning:
NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70 sm_75.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/
结果显示是NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.于是查了一下CUDA10.1对应的CUDA capability包括
sm_30、sm_35、sm_50、sm_52、sm_53、sm_60、sm_61、sm_62、sm_70、sm_72和sm_75
所以得出的结论是这个显卡不能用CUDA10.1,只能升版本换回了CUDA11.6,具体方法是
//先删除原先建立的软链接
sudo rm -rf /usr/local/cuda
//将切换的cuda版本软连接到原先的cuda中
sudo ln -s /usr/local/cuda-11.6 /usr/local/cuda
三、修改torch版本后遇到的问题
1.然后安装对应版本的torch和torchvision
torch-1.13.0+cu116-cp37-cp37m-linux_x86_64.whl
torchvision-0.14.0+cu116-cp37-cp37m-linux_x86_64.whl
2.运行.py文件报错
AttributeError: module 'torch.nn.functional' has no attribute '_pad'
3.猜测是在PyTorch 1.7.0中使用的torch.nn.functional._pad
函数书写格式在PyTorch 1.13.0修改了,于是询问chatgpt,发现确实修改,PyTorch 1.13.0改为
torch.nn.functional.pad
至此,.py文件顺利运行