TensorFlow 读取GPU并设置内存自增长
import matplotlib as mpl
import matplotlib. pyplot as plt
% matplotlib inline
import numpy as np
import sklearn
import pandas as pd
import os
import sys
import time
import tensorflow as tf
from tensorflow_core. python. keras. api. _v2 import keras
print ( tf. __version__)
print ( sys. version_info)
for module in mpl, np, pd, sklearn, tf, keras:
print ( module. __name__, module. __version__)
tf. debugging. set_log_device_placement( True )
gpus = tf. config. experimental. list_physical_devices( "GPU" )
for gpu in gpus:
tf. config. experimental. set_memory_growth( gpu, True )
print ( "物理GPU个数:" , len ( gpus) )
logical_gpus = tf. config. experimental. list_logical_devices( "GPU" )
print ( "逻辑GPU个数:" , len ( logical_gpus) )
tensorflow 1.13 GPU + keras 内存自增长
import numpy as np
import keras. backend as K
import tensorflow as tf
config = tf. ConfigProto( )
config. gpu_options. allow_growth = True
K. tensorflow_backend. set_session( tf. Session( config= config) )