使用Edward时,我的TensorFlow图异常大
我在这里有我从这里修改的代码。基本上我写的是:使用Edward时,我的TensorFlow图异常大,tensorflow,bayesian,Tensorflow,Bayesian,我在这里有我从这里修改的代码。基本上我写的是: #import matplotlib.pyplot as plt import numpy as np import tensorflow as tf #from tensorflow.examples.tutorials.mnist import input_data from edward.models import Categorical, Normal import edward as ed #ed.set_seed(39) import
#import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
#from tensorflow.examples.tutorials.mnist import input_data
from edward.models import Categorical, Normal
import edward as ed
#ed.set_seed(39)
import pandas as pd
import csv
# Use the TensorFlow method to download and/or load the data.
with open ("data_final.csv", "r") as csvfile:
reader1 = csv.reader(csvfile)
data1 = np.array(list(reader1)).astype(np.float)
#mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
N = data1.shape[0] -1 # number of images in a minibatch.
D = 4 # number of features.
K = 4 # number of classes.
# Create a placeholder to hold the data (in minibatches) in a TensorFlow graph.
x = tf.placeholder(tf.float32, [N, D])
# Normal(0,1) priors for the variables. Note that the syntax assumes TensorFlow 1.1.
w = Normal(loc=tf.zeros([D, K]), scale=tf.ones([D, K]))
b = Normal(loc=tf.zeros(K), scale=tf.ones(K))
# Categorical likelihood for classication.
y =tf.matmul(x,w)+b
# Contruct the q(w) and q(b). in this case we assume Normal distributions.
qw = Normal(loc=tf.Variable(tf.random_normal([D, K])),
scale=tf.nn.softplus(tf.Variable(tf.random_normal([D, K]))))
qb = Normal(loc=tf.Variable(tf.random_normal([K])),
scale=tf.nn.softplus(tf.Variable(tf.random_normal([K]))))
# We use a placeholder for the labels in anticipation of the traning data.
y_ph = tf.placeholder(tf.float32, [N, K])
# Define the VI inference technique, ie. minimise the KL divergence between q and p.
inference = ed.KLqp({w: qw, b: qb}, data={y:y_ph})
# Initialse the infernce variables
inference.initialize(n_iter=5000, n_print=100, scale={y: 1})
# We will use an interactive session.
sess = tf.InteractiveSession()
# Initialise all the vairables in the session.
tf.global_variables_initializer().run()
我使用链接的数据来运行代码。在运行代码不到一秒钟的时间后,我发现一个错误(因此我很难相信这真的发生了),它说:
ValueError:GraphDef不能大于2GB
我认为还有其他一些主题和我的一样有错误,但是那些人已经实例化了100万个参数。我有20个参数的订单,所以不确定为什么会出现这个错误 在我的例子中,仍然有一些变量(很可能是一个图)不是从以前的Edward运行中垃圾收集的。垃圾收集/重置控制台修复了该问题 请注意,如果在ipython笔记本中运行,也会发生这种情况。