赞
踩
- import keras.backend.tensorflow_backend as KTF
- from tensorflow import set_random_seed
-
- config = tf.ConfigProto(allow_soft_placement=True)
- # 设置最大占有GPU不超过显存的80%
- config.gpu_options.per_process_gpu_memory_fraction = 0.8
- # GPU资源使用率,先少量分配,按需逐步增加
- config.gpu_options.allow_growth = True
-
- sess = tf.Session(config=config)
- KTF.set_session(sess) # 设置sessio
- set_random_seed(2) # 随机数种子
tf2配置
- gpus = tf.config.experimental.list_physical_devices('GPU')
- if gpus:
- try: # 设置 GPU 为增长式占用
- for gpu in gpus:
- tf.config.experimental.set_memory_growth(gpu, True)
- except RuntimeError as e:
- # 打印异常
- print(e)
- tf.random.set_seed(2) # 随机数种子
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。