本文整理汇总了Python中tensorflow.reset_default_graph方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.reset_default_graph方法的具体用法?Python tensorflow.reset_default_graph怎么用?Python tensorflow.reset_default_graph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.reset_default_graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: network_surgery
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def network_surgery():
tf.reset_default_graph()
inputs = tf.placeholder(tf.float32,
shape=(None, 131072, 4),
name='inputs')
targets = tf.placeholder(tf.float32, shape=(None, 1024, 4229),
name='targets')
targets_na = tf.placeholder(tf.bool, shape=(None, 1024), name="targets_na")
preds_adhoc = tf.placeholder(tf.float32, shape=(None, 960, 4229), name="Placeholder_15")
saver = tf.train.import_meta_graph("model_files/model.tf.meta",
input_map={'Placeholder_15:0': preds_adhoc,
'Placeholder:0': targets_na,
'inputs:0': inputs,
'targets:0': targets
})
ops = tf.get_default_graph().get_operations()
out = tf.train.export_meta_graph(filename='model_files/model.tf-modified.meta', as_text=True)
ops[:15]
示例2: testUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 2
height, width = 224, 224
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = mobilenet_v1.mobilenet_v1(inputs, num_classes)
self.assertTrue(logits.op.name.startswith('MobilenetV1/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Conv2d_13_pointwise']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024])
示例3: testUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 2
height, width = 224, 224
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v2(inputs, num_classes)
self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_5c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024])
示例4: testUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 2
height, width = 299, 299
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v3(inputs, num_classes)
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_7c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048])
示例5: testUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 2
height, width = 224, 224
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v1(inputs, num_classes)
self.assertTrue(logits.op.name.startswith('InceptionV1/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_5c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024])
示例6: predict_dict
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def predict_dict(self, images):
"""
Runs the model with images.
"""
images_ip = self.graph.get_tensor_by_name(u'input_images_1:0')
params = self.graph.get_tensor_by_name(u'add_2:0')
verts = self.graph.get_tensor_by_name(u'Flamenetnormal_2/Add_9:0')
feed_dict = {
images_ip: images,
}
fetch_dict = {
'vertices': verts,
'parameters': params,
}
results = self.sess.run(fetch_dict, feed_dict)
tf.reset_default_graph()
return results
示例7: test_generator_graph
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_generator_graph(self):
tf.set_random_seed(1234)
# Check graph construction for a number of image size/depths and batch
# sizes.
for i, batch_size in zip(xrange(3, 7), xrange(3, 8)):
tf.reset_default_graph()
final_size = 2 ** i
noise = tf.random_normal([batch_size, 64])
image, end_points = dcgan.generator(
noise,
depth=32,
final_size=final_size)
self.assertAllEqual([batch_size, final_size, final_size, 3],
image.shape.as_list())
expected_names = ['deconv%i' % j for j in xrange(1, i)] + ['logits']
self.assertSetEqual(set(expected_names), set(end_points.keys()))
# Check layer depths.
for j in range(1, i):
layer = end_points['deconv%i' % j]
self.assertEqual(32 * 2**(i-j-1), layer.get_shape().as_list()[-1])
示例8: test_discriminator_graph
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_discriminator_graph(self):
# Check graph construction for a number of image size/depths and batch
# sizes.
for i, batch_size in zip(xrange(1, 6), xrange(3, 8)):
tf.reset_default_graph()
img_w = 2 ** i
image = tf.random_uniform([batch_size, img_w, img_w, 3], -1, 1)
output, end_points = dcgan.discriminator(
image,
depth=32)
self.assertAllEqual([batch_size, 1], output.get_shape().as_list())
expected_names = ['conv%i' % j for j in xrange(1, i+1)] + ['logits']
self.assertSetEqual(set(expected_names), set(end_points.keys()))
# Check layer depths.
for j in range(1, i+1):
layer = end_points['conv%i' % j]
self.assertEqual(32 * 2**(j-1), layer.get_shape().as_list()[-1])
示例9: testGlobalPoolUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testGlobalPoolUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 1
height, width = 250, 300
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v2(inputs, num_classes,
global_pool=True)
self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_5c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 10, 1024])
示例10: testGlobalPoolUnknownImageShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def testGlobalPoolUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 1
height, width = 330, 400
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v3(inputs, num_classes,
global_pool=True)
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_7c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 11, 2048])
示例11: test_equalize_sv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_equalize_sv(self):
np.random.seed(1)
tf.reset_default_graph()
tf.set_random_seed(0)
latent_dim = 2
res_ranks, res_biplot = paired_omics(
self.microbes, self.metabolites,
epochs=1000, latent_dim=latent_dim,
min_feature_count=1, learning_rate=0.1,
equalize_biplot=True
)
# make sure the biplot is of the correct dimensions
npt.assert_allclose(
res_biplot.samples.shape,
np.array([self.microbes.shape[0], latent_dim]))
npt.assert_allclose(
res_biplot.features.shape,
np.array([self.metabolites.shape[0], latent_dim]))
# make sure that the biplot has the correct ordering
self.assertGreater(res_biplot.proportion_explained[0],
res_biplot.proportion_explained[1])
self.assertGreater(res_biplot.eigvals[0],
res_biplot.eigvals[1])
示例12: test_residuals
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_residuals(device, dtype):
npdtype = dtype.as_numpy_dtype
M, K, tau = (20, 30), 3, 0.1
U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
noise = np.random.normal(size=M).astype(npdtype)
data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)
lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
lh.init(data=data)
r = lh.residuals(U, data)
assert(r.dtype == dtype)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
npr = sess.run(r)
assert(np.allclose(noise.flatten(), npr, atol=1e-5, rtol=1e-5))
tf.reset_default_graph()
示例13: test_loss
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_loss(device, dtype):
npdtype = dtype.as_numpy_dtype
M, K, tau = (20, 30), 3, 0.1
U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
noise = np.random.normal(size=M).astype(npdtype)
data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)
lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
lh.init(data=data)
loss = lh.loss(U, data)
assert(loss.dtype == dtype)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
nploss = sess.run(loss)
assert(np.allclose(np.sum(noise**2), nploss, atol=1e-5, rtol=1e-5))
tf.reset_default_graph()
示例14: test_llh
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_llh(device, dtype):
npdtype = dtype.as_numpy_dtype
M, K, tau = (20, 30), 3, 0.1
U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
noise = np.random.normal(size=M).astype(npdtype)
data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)
lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
lh.init(data=data)
llh = lh.llh(U, data)
assert(llh.dtype == dtype)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
npllh = sess.run(llh)
llhgt = np.sum(sp.stats.norm(loc=0., scale=1./np.sqrt(tau)).logpdf(noise))
assert(np.allclose(llhgt, npllh, atol=1e-5, rtol=1e-5))
tf.reset_default_graph()
示例15: test_update
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import reset_default_graph [as 别名]
def test_update(device, f, updateType, dtype):
npdtype = dtype.as_numpy_dtype
M, K, tau = (20, 30), 3, 0.1
npU = (np.random.normal(size=(K, M[0])).astype(npdtype),
np.random.normal(size=(K, M[1])).astype(npdtype))
U = (tf.constant(npU[0]), tf.constant(npU[1]))
npnoise = np.random.normal(size=M).astype(npdtype)
npdata = np.dot(npU[0].T, npU[1]) + npnoise
data = tf.constant(npdata, dtype=dtype)
lh = Normal2dLikelihood(M=M, K=K, tau=tau, updateType=updateType)
lh.init(data=data)
lh.noiseDistribution.update = MagicMock()
residuals = tf.ones_like(data)
lh.residuals = MagicMock(return_value=residuals)
lh.update(U, data)
if updateType == UpdateType.ALL:
lh.residuals.assert_called_once()
lh.noiseDistribution.update.assert_called_once()
else:
lh.residuals.assert_not_called()
lh.noiseDistribution.update.assert_not_called()
tf.reset_default_graph()