AhmedSSabir
commited on
Commit
•
c70396e
1
Parent(s):
a579830
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
```python
|
5 |
+
import tensorflow as tf
|
6 |
+
import numpy as np
|
7 |
+
import pandas as pd
|
8 |
+
import sys
|
9 |
+
from sklearn.model_selection import train_test_split
|
10 |
+
|
11 |
+
sys.path.insert(0, "bert_experimental")
|
12 |
+
|
13 |
+
from bert_experimental.finetuning.text_preprocessing import build_preprocessor
|
14 |
+
from bert_experimental.finetuning.graph_ops import load_graph
|
15 |
+
|
16 |
+
|
17 |
+
df = pd.read_csv("data/test.tsv", sep='\t')
|
18 |
+
|
19 |
+
|
20 |
+
texts = []
|
21 |
+
delimiter = " ||| "
|
22 |
+
|
23 |
+
for vis, cap in zip(df.visual.tolist(), df.caption.tolist()):
|
24 |
+
texts.append(delimiter.join((str(vis), str(cap))))
|
25 |
+
|
26 |
+
|
27 |
+
texts = np.array(texts)
|
28 |
+
|
29 |
+
trX, tsX = train_test_split(texts, shuffle=False, test_size=0.01)
|
30 |
+
|
31 |
+
|
32 |
+
restored_graph = load_graph("frozen_graph.pb")
|
33 |
+
|
34 |
+
graph_ops = restored_graph.get_operations()
|
35 |
+
input_op, output_op = graph_ops[0].name, graph_ops[-1].name
|
36 |
+
print(input_op, output_op)
|
37 |
+
|
38 |
+
x = restored_graph.get_tensor_by_name(input_op + ':0')
|
39 |
+
y = restored_graph.get_tensor_by_name(output_op + ':0')
|
40 |
+
|
41 |
+
preprocessor = build_preprocessor("uncased_L-12_H-768_A-12/vocab.txt", 64)
|
42 |
+
py_func = tf.numpy_function(preprocessor, [x], [tf.int32, tf.int32, tf.int32], name='preprocessor')
|
43 |
+
|
44 |
+
py_func = tf.numpy_function(preprocessor, [x], [tf.int32, tf.int32, tf.int32])
|
45 |
+
|
46 |
+
##predictions
|
47 |
+
|
48 |
+
sess = tf.Session(graph=restored_graph)
|
49 |
+
|
50 |
+
print(trX[:4])
|
51 |
+
|
52 |
+
y = tf.print(y, summarize=-1)
|
53 |
+
#x = tf.print(x, summarize=-1)
|
54 |
+
y_out = sess.run(y, feed_dict={
|
55 |
+
x: trX[:4].reshape((-1,1))
|
56 |
+
#x: trX[:90000].reshape((-1,1))
|
57 |
+
})
|
58 |
+
|
59 |
+
|
60 |
+
print(y_out)
|
61 |
+
|
62 |
+
|
63 |
+
````
|