本文整理汇总了Python中tensorflow.all_variables函数的典型用法代码示例。如果您正苦于以下问题:Python all_variables函数的具体用法?Python all_variables怎么用?Python all_variables使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了all_variables函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: reset_module
def reset_module(self, module):
temp = set(tf.all_variables())
module.backward(module.loss)
self.sess.run(tf.initialize_variables(set(tf.all_variables()) - temp))
开发者ID:bentzinir,项目名称:Buffe,代码行数:7,代码来源:driver.py
示例2: __init__
def __init__(self, network_architecture, transfer_fct=tf.nn.softplus,
learning_rate=0.001, batch_size=100,load_model = False,checkpoint_folder = './vae_checkpoints'):
self.network_architecture = network_architecture
self.transfer_fct = transfer_fct
self.learning_rate = learning_rate
self.batch_size = batch_size
# tf Graph input
self.x = tf.placeholder(tf.float32, [None, network_architecture["n_input"]])
# Create autoencoder network
# Initializing the tensor flow variables
# Launch the session
self.sess = tf.InteractiveSession()
#self.saver = tf.train.Saver(tf.all_variables())
self._create_network()
# Define loss function based variational upper-bound and
# corresponding optimizer
self._create_loss_optimizer()
print len(tf.all_variables())
self.saver = tf.train.Saver(var_list=tf.all_variables())
if load_model == False:
init = tf.initialize_all_variables()
self.sess.run(init)
else:
ckpt = tf.train.get_checkpoint_state(checkpoint_folder)
self.saver.restore(self.sess, ckpt.model_checkpoint_path)
print "Loaded model:",ckpt.model_checkpoint_path
self.sess.run(tf.all_variables())
开发者ID:awjuliani,项目名称:NeuralDreamVideos,代码行数:32,代码来源:model_vae.py
示例3: _discriminator_model
def _discriminator_model(sess, features, disc_input):
# Fully convolutional model
mapsize = 3
layers = [64, 128, 256, 512]
old_vars = tf.all_variables()
model = Model('DIS', 2*disc_input - 1)
for layer in range(len(layers)):
nunits = layers[layer]
stddev_factor = 2.0
model.add_conv2d(nunits, mapsize=mapsize, stride=2, stddev_factor=stddev_factor)
model.add_batch_norm()
model.add_relu()
# Finalization a la "all convolutional net"
model.add_conv2d(nunits, mapsize=mapsize, stride=1, stddev_factor=stddev_factor)
model.add_batch_norm()
model.add_relu()
model.add_conv2d(nunits, mapsize=1, stride=1, stddev_factor=stddev_factor)
model.add_batch_norm()
model.add_relu()
# Linearly map to real/fake and return average score
# (softmax will be applied later)
model.add_conv2d(1, mapsize=1, stride=1, stddev_factor=stddev_factor)
model.add_mean()
new_vars = tf.all_variables()
disc_vars = list(set(new_vars) - set(old_vars))
return model.get_output(), disc_vars
开发者ID:ameya005,项目名称:srez,代码行数:35,代码来源:srez_model.py
示例4: train_dnn
def train_dnn(data_folder, model_file):
# Output of dnn using input x
y = DNN(x)
print "Loading training pickles..."
train_set = import_data.load_dataset(data_folder + '/train_data.pickle',
data_folder + '/train_labels.pickle',
context_frames=context_frames)
# Create the dir for the model
if not os.path.isdir('%s/models/%s'%(save_loc,start_date)):
try:
os.makedirs('%s/models/%s'%(save_loc,start_date))
except OSError:
if not os.path.isdir('%s/models/%s'%(save_loc,start_date)):
raise
# Create the session
global sess
sess = tf.InteractiveSession()
global summary_op
global train_writer
global saver
saver = tf.train.Saver()
# Op for merging all summaries
summary_op = tf.merge_all_summaries()
# Summary Writer
train_writer = tf.train.SummaryWriter('%ssummaries/%s'%(save_loc, start_date), sess.graph)
# Cost function
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
# Optimizer
# For gradient descend, learning rate = 0.002 (see Hinton et al.)
# For AdamOptimizer, learning rate = 0.0001 (better than default (exp 1.2))
if (optimizer_name == 'Adam'):
# Hacky solution for always making sure that the beta2_power var
# is always initialized
temp = set(tf.all_variables())
optimizer = tf.train.AdamOptimizer(1e-4).minimize(cost)
sess.run(tf.initialize_variables(set(tf.all_variables()) - temp))
else:
optimizer = tf.train.GradientDescentOptimizer(0.02).minimize(cost)
if model_file:
saver.restore(sess, model_file)
print "Model restored"
else:
# Initialization
init_op = tf.initialize_all_variables()
sess.run(init_op)
print("Training network. Date: %s" % start_date)
train(train_set, y, cost, optimizer)
save_path = saver.save(sess, "%s/models/%s/model.ckpt"%(save_loc, start_date))
print("Model saved in file: %s" % save_path)
print("Summaries written to summaries/%s" % start_date)
evaluate_dnn(data_folder, y)
开发者ID:TimovNiedek,项目名称:timit_tf,代码行数:60,代码来源:run_dnn.py
示例5: sample
def sample(self, args):
if self.model is None:
# Allow sample to be usable outside of main()
with open(os.path.join(args.save_dir, 'config.pkl')) as f:
saved_args = cPickle.load(f)
with open(os.path.join(args.save_dir, 'chars_vocab.pkl')) as f:
self.chars, self.vocab = cPickle.load(f)
self.model = Model(saved_args, True)
with tf.Session() as sess:
tf.initialize_all_variables().run()
saver = tf.train.Saver(tf.all_variables())
ckpt = tf.train.get_checkpoint_state(args.save_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
return self.model.sample(sess, self.chars, self.vocab, args.n, args.prime)
else:
with tf.Session() as sess:
tf.initialize_all_variables().run()
saver = tf.train.Saver(tf.all_variables())
ckpt = tf.train.get_checkpoint_state(args.save_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
return self.model.sample(sess, self.chars, self.vocab, args.n, args.prime)
return None
开发者ID:ShipstoneDevelopment,项目名称:char-rnn-tensorflow,代码行数:26,代码来源:sample.py
示例6: _create_initializers
def _create_initializers(self):
if self._var_count != len(tf.all_variables()):
self._saver = tf.train.Saver(tf.all_variables(), max_to_keep=5)
self._init = tf.initialize_all_variables()
self._check_inited = tf.assert_variables_initialized()
self._var_count = len(tf.all_variables())
if self._summary_writer:
self._summaries = tf.merge_all_summaries()
self._summary_writer.add_graph(tf.get_default_graph().as_graph_def())
开发者ID:pombredanne,项目名称:prettytensor,代码行数:9,代码来源:local_trainer.py
示例7: _create_initializers
def _create_initializers(self):
if self._var_count != len(tf.all_variables()):
save_dir = os.path.dirname(self._save_path) if self._save_path else None
if save_dir and not tf.gfile.IsDirectory(save_dir):
tf.gfile.MakeDirs(save_dir)
self._saver = tf.train.Saver(tf.all_variables(), max_to_keep=5)
self._init = tf.initialize_all_variables()
self._check_inited = tf.assert_variables_initialized()
self._var_count = len(tf.all_variables())
if self._summary_writer:
self._summaries = tf.merge_all_summaries()
self._summary_writer.add_graph(tf.get_default_graph())
开发者ID:codeaudit,项目名称:prettytensor,代码行数:12,代码来源:local_trainer.py
示例8: testGraphMatchesImmediate
def testGraphMatchesImmediate(self):
"""Ensures that the vars line up between the two modes."""
with tf.Graph().as_default():
input_pt = prettytensor.wrap(self.input)
self.BuildLargishGraph(input_pt)
normal_names = sorted([v.name for v in tf.all_variables()])
with tf.Graph().as_default():
template = prettytensor.template('input')
self.BuildLargishGraph(template).construct(
input=prettytensor.wrap(self.input))
template_names = sorted([v.name for v in tf.all_variables()])
self.assertSequenceEqual(normal_names, template_names)
开发者ID:pombredanne,项目名称:prettytensor,代码行数:14,代码来源:templated_pretty_tensor_test.py
示例9: register_all_variables_and_grards
def register_all_variables_and_grards(y):
all_vars = tf.all_variables()
for v in tf.all_variables():
tf.histogram_summary('hist_'+v.name, v)
if v.get_shape() == []:
tf.scalar_summary('scal_'+v.name, v)
grad_vars = opt.compute_gradients(y,all_vars) #[ (T(gradient),variable) ]
for (dldw,v) in grad_vars:
if dldw != None:
tf.histogram_summary('hist_'+v.name+'dW', dldw)
if v.get_shape() == [] or dldw.get_shape() == []:
tf.scalar_summary('scal_'+v.name+'dW', dldw)
l2norm_dldw = tf.reduce_mean(tf.square(dldw))
tf.scalar_summary('scal_'+v.name+'dW_l2_norm', l2norm_dldw)
开发者ID:brando90,项目名称:tensor_flow_experiments,代码行数:15,代码来源:main_nn.py
示例10: add_aux_layer
def add_aux_layer(self, aux_attrs):
layer_name = aux_attrs['layer_name']
with tf.variable_scope(layer_name):
init_op = tf.initialize_all_variables()
saver = tf.train.Saver(tf.all_variables())
tensors_dict = {'%_init_op' % layer_name: init_op, '%s_saver_op' % layer_name: saver}
return tensors_dict
开发者ID:chengyang317,项目名称:information_pursuit,代码行数:7,代码来源:framwork.py
示例11: guarantee_initialized_variables
def guarantee_initialized_variables(self, session, list_of_variables = None):
if list_of_variables is None:
list_of_variables = tf.all_variables()
uninitialized_variables = list(tf.get_variable(name) for name in
session.run(tf.report_uninitialized_variables(list_of_variables)))
session.run(tf.initialize_variables(uninitialized_variables))
return uninitialized_variables
开发者ID:slundqui,项目名称:TFSparseCode,代码行数:7,代码来源:base.py
示例12: train_model
def train_model(args):
data_loader = InputHandler(args.data_dir, args.batch_size, args.result_length)
args.vocabulary_size = data_loader.vocabulary_size
# Save the original files, so that we can load the model when sampling
with open(os.path.join(args.snapshots_dir, CONFIGURATION_FILE), 'wb') as f:
cPickle.dump(args, f)
with open(os.path.join(args.snapshots_dir, WORDS_VOCABULARY_FILE), 'wb') as f:
cPickle.dump((data_loader.words, data_loader.vocabulary), f)
model = RNNModel(args.rnn_size, args.network_depth, args.batch_size, args.result_length,
args.vocabulary_size, args.gradient)
with tf.Session() as session:
tf.initialize_all_variables().run()
saver = tf.train.Saver(tf.all_variables())
for e in range(args.num_epochs):
session.run(tf.assign(model.lr, args.training_rate * (args.decay_rate ** e)))
data_loader.set_batch_pointer_to_zero()
state = model.initial_state.eval()
for b in range(data_loader.num_batches):
x, y = data_loader.get_next_batch()
feed = {model.input_data: x, model.targets: y, model.initial_state: state}
train_loss, state, _ = session.run([model.cost, model.final_state, model.train_op], feed)
if (e * data_loader.num_batches + b) % args.snapshot == 0 \
or (e==args.num_epochs-1 and b == data_loader.num_batches-1): # save for the last result
snapshot_path = os.path.join(args.snapshots_dir, 'model.ckpt')
saver.save(session, snapshot_path, global_step = e * data_loader.num_batches + b)
print("Model snapshot was taken to {}".format(snapshot_path))
开发者ID:lidanh,项目名称:game-of-thrones-tweets-generator,代码行数:30,代码来源:train_rnn_model.py
示例13: run_model_image
def run_model_image(checkpoint_file, image):
"""
Run an image through the trained model and vizualize its activations
:param checkpoint_file: The saved model parameters for the basic model
:param image: The supplied image (same dimensions as training).
"""
with tf.Graph().as_default():
image = tf.reshape(image, [IMAGE_SIZE, IMAGE_SIZE, 1])
image = tf.image.per_image_whitening(image)
image = tf.reshape(image, [1, IMAGE_SIZE, IMAGE_SIZE, 1])
image = tf.cast(image, tf.float32)
relu1, relu2, relu3 = inference(train=False, images=image, visualize=True)
saver = tf.train.Saver(tf.all_variables())
sess = tf.Session()
saver.restore(sess=sess, save_path=checkpoint_file)
units = relu1.eval(session=sess)
plotNNFilter(units)
units = relu2.eval(session=sess)
plotNNFilter(units)
units = relu3.eval(session=sess)
plotNNFilter(units)
开发者ID:ramhiser,项目名称:deep-learning-with-tensorflow-meetup,代码行数:26,代码来源:visualize_activations.py
示例14: restore_fn
def restore_fn(self, checkpoint_path, from_detection_checkpoint=True):
"""Return callable for loading a checkpoint into the tensorflow graph.
Args:
checkpoint_path: path to checkpoint to restore.
from_detection_checkpoint: whether to restore from a full detection
checkpoint (with compatible variable names) or to restore from a
classification checkpoint for initialization prior to training.
Returns:
a callable which takes a tf.Session as input and loads a checkpoint when
run.
"""
variables_to_restore = {}
for variable in tf.all_variables():
if variable.op.name.startswith(self._extract_features_scope):
var_name = variable.op.name
if not from_detection_checkpoint:
var_name = (
re.split('^' + self._extract_features_scope + '/', var_name)[-1])
variables_to_restore[var_name] = variable
# TODO: Load variables selectively using scopes.
variables_to_restore = (
variables_helper.get_variables_available_in_checkpoint(
variables_to_restore, checkpoint_path))
saver = tf.train.Saver(variables_to_restore)
def restore(sess):
saver.restore(sess, checkpoint_path)
return restore
开发者ID:Peterwangcn,项目名称:object_detector_app,代码行数:30,代码来源:ssd_meta_arch.py
示例15: testPrepareSessionWithReadyForLocalInitOp
def testPrepareSessionWithReadyForLocalInitOp(self):
with tf.Graph().as_default():
v = tf.Variable(1, name="v")
w = tf.Variable(
v,
trainable=False,
collections=[tf.GraphKeys.LOCAL_VARIABLES],
name="w")
with self.test_session():
self.assertEqual(False, tf.is_variable_initialized(v).eval())
self.assertEqual(False, tf.is_variable_initialized(w).eval())
sm2 = tf.train.SessionManager(
ready_op=tf.report_uninitialized_variables(),
ready_for_local_init_op=tf.report_uninitialized_variables(
tf.all_variables()),
local_init_op=w.initializer)
sess = sm2.prepare_session("", init_op=v.initializer)
self.assertEqual(
True,
tf.is_variable_initialized(sess.graph.get_tensor_by_name("v:0")).eval(
session=sess))
self.assertEqual(
True,
tf.is_variable_initialized(sess.graph.get_tensor_by_name("w:0")).eval(
session=sess))
self.assertEquals(1, sess.run(v))
self.assertEquals(1, sess.run(w))
开发者ID:821760408-sp,项目名称:tensorflow,代码行数:27,代码来源:session_manager_test.py
示例16: testGradient
def testGradient(self):
with self.test_session(use_gpu=self._use_gpu, graph=tf.Graph()) as sess:
batch_size = 1
cell_size = 3
input_size = 2
# Inputs
x = tf.zeros([batch_size, input_size])
h = tf.zeros([batch_size, cell_size])
output = gru_ops.GRUBlockCell(cell_size)(x, h)
sess.run([tf.initialize_all_variables()])
all_variables = tf.all_variables()
[w_ru, b_ru, w_c, b_c] = all_variables[:4]
error_x = tf.test.compute_gradient_error(x, (batch_size, input_size), output[0], (batch_size, cell_size))
error_h = tf.test.compute_gradient_error(h, (batch_size, cell_size), output[0], (batch_size, cell_size))
error_w_ru = tf.test.compute_gradient_error(
w_ru, (input_size + cell_size, 2 * cell_size), output[0], (batch_size, cell_size)
)
error_w_c = tf.test.compute_gradient_error(
w_c, (input_size + cell_size, cell_size), output[0], (batch_size, cell_size)
)
error_b_ru = tf.test.compute_gradient_error(b_ru, (2 * cell_size,), output[0], (batch_size, cell_size))
error_b_c = tf.test.compute_gradient_error(b_c, (cell_size,), output[0], (batch_size, cell_size))
eps = 1e-4
self.assertLess(error_x, eps)
self.assertLess(error_h, eps)
self.assertLess(error_w_ru, eps)
self.assertLess(error_w_c, eps)
self.assertLess(error_b_ru, eps)
self.assertLess(error_b_c, eps)
开发者ID:damienmg,项目名称:tensorflow,代码行数:35,代码来源:gru_ops_test.py
示例17: cluster_feature_analysis
def cluster_feature_analysis(sess, user_ids):
# Get trained parameters
lstm_vars = [v for v in tf.all_variables() if v.name.startswith('lstm')]
matrix_var = sess.run(lstm_vars[0])
bias_var = sess.run(lstm_vars[1])
# Split the gates
matrix_i, matrix_j, matrix_f, matrix_o = sess.run(array_ops.split(1, 4, matrix_var))
bias_i, bias_j, bias_f, bias_o = sess.run(array_ops.split(0, 4, bias_var))
dict_i, dict_j, dict_f, dict_o = dict(), dict(), dict(), dict()
for feature in range(len(config.feature_desc)):
dict_i[feature] = []
dict_j[feature] = []
dict_f[feature] = []
dict_o[feature] = []
for user_id in user_ids:
print user_id
gates_i, gates_j, gates_f, gates_o = feature_importance(sess, user_id, matrix_i,
matrix_j, matrix_f, matrix_o,
bias_i, bias_j, bias_f, bias_o)
for feature in range(len(config.feature_desc)):
dict_i[feature].append(gates_i[feature])
dict_j[feature].append(gates_j[feature])
dict_f[feature].append(gates_f[feature])
dict_o[feature].append(gates_o[feature])
return dict_i, dict_j, dict_f, dict_o
开发者ID:minhitbk,项目名称:data-science,代码行数:27,代码来源:lstm_analysis.py
示例18: evaluate
def evaluate():
"""Eval CIFAR-10 for a number of steps."""
with tf.Graph().as_default():
# Get images and labels for CIFAR-10.
eval_data = FLAGS.eval_data == 'test'
images, labels = cifar10.inputs(eval_data=eval_data)
# Build a Graph that computes the logits predictions from the
# inference model.
logits = cifar10.inference(images)
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = {}
for v in tf.all_variables():
if v in tf.trainable_variables():
restore_name = variable_averages.average_name(v)
else:
restore_name = v.op.name
variables_to_restore[restore_name] = v
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.merge_all_summaries()
graph_def = tf.get_default_graph().as_graph_def()
summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir,
graph_def=graph_def)
while True:
eval_once(saver, summary_writer, top_k_op, summary_op)
if FLAGS.run_once:
break
time.sleep(FLAGS.eval_interval_secs)
开发者ID:Dayz001,项目名称:MachineLearning,代码行数:32,代码来源:cifar10_eval.py
示例19: predict
def predict(self,x_test):
x_test = self.normalize_xtest(x_test)
X = tf.placeholder("float", [None, self.inputNumber])
Y = tf.placeholder("float", [None, self.outputNumber])
W1 = self.init_weight([self.inputNumber, self.layerOne], 'W1')
B1 = self.init_bias([self.layerOne], 'B1')
W2 = self.init_weight([self.layerOne, self.layerTwo], 'W2')
B2 = self.init_bias([self.layerTwo], 'B2')
W3 = self.init_weight([self.layerTwo,self.outputNumber], 'W3')
B3 = self.init_bias([self.outputNumber], 'B3')
L2 = self.model(X, W1, B1)
L3 = self.model(L2, W2, B2)
y_out = tf.nn.relu(tf.matmul(L3, W3) + B3)
cost = tf.reduce_mean(tf.square((Y - y_out)))
train_op = tf.train.AdamOptimizer(self.learningRate).minimize(cost)
pridict_op = tf.nn.relu(tf.matmul(L3, W3) + B3)
sess = tf.Session()
init = tf.initialize_all_variables()
sess.run(init)
saver = tf.train.Saver(tf.all_variables())
saver.restore(sess,self.savePath)
y_predict = sess.run(pridict_op, feed_dict={X:x_test})
return self.denormalize_ypredict(y_predict)
开发者ID:ChenLiangbo,项目名称:iloveme,代码行数:32,代码来源:myNeurolNetworkModel.py
示例20: evaluate
def evaluate (tfrecord_file_paths, theme):
eval_dir = 'workspace/{}/eval'.format(theme)
with tf.Graph().as_default() as g:
images, labels = distorted_inputs(tfrecord_file_paths=tfrecord_file_paths)
logits = cifar10.inference(tf.image.resize_images(images, cifar10.IMAGE_SIZE, cifar10.IMAGE_SIZE))
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
variable_averages = tf.train.ExponentialMovingAverage(cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = {}
for v in tf.all_variables():
if v in tf.trainable_variables():
restore_name = variable_averages.average_name(v)
else:
restore_name = v.op.name
variables_to_restore[restore_name] = v
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.merge_all_summaries()
summary_writer = tf.train.SummaryWriter(eval_dir, g)
eval_once(theme, saver, summary_writer, top_k_op, summary_op)
开发者ID:daiz713,项目名称:tfPhotoClassifier,代码行数:26,代码来源:eval.py
注:本文中的tensorflow.all_variables函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论