高级TensorFlow编程:GPU计算与第三方库应用
在深度学习领域,GPU计算和高级编程库的使用对于提高模型训练效率和简化开发流程至关重要。本文将介绍GPU计算的相关内容,以及Keras、Pretty Tensor和TFLearn等TensorFlow-based库的特点和应用。
1. GPU计算
GPU最初是为图形应用而开发的专用硬件组件,但后来人们发现它也可用于深度神经网络(DNN)架构中的计算。以下将介绍如何在TensorFlow中进行GPU计算。
1.1 支持软放置的GPU源代码
为了更好地理解,以下是完整的源代码:
import numpy as np
import tensorflow as tf
import datetime
log_device_placement = True
n = 10
A = np.random.rand(10000, 10000).astype('float32')
B = np.random.rand(10000, 10000).astype('float32')
c1 = []
def matpow(M, n):
if n < 1: #Abstract cases where n < 1
return M
else:
return tf.matmul(M, matpow(M, n-1))
with tf.device('/gpu:1'):
a = tf.placeholder(tf.float32, [10000, 10000])
b = tf.
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



