这是我正在运行的示例MNIST代码:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,W) + b)
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding='SAME')
W_conv1 = weight_variable([5, …Run Code Online (Sandbox Code Playgroud) 我是tensorflow和机器学习的新手.最近我正在研究一个模型.我的模型如下,
字符级嵌入向量 - >嵌入查找 - > LSTM1
字级嵌入矢量 - >嵌入查找 - > LSTM2
[LSTM1 + LSTM2] - >单层MLP-> softmax层
[LSTM1 + LSTM2] - >单层MLP-> WGAN鉴别器
他的模型代码
当我正在研究这个模型时,我得到了以下错误.我以为我的批次太大了.因此,我尝试将批量大小从20减少到10,但它不起作用.
ResourceExhaustedError(参见上面的回溯):OOM在分配张量形状时[24760,100] [[节点:字符/ bidirectional_rnn/bw/bw/while/bw/lstm_cell/split = Split [T = DT_FLOAT,num_split = 4,_device] ="/ job:localhost/replica:0/task:0/device:GPU:0"](gradients_2/Add_3/y,chars/bidirectional_rnn/bw/bw/while/bw/lstm_cell/BiasAdd)] [[Node :bi-lstm/bidirectional_rnn/bw/bw/stack/_167 = _Recvclient_terminated = false,recv_device ="/ job:localhost/replica:0/task:0/device:CPU:0",send_device ="/ job:localhost /副本:0 /任务:0 /设备:GPU:0",send_device_incarnation = 1,tensor_name ="edge_636_bi-lstm/bidirectional_rnn/bw/bw/stack",tensor_type = DT_INT32,_device ="/ job:localhost/replica:0 /任务:0 /装置:CPU:0" ]]
张量形状[24760,100]表示2476000*32/8*1024*1024 = 9.44519043 MB内存.我在Titan X(11 GB)GPU上运行代码.怎么可能出错?为什么会发生这种错误?
*额外信息*:LSTM1的大小为100.对于双向LSTM,它变为200.LSTM2的大小为300.对于双向LSTM,它变为600.
*注*:错误发生在32个纪元之后.我的问题是为什么在32个时代之后出现了错误.为什么不在最初的时代.
在我的 tensorflow2.0b 程序中,我确实收到了这样的错误
ResourceExhaustedError: OOM when allocating tensor with shape[727272703] and type int8 on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [Op:TopKV2]
Run Code Online (Sandbox Code Playgroud)
在此程序中的许多基于 GPU 的操作已成功执行后,会出现该错误。
我喜欢释放与这些过去的操作相关的所有 GPU 内存,以避免上述错误。我怎样才能在 tensorflow-2.0b 中做到这一点?如何从我的程序中检查内存使用情况?
我只能使用 tf.session() 找到相关信息,这在 tensorflow2.0 中不再可用