猿问

Tensorflow如何使用我的GPU?

所以我正在训练Tensorflow中的NN,同时我正在监视我的GPU负载。

从屏幕截图中可以看到Tensorflow基本上只使用GPU内存,这正常吗?我以为他们利用了我所有的cuda核心来执行一些计算等。


有没有人真的知道这些东西?


提前致谢!


代码来了...


import tensorflow as tf

tf.logging.set_verbosity(tf.logging.INFO)


# ... some file reading here 


def train_input_fn(features, labels, batch_size):

    return tf.estimator.inputs.pandas_input_fn(

        x = features,

        y = labels,

        num_epochs = 1,

        shuffle = True,

        batch_size = batch_size)


def eval_input_fn(features, labels):

    return tf.estimator.inputs.pandas_input_fn(

        x = features,

        y = labels,

        num_epochs = 1,

        shuffle = True)


def pred_input_fn(features):

    return tf.estimator.inputs.pandas_input_fn(

        x = features,

        num_epochs = 1,

        shuffle = False)


model_dir = './DNN_Linear_Combined_Regressor'


file_writer = tf.summary.FileWriter(model_dir)


estimator = tf.estimator.DNNLinearCombinedRegressor(

    model_dir = model_dir,

    linear_feature_columns = wide_columns,

    dnn_feature_columns = deep_columns,

    dnn_optimizer = tf.train.AdamOptimizer(learning_rate=0.001),

    dnn_hidden_units = [64,64,64,8], 

    batch_norm = True,

    dnn_dropout = 0.1

)


train_spec = tf.estimator.TrainSpec(input_fn = train_input_fn(train, y_train, batch_size=5000))

eval_spec = tf.estimator.EvalSpec(input_fn = eval_input_fn(valid, y_valid))


tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)


千巷猫影
浏览 147回答 2
2回答

慕桂英546537

根据此处的TensorFlow文档,默认情况下,TensorFlow将使用与您的GPU内存一样多的内存。另外,您可以通过以下代码检查哪个张量计算正在使用终端中的哪个设备:# Creates an estimator with log_device_placement set to True.sess_config = tf.ConfigProto(log_device_placement=True)run_config = tf.estimator.RunConfig(session_config = sess_config)your_classifier = tf.estimator.Estimator(config=run_config)您会看到以下内容:Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci busid: 0000:05:00.0b: /job:localhost/replica:0/task:0/device:GPU:0a: /job:localhost/replica:0/task:0/device:GPU:0MatMul: /job:localhost/replica:0/task:0/device:GPU:0GPU:0您的默认GPU在哪里。
随时随地看视频慕课网APP

相关分类

Python
我要回答