def tf_logs(tmpdir_factory):
import numpy as np
import tensorflow as tf
x = np.random.rand(5)
y = 3 * x + 1 + 0.05 * np.random.rand(5)
a = tf.Variable(0.1)
b = tf.Variable(0.)
err = a*x+b-y
loss = tf.norm(err)
tf.summary.scalar("loss", loss)
tf.summary.scalar("a", a)
tf.summary.scalar("b", b)
merged = tf.summary.merge_all()
optimizor = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
with tf.Session() as sess:
log_dir = tmpdir_factory.mktemp("logs", numbered=False)
log_dir = str(log_dir)
train_write = tf.summary.FileWriter(log_dir, sess.graph)
tf.global_variables_initializer().run()
for i in range(1000):
_, merged_ = sess.run([optimizor, merged])
train_write.add_summary(merged_, i)
return log_dir
python类norm()的实例源码
test_tensorboard_integration.py 文件源码
项目:jupyter_tensorboard
作者: lspvic
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
Bidirectionnet_GMM_softmaxloss.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def build_input(self):
# positive
self.raw_sentence= tf.placeholder(tf.float32, shape=[self.batch_size,18000],name='raw_sentence')
self.sentence_emb =self.raw_sentence/tf.norm(self.raw_sentence,axis=-1,keep_dims=True) #tf.nn.embedding_lookup(tf.get_variable('word_embedding',[4096,512]),self.raw_sentence)
self.image_feat = tf.placeholder(tf.float32,shape=[self.batch_size,4096], name='image_features')
self.image_feat_norm = self.image_feat/tf.norm(self.image_feat,axis=-1,keep_dims=True)
self.sen_feat_norm = self.sentence_emb/tf.norm(self.sentence_emb,axis=-1,keep_dims=True)
self.im_similarity = tf.matmul(self.image_feat_norm,self.image_feat_norm,transpose_b=True)
self.sen_similarity =tf.matmul(self.sen_feat_norm,self.sen_feat_norm,transpose_b=True)
Bidirectionnet_GMM_better_topK.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def build_input(self):
# positive
self.raw_sentence= tf.placeholder(tf.float32, shape=[self.batch_size,18000],name='raw_sentence')
self.sentence_emb =self.raw_sentence/tf.norm(self.raw_sentence,axis=-1,keep_dims=True) #tf.nn.embedding_lookup(tf.get_variable('word_embedding',[4096,512]),self.raw_sentence)
self.image_feat = tf.placeholder(tf.float32,shape=[self.batch_size,4096], name='image_features')
self.image_feat_norm = self.image_feat/tf.norm(self.image_feat,axis=-1,keep_dims=True)
self.sen_feat_norm = self.sentence_emb/tf.norm(self.sentence_emb,axis=-1,keep_dims=True)
self.im_similarity = tf.matmul(self.image_feat_norm,self.image_feat_norm,transpose_b=True)
self.sen_similarity =tf.matmul(self.sen_feat_norm,self.sen_feat_norm,transpose_b=True)
Bidirectionnet_GMM_better_topK.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def sentencenet(self, sentence_emb, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 =tf.nn.dropout(tf.contrib.layers.fully_connected(sentence_emb,2048, \
weights_regularizer=wd, scope='s_fc1'),keep_prob=self.keep_prob )# 20*10*256
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = sentence_fc2
return sentence_fc2
Bidirectionnet_GMM_better_topK.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.nn.dropout(tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1'),keep_prob=self.keep_prob)
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
def sentencenet(self, input_tensor, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 = tf.contrib.layers.fully_connected(input_tensor, 2048, weights_regularizer=wd, scope='s_fc1')
#drop_fc1 = tf.nn.dropout(sentence_fc1, self.keep_prob, name='drop_fc1')
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None, weights_regularizer=wd, scope='s_fc2')
sentence_fc2_bn = tf.contrib.layers.batch_norm(sentence_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='s_fc2_bn')
embed = sentence_fc2_bn/tf.norm(sentence_fc2_bn,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = embed
return embed
def build_input(self):
# positive
self.raw_sentence= tf.placeholder(tf.float32, shape=[self.batch_size,18000],name='raw_sentence')
self.sentence_emb =tf.sign(self.raw_sentence)*tf.pow(tf.abs(self.raw_sentence),0.5)/tf.norm(self.raw_sentence,axis=1,keep_dims=True) #tf.nn.embedding_lookup(tf.get_variable('word_embedding',[4096,512]),self.raw_sentence)
self.image_feat = tf.placeholder(tf.float32,shape=[self.batch_size,4096], name='image_features')
def sentencenet(self, sentence_emb, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 =tf.nn.dropout(tf.contrib.layers.fully_connected(sentence_emb,2048, \
weights_regularizer=wd, scope='s_fc1'),keep_prob=self.keep_prob) # 20*10*256
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = sentence_fc2
return sentence_fc2
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.nn.dropout(tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1'),keep_prob=self.keep_prob)
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
def sentencenet(self, sentence_emb, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 =tf.contrib.layers.fully_connected(sentence_emb,2048, \
weights_regularizer=wd, scope='s_fc1') # 20*10*256
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = sentence_fc2
return sentence_fc2
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1')
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
Bidirectionnet_GMM_better_topK_9000feat.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def sentencenet(self, sentence_emb, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 =tf.nn.dropout(tf.contrib.layers.fully_connected(sentence_emb,2048, \
weights_regularizer=wd, scope='s_fc1'),keep_prob=self.keep_prob )# 20*10*256
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = sentence_fc2
return sentence_fc2
Bidirectionnet_GMM_better_topK_9000feat.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.nn.dropout(tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1'),keep_prob=self.keep_prob)
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
Bidirectionnet_GMM9000feat_softmaxloss.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def build_input(self):
# positive
self.labels = tf.placeholder(tf.float32, shape=[None,self.num_class], name='concept_labels')
self.raw_sentence= tf.placeholder(tf.float32, shape=[self.batch_size,9000],name='raw_sentence')
self.sentence_emb =self.raw_sentence/tf.norm(self.raw_sentence,axis=-1,keep_dims=True) #tf.nn.embedding_lookup(tf.get_variable('word_embedding',[4096,512]),self.raw_sentence)
self.image_feat = tf.placeholder(tf.float32,shape=[self.batch_size,4096], name='image_features')
self.image_feat_norm = self.image_feat/tf.norm(self.image_feat,axis=-1,keep_dims=True)
self.sen_feat_norm = self.sentence_emb/tf.norm(self.sentence_emb,axis=-1,keep_dims=True)
self.im_similarity = tf.matmul(self.image_feat_norm,self.image_feat_norm,transpose_b=True)
self.sen_similarity =tf.matmul(self.sen_feat_norm,self.sen_feat_norm,transpose_b=True)
Bidirectionnet_GMM9000feat_softmaxloss.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def sentencenet(self, sentence_emb, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
sentence_fc1 =tf.nn.dropout(tf.contrib.layers.fully_connected(sentence_emb,2048, \
weights_regularizer=wd, scope='s_fc1'),keep_prob=self.keep_prob )# 20*10*256
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = sentence_fc2
return sentence_fc2
Bidirectionnet_GMM_dataflow.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 16
收藏 0
点赞 0
评论 0
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1')
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
def sentencenet(self, input_tensor, reuse=False):
with tf.variable_scope('sentence_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
#lstm_embed = self.lstm(input_tensor, reuse=reuse)
sentence_fc1 = tf.contrib.layers.fully_connected(input_tensor, 2048, weights_regularizer=wd, scope='s_fc1')
#drop_fc1 = tf.nn.dropout(sentence_fc1, self.keep_prob, name='drop_fc1')
sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None, weights_regularizer=wd, scope='s_fc2')
sentence_fc2_bn = tf.contrib.layers.batch_norm(sentence_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='s_fc2_bn')
embed = sentence_fc2_bn/tf.norm(sentence_fc2_bn,axis= -1,keep_dims=True)
self.endpoint['sentence_fc1'] = sentence_fc1
self.endpoint['sentence_fc2'] = embed
return embed
def imagenet(self, image_feat, reuse=False, skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1')
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed
Bidirectionnet_cluster_tfidf.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 15
收藏 0
点赞 0
评论 0
def build_input(self):
# positive
self.raw_sentence= tf.placeholder(tf.float32, shape=[self.batch_size,1000],name='raw_sentence')
self.sentence_emb =self.raw_sentence/(1e-12+tf.norm(self.raw_sentence,ord=2,axis=1,keep_dims=True)) #tf.nn.embedding_lookup(tf.get_variable('word_embedding',[4096,512]),self.raw_sentence)
self.image_feat = tf.placeholder(tf.float32,shape=[self.batch_size,4096], name='image_features')
Bidirectionnet_cluster_tfidf.py 文件源码
项目:image-text-matching
作者: llltttppp
项目源码
文件源码
阅读 16
收藏 0
点赞 0
评论 0
def imagenet(self, image_feat, reuse=False,skip=False):
if skip:
return image_feat
with tf.variable_scope('image_net', reuse=reuse) as scope:
wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
image_fc1 = tf.nn.dropout(tf.contrib.layers.fully_connected(image_feat,2048, weights_regularizer=wd,scope='i_fc1'),keep_prob=self.keep_prob)
#drop_fc1 = tf.nn.dropout(image_fc1, self.keep_prob, name='drop_fc1')
image_fc2 = tf.contrib.layers.fully_connected(image_fc1, 512, activation_fn=None, weights_regularizer=wd, scope='i_fc2')
image_fc2_bn = tf.contrib.layers.batch_norm(image_fc2, center=True, scale=True, is_training=self.is_training,
reuse=reuse, decay=0.999, updates_collections=None,
scope='i_fc2_bn')
embed = image_fc2_bn / tf.norm(image_fc2_bn,axis=-1,keep_dims=True)
self.endpoint['image_fc1'] = image_fc1
self.endpoint['image_fc2'] = embed
return embed