Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ba360b0
update to work
Smellly Apr 16, 2018
9fd37a4
update
Smellly Apr 16, 2018
b4f17db
update to tf 1.4
Smellly Apr 19, 2018
ed75af1
uppate with bugs but can run
Smellly Apr 20, 2018
a9af301
modify to tf1.4
Smellly Apr 24, 2018
6bf9e81
add topic but not work
Smellly Apr 25, 2018
710c6cb
update
Smellly Apr 27, 2018
767b12d
add topic_extrac
Smellly Apr 30, 2018
7dcf013
modify readme
Smellly May 3, 2018
b9552f0
update
Smellly May 4, 2018
6f2f311
modify topic dir
Smellly May 4, 2018
0e166b8
update
Smellly May 4, 2018
0f4cd02
bug fixed
Smellly May 5, 2018
a8960ce
bug fixed
Smellly May 5, 2018
eac75a4
update
Smellly May 6, 2018
37503d3
modify extract_topic
Smellly May 7, 2018
1335cfe
update preprocess topic
Smellly May 7, 2018
04f59d3
add readme for topic
Smellly May 7, 2018
f02081b
update
Smellly May 7, 2018
1ae922f
update
Smellly May 7, 2018
b497e07
update
Smellly May 7, 2018
812fd9c
update target
Smellly May 7, 2018
d569624
modify
Smellly May 7, 2018
93cd997
bug fixed
Smellly May 7, 2018
ce798a5
day work update
Smellly May 7, 2018
08ded53
update
Smellly May 8, 2018
55e646e
update to run
Smellly May 8, 2018
3566a75
update
Smellly May 9, 2018
1807796
update
Smellly May 9, 2018
1798185
add images_W
Smellly May 9, 2018
5145061
fix images_W
Smellly May 9, 2018
cf59eba
update
Smellly May 9, 2018
1532faf
update
Smellly May 10, 2018
7cdf162
add summary
Smellly May 10, 2018
8fc5503
update summary
Smellly May 10, 2018
47c5525
day work update
Smellly May 10, 2018
9c64255
add viusalize
Smellly May 11, 2018
08dd704
merge mscoco and cub dictionary
Smellly May 11, 2018
d142e51
daily update
Smellly May 12, 2018
00c758c
add G_loss
Smellly May 12, 2018
29f2bf4
add gt in model_test
Smellly May 14, 2018
e27a601
update
Smellly May 14, 2018
d728c4b
update
Smellly May 14, 2018
0b331cd
add d_text_loss to tensorboard
Smellly May 14, 2018
b7eeb7f
add d_text_loss to tensorboard
Smellly May 14, 2018
22327bf
add AI challenge data
Smellly May 18, 2018
2170494
update
Smellly May 18, 2018
3c565db
add prepro_ai_annotation
Smellly May 18, 2018
fa37d50
use unicode
Smellly May 21, 2018
7c1b98f
update
Smellly May 21, 2018
ea391b2
modify unicode to utf-8
Smellly May 21, 2018
7e5ed41
rm annatation
Smellly May 21, 2018
84ded3b
add weibo
Smellly May 21, 2018
51f6692
update
Smellly May 21, 2018
32aee0b
update
Smellly May 22, 2018
55232df
update
Smellly May 22, 2018
59c6cbc
update
Smellly May 22, 2018
fd3df29
update
Smellly May 23, 2018
d2e85b3
id must be int
Smellly May 23, 2018
feeb7bd
img_id
Smellly May 23, 2018
3b7eba2
update
Smellly May 24, 2018
3e0a057
update to Chinese
Smellly May 24, 2018
c65e3df
modify ascii to utf8
Smellly May 24, 2018
905ce4a
update
Smellly May 24, 2018
580145c
encoding problems
Smellly May 28, 2018
30d0dae
update
Smellly May 29, 2018
5190288
update
Smellly Jun 19, 2018
aa51f81
update
Smellly Oct 31, 2018
5bb4402
add requirments.txt
Smellly Oct 31, 2018
b2cee11
update
Smellly Nov 1, 2018
b830880
update inference
Smellly Nov 6, 2018
c3cc90a
fix some bugs remain some
Smellly Nov 20, 2018
f2bb494
update can run
Smellly Nov 21, 2018
ec453e6
fix bugs
Smellly Nov 26, 2018
8b70f8f
update
Smellly Nov 26, 2018
e922926
update
Smellly Nov 27, 2018
1bee59a
update
Smellly Nov 27, 2018
d4e5ac6
update and optimize
Smellly Nov 27, 2018
ec68dfa
more clear code
Smellly Dec 29, 2018
474da1d
update
Smellly Jan 2, 2019
78deea6
update
Smellly Jan 2, 2019
5361560
update
Smellly Jan 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
*.pyc

*.zip

*.pkl

*.tar.gz

*.npz

*.swp

*.txt

logs*

checkpoint*

# some data
data-prepro/MSCOCO_preprocess/deep-residual-networks
data-prepro/MSCOCO_preprocess/neuraltalk2
data-prepro/MSCOCO_preprocess/resnet_model
data-prepro/MSCOCO_preprocess/mscoco_data
data-prepro/MSCOCO_preprocess/cub_data
data-prepro/MSCOCO_preprocess/annotations
data-prepro/CUB200_preprocess
data-prepro/topic/

show-adapt-tell/coco_spice

topic-adapt-tell/coco_spice
topic-adapt-tell/results*
topic-adapt-tell/log*
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "data-prepro/MSCOCO_preprocess/deep-residual-networks"]
path = data-prepro/MSCOCO_preprocess/deep-residual-networks
url = [email protected]:KaimingHe/deep-residual-networks.git
[submodule "show-adapt-tell/coco-caption"]
path = show-adapt-tell/coco-caption
url = [email protected]:peteanderson80/coco-caption.git
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ If you find this code useful for your research, please cite
## Requirements

- Python 2.7
- [Tensoflow 0.12.1](https://www.tensorflow.org/versions/r0.12/get_started/os_setup)
- ~~[Tensoflow 0.12.1](https://www.tensorflow.org/versions/r0.12/get_started/os_setup)~~
- [Tensorflow 1.4](https://www.tensorflow.org/versions/r1.4/)
- [Caffe](https://github.com/BVLC/caffe)
- OpenCV 2.4.9

P.S. Please clone the repository with the `--recursive` flag:

```Shell
# Make sure to clone with --recursive
git clone --recursive https://github.com/tsenghungchen/show-adapt-and-tell.git
git clone --recursive https://github.com/Smellly/show-adapt-and-tell.git
```

## Data Preprocessing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
import json
import numpy as np
from tqdm import tqdm
import pdb
# import pdb
import os
import pickle
import cPickle
try:
import cPickle as pkl
except:
import pickle as pkl
import string
import sys

def unpickle(p):
return cPickle.load(open(p,'r'))
return pkl.load(open(p,'r'))

def load_json(p):
return json.load(open(p,'r'))

def clean_words(data):
dict = {}
d = {}
freq = {}
# start with 1
idx = 1
sentence_count = 0
eliminate = 0
max_w = 30
for k in tqdm(range(len(data['caption']))):
sen = data['caption'][k]
filename = data['file_name'][k]
# for k in tqdm(range(len(data['caption']))):
for k in tqdm(data.keys()):
# print k, type(k), data[k]
sen = data[k][0]['caption']
filename = data[k][0]['filename']
# skip the no image description
words = re.split(' ', sen)
# pop the last u'.'
Expand All @@ -36,24 +41,31 @@ def clean_words(data):
if p in word:
word = word.replace(p,'')
word = word.lower()
if word not in dict.keys():
dict[word] = idx
if word not in d.keys():
d[word] = idx
idx += 1
freq[word] = 1
else:
freq[word] += 1
else:
eliminate += 1

print 'Threshold(max_words) =', max_w
print 'Eliminate =', eliminate
print 'Total sentence_count =', sentence_count
print 'Number of different words =', len(dict.keys())
print 'Number of different words =', len(d.keys())
print 'Saving....'
np.savez('cleaned_words', dict=dict, freq=freq)
return dict, freq

np.savez('K_cleaned_words', dict=d, freq=freq)

return d, freq


phase = 'train'
phase = sys.argv[1]
data_path = './cub_data/K_' + phase + '_annotation.json'
data = load_json(data_path)
# print type(data), data.keys()

id2name = unpickle('id2name.pkl')
id2caption = unpickle('id2caption.pkl')
splits = unpickle('splits.pkl')
Expand All @@ -70,23 +82,34 @@ def clean_words(data):
caption_list.append(sen)

# build dictionary
if not os.path.isfile('cub_data/dictionary_'+str(thres)+'.npz'):
pdb.set_trace()
if not os.path.isfile('./cub_data/dictionary_'+str(thres)+'.npz'):
# pdb.set_trace()
# clean the words through the frequency
words = np.load('K_cleaned_words.npz')
dict = words['dict'].item(0)
freq = words['freq'].item(0)
if not os.path.isfile('K_cleaned_words.npz'):
d, freq = clean_words(data)
else:
words = np.load('K_cleaned_words.npz')
d = words['d'].item(0)
freq = words['freq'].item(0)

idx2word = {}
word2idx = {}
idx = 1
for k in tqdm(dict.keys()):
for k in tqdm(d.keys()):
if freq[k] >= thres:
word2idx[k] = idx
idx2word[str(idx)] = k
idx += 1

word2idx[u'<UNK>'] = len(word2idx.keys())+1
word2idx[u'<BOS>'] = 0
idx2word["0"] = u'<BOS>'
word2idx[u'<EOS>'] = len(word2idx.keys())
idx2word[str(len(idx2word.keys()))] = u'<EOS>'
word2idx[u'<UNK>'] = len(word2idx.keys())
idx2word[str(len(word2idx.keys()))] = u'<UNK>'
word2idx[u'<NOT>'] = len(word2idx.keys())
idx2word[str(len(idx2word.keys()))] = u'<NOT>'

print 'Threshold of word fequency =', thres
print 'Total words in the dictionary =', len(word2idx.keys())
np.savez('cub_data/dictionary_'+str(thres), word2idx=word2idx, idx2word=idx2word)
Expand All @@ -104,6 +127,7 @@ def clean_words(data):
filename_list_new = []
img_id_list_new = []
caption_length = []

for k in tqdm(range(len(caption_list))):
sen = caption_list[k]
img_id = img_id_list[k]
Expand Down Expand Up @@ -143,8 +167,10 @@ def clean_words(data):
tokenized_caption_info['filename_list'] = np.asarray(filename_list_new)
tokenized_caption_info['img_id_list'] = np.asarray(img_id_list_new)
tokenized_caption_info['raw_caption_list'] = np.asarray(caption_list_new)

print 'Number of sentence =', num_sentence
print 'eliminate = ', eliminate

with open('./cub_data/tokenized_'+phase+'_caption.pkl', 'w') as outfile:
pickle.dump(tokenized_caption_info, outfile)
pkl.dump(tokenized_caption_info, outfile)

3 changes: 2 additions & 1 deletion data-prepro/CUB200_preprocess/get_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cPickle

# generate name2id & id2name dictionary
name_id_path = '../images.txt'
name_id_path = 'cub_data/CUB_200_2011/images.txt'
name_id = open(name_id_path).read().splitlines()
name2id = {}
id2name = {}
Expand All @@ -19,6 +19,7 @@
# CUB_CVPR16 will be created after unzipping.
caption_path = './CUB_CVPR16/text_c10/'
id2caption = {}

for name in name2id:
txt_name = '.'.join(name.split('.')[0:-1]) + '.txt'
txt_path = os.path.join(caption_path, txt_name)
Expand Down
61 changes: 57 additions & 4 deletions data-prepro/CUB200_preprocess/prepro_cub_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
from random import shuffle, seed
import pickle as pk
import pdb
input_data = 'split.pkl'

input_data = 'splits.pkl'
with open(input_data) as data_file:
dataset = pk.load(data_file)

skip_num = 0
val_data = {}
test_data = {}
train_data = []

train_data = {}
val_dataset = []
test_dataset = []
counter = 0
id2name = pk.load(open('id2name.pkl'))
data = pk.load(open('id2caption.pkl'))

print("Processing test_data")
for i in dataset['test_id']:
caps = []
# For GT
Expand All @@ -40,6 +41,58 @@
caps.append(tmp)

test_data[i] = caps

print 'dump %d in test_data'%len(test_data)
json.dump(test_data, open('cub_data/K_test_annotation.json', 'w'))
# pk.dump(test_data, open('cub_data/K_test_annotation.pkl', 'w'))

print("Processing train_data")
for i in dataset['train_id']:
caps = []
# For GT
name = id2name[i]
count = 0
for sen in data[i]:
for punc in string.punctuation:
if punc in sen:
sen = sen.replace(punc, '')

tmp = {}
tmp['filename'] = name
tmp['img_id'] = i
tmp['cap_id'] = count
tmp['caption'] = sen
count += 1
caps.append(tmp)

# print i, type(i)
train_data[i] = caps
print 'number of skip train data: ' + str(skip_num)
[u'info', u'images', u'licenses', u'type', u'annotations']
json.dump(test_data, open('cub_data/K_test_annotation.json', 'w'))
print 'dump %d in train_data'%len(train_data)
json.dump(test_data, open('cub_data/K_train_annotation.json', 'w'))
# pk.dump(train_data, open('cub_data/K_train_annotation.pkl', 'w'))

print("Processing val_data")
for i in dataset['val_id']:
caps = []
# For GT
name = id2name[i]
count = 0
for sen in data[i]:
for punc in string.punctuation:
if punc in sen:
sen = sen.replace(punc, '')

tmp = {}
tmp['filename'] = name
tmp['img_id'] = i
tmp['cap_id'] = count
tmp['caption'] = sen
count += 1
caps.append(tmp)

val_data[i] = caps
# pk.dump(val_data, open('cub_data/K_val_annotation.pkl', 'w'))
print 'dump %d in val_data'%len(val_data)
json.dump(test_data, open('cub_data/K_val_annotation.json', 'w'))
10 changes: 7 additions & 3 deletions data-prepro/MSCOCO_preprocess/extract_resnet_coco.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys
sys.path.append('/home/PaulChen/deep-residual-networks/caffe/python')
# sys.path.append('/home/PaulChen/deep-residual-networks/caffe/python')
sys.path.append('/home/smelly/projects/show-adapt-and-tell/data-prepro/MSCOCO_preprocess/deep-residual-networks/caffe')
sys.path.append('/home/smelly/projects/show-adapt-and-tell/data-prepro/MSCOCO_preprocess/deep-residual-networks/caffe/python')

import caffe

import numpy as np
import argparse
import cv2
Expand Down Expand Up @@ -77,7 +81,7 @@ def extract_image(net, image_file):

def split(split, net, feat_dict):
print 'load ' + split
img_dir = './coco/'
img_dir = '/home/smelly/projects/ic_models/im2txt/im2txt/data/mscoco/raw-data/'
img_path = os.path.join(img_dir, split)
img_list = os.listdir(img_path)
pool5_list = []
Expand All @@ -90,7 +94,7 @@ def split(split, net, feat_dict):

if __name__ == '__main__':
args = parse_args()
caffe_path = os.path.join('/home','PaulChen','caffe','python')
# caffe_path = os.path.join('/home','PaulChen','caffe','python')

print 'caffe setting'
caffe.set_mode_gpu()
Expand Down
Loading