bug5-os.environ无效

文章目录


由于Tensorflow特有的原因,在打印是会打印一大推无效信息,其中包括INFO,WARNING,ERROR,FATAL
我的如下

2020-10-07 16:11:20.472324: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-10-07 16:11:22.047611: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-10-07 16:11:22.075530: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
2020-10-07 16:11:22.075766: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-10-07 16:11:22.075956: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-10-07 16:11:22.076293: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-10-07 16:11:22.079354: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
2020-10-07 16:11:22.079541: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-10-07 16:11:22.079736: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-10-07 16:11:22.541337: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-07 16:11:22.541480: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2020-10-07 16:11:22.541611: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2020-10-07 16:11:22.541844: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1335 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)

通过在最开始添加,即置于导入Tensorflow前

import os

# 将无效信息屏蔽掉
# 取值有四个:0,1,2,3,分别对应INFO,WARNING,ERROR,FATAL
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

如果仍然无效,一般是未置于最开始

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在给定的代码中,os.environ['CUDA_VISIBLE_DEVICES'] = '1'设置的CUDA可见设备无效的原因是在torch引入之前进行的设定。根据代码结构,startup.py文件中的os.environ['CUDA_VISIBLE_DEVICES'] = '1'应该放在从tools.train中导入main函数之前。这样,当main函数被调用时,CUDA可见设备就已经正确设置了。因此,你需要将os.environ['CUDA_VISIBLE_DEVICES'] = '1'放在from tools.train import main之前。这样,os.environ['CUDA_VISIBLE_DEVICES']的设置就会在main函数被调用时生效。 示例代码可以是这样的: ```python import os os.environ['CUDA_VISIBLE_DEVICES'] = '1' from tools.train import main def startup(gpu=0, config1='xxx', config2='xxx'): args = parse_args(config1, config2) main(args) if __name__ == "__main__": startup(gpu=1) ``` 这样,os.environ['CUDA_VISIBLE_DEVICES'] = '1'就会在main函数执行时生效了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [os.environ[‘CUDA_VISIBLE_DEVICES‘]无效的解决方法](https://blog.csdn.net/asd123pwj/article/details/126442265)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [python os.environ 读取和设置环境变量](https://blog.csdn.net/weixin_39650994/article/details/110971897)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值