How i can get the feature vector from this model?
Here is my code suggestion: (TF 1.14)
```
import tensorflow as tf
import numpy as np
import cv2
def load_pb(path_to_pb):
with tf.gfile.GFile(path_to_pb, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def, name='')
return graph
graph = load_pb(fpath_to_pb_file)
input = graph.get_tensor_by_name('input:0')
output = graph.get_tensor_by_name('embeddings:0')
phase_train_placeholder = graph.get_tensor_by_name("phase_train:0")
img = cv2.imread(path_to_test_image)
def preprocess_img(x):
x = cv2.resize(x, (160, 160))
mean = np.mean(x)
std = np.std(x)
std_adj = np.maximum(std, 1.0/np.sqrt(x.size))
y = np.multiply(np.subtract(x, mean), 1/std_adj)
return np.expand_dims(y, 0)
with tf.Session(graph=graph) as sess:
embed = sess.run(output, feed_dict={input:preprocess_img(img), phase_train_placeholder:False})
print(embed)```
Most helpful comment
Here is my code suggestion: (TF 1.14)
```
import tensorflow as tf
import numpy as np
import cv2
def load_pb(path_to_pb):
with tf.gfile.GFile(path_to_pb, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def, name='')
return graph
graph = load_pb(fpath_to_pb_file)
input = graph.get_tensor_by_name('input:0')
output = graph.get_tensor_by_name('embeddings:0')
phase_train_placeholder = graph.get_tensor_by_name("phase_train:0")
img = cv2.imread(path_to_test_image)
def preprocess_img(x):
x = cv2.resize(x, (160, 160))
mean = np.mean(x)
std = np.std(x)
std_adj = np.maximum(std, 1.0/np.sqrt(x.size))
y = np.multiply(np.subtract(x, mean), 1/std_adj)
return np.expand_dims(y, 0)
with tf.Session(graph=graph) as sess:
embed = sess.run(output, feed_dict={input:preprocess_img(img), phase_train_placeholder:False})
print(embed)```