Skip to content

Commit ed75af1

Browse files
committed
uppate with bugs but can run
1 parent b4f17db commit ed75af1

File tree

7 files changed

+1294
-148
lines changed

7 files changed

+1294
-148
lines changed

show-adapt-tell/highway.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import tensorflow as tf
2+
3+
# highway layer that borrowed from https://github.com/carpedm20/lstm-char-cnn-tensorflow
4+
def highway(input_, size, layer_size=1, bias=-2, f=tf.nn.relu):
5+
"""Highway Network (cf. http://arxiv.org/abs/1505.00387).
6+
7+
t = sigmoid(Wy + b)
8+
z = t * g(Wy + b) + (1 - t) * y
9+
where g is nonlinearity, t is transform gate, and (1 - t) is carry gate.
10+
"""
11+
output = input_
12+
for idx in xrange(layer_size):
13+
output = f(tf.nn.rnn_cell._linear(output, size, 0, scope='output_lin_%d' % idx))
14+
transform_gate = tf.sigmoid(
15+
tf.nn.rnn_cell._linear(input_, size, 0, scope='transform_lin_%d' % idx) + bias)
16+
carry_gate = 1. - transform_gate
17+
output = transform_gate * output + carry_gate * input_
18+
return output
19+

show-adapt-tell/highway_tf1.4.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import tensorflow as tf
2+
3+
import sys
4+
sys.path.append('/home/smelly/miniconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops')
5+
import rnn_cell_impl
6+
7+
# highway layer that borrowed from https://github.com/carpedm20/lstm-char-cnn-tensorflow
8+
def highway(input_, size, layer_size=1, bias=-2, f=tf.nn.relu):
9+
"""Highway Network (cf. http://arxiv.org/abs/1505.00387).
10+
11+
t = sigmoid(Wy + b)
12+
z = t * g(Wy + b) + (1 - t) * y
13+
where g is nonlinearity, t is transform gate, and (1 - t) is carry gate.
14+
"""
15+
output = input_
16+
for idx in xrange(layer_size):
17+
# output = f(tf.nn.rnn_cell._linear(output, size, 0, scope='output_lin_%d' % idx))
18+
with tf.variable_scope('output_lin_%d' % idx):
19+
output = f(
20+
rnn_cell_impl._linear(
21+
output, size, 0))
22+
# for tf.1.2.1 above
23+
# tf.nn.rnn_cell._linear(input_, size, 0, scope='transform_lin_%d' % idx) + bias)
24+
with tf.variable_scope('transform_lin_%d' % idx):
25+
transform_gate = tf.sigmoid(
26+
rnn_cell_impl._linear(
27+
input_, size, 0) + bias)
28+
carry_gate = 1. - transform_gate
29+
output = transform_gate * output + carry_gate * input_
30+
return output
31+

show-adapt-tell/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
FLAGS = flags.FLAGS
4040
pp = pprint.PrettyPrinter()
41+
4142
def main(_):
4243
pp.pprint(flags.FLAGS.__flags)
4344

@@ -60,7 +61,7 @@ def main(_):
6061
print('G_pretrained_model train')
6162
G_pretrained_model.train()
6263
print('G_pretrained_model evaluate')
63-
G_pretrained_model.evaluate('test', 0, )
64+
G_pretrained_model.evaluate('test', 0)
6465
if FLAGS.D_is_pretrain:
6566
negative_dataset = mscoco_negative(dataset, FLAGS)
6667
D_pretrained_model = D_pretrained(sess, dataset, negative_dataset, info, conf=FLAGS)

show-adapt-tell/model.py

Lines changed: 67 additions & 145 deletions
Large diffs are not rendered by default.

show-adapt-tell/model_tf1.4.py

Lines changed: 830 additions & 0 deletions
Large diffs are not rendered by default.

show-adapt-tell/pretrain_G.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
'''
3+
// Author: Jay Smelly.
4+
// Last modify: 2018-04-20 10:59:19.
5+
// File name: pretrain_G.py
6+
//
7+
// Description: tensorflow 0.12.1
8+
'''
9+
110
from __future__ import division
211
import os
312
import time
@@ -293,9 +302,11 @@ def evaluate(self, split, count, eval_algo='max'):
293302
break
294303
meteor_pd[str(int(image_id[j]))] = [{'image_id':str(int(image_id[j])), 'caption':samples[j][0]}]
295304
meteor_id.append(str(int(image_id[j])))
296-
#np.savez("result_%s"%str(count), meteor_pd=meteor_pd, meteor_id=meteor_id)
305+
# np.savez("result_%s"%str(count), meteor_pd=meteor_pd, meteor_id=meteor_id)
306+
# test_annotation is a json file
297307
scorer = COCOEvalCap(test_annotation, meteor_pd, meteor_id)
298-
scorer.evaluate(verbose=True)
308+
# scorer.evaluate(verbose=True)
309+
scorer.evaluate()
299310

300311
def save(self, checkpoint_dir, step):
301312
model_name = "G_pretrained"
@@ -320,3 +331,4 @@ def load(self, checkpoint_dir):
320331
else:
321332
return False
322333

334+

0 commit comments

Comments
 (0)