设置指定GPU
Environment Variable Syntax Results
CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen
CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible
CUDA_VISIBLE_DEVICES="0,1" Same as above, quotation marks are optional
CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked
CUDA_VISIBLE_DEVICES="" No GPU will be visible
CUDA_VISIBLE_DEVICES="-1" forbid GPU
在运行代码之前只需在import后加入下列语句即可:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1, 2, 3"
忽略多余信息
类似这种信息有时候会妨碍我们看print:
采用以下代码忽略:
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
3代表的是只有代码出错了才会显示,否则不显示。还有2和1,2代表输出错误和警告,1代表默认设置,显示所有信息。
忽略警告
警告类似这种:
使用以下命令忽略:
import warnings
warnings.filterwarnings('ignore')