Open
Description
Hi, I'm trying to write a script to embed a single image based on your code, it's look something like this:
import json
import os
from importlib import import_module
import cv2
import tensorflow as tf
import numpy as np
sess = tf.Session()
# Read config
config = json.loads(open(os.path.join(
'<exp_root>', 'args.json'), 'r').read())
# Input img
net_input_size = (
config['net_input_height'], config['net_input_width'])
img = tf.placeholder(tf.float32, (None, net_input_size[0], net_input_size[1], 3))
# Create the model and an embedding head.
model = import_module('nets.' + config['model_name'])
head = import_module('heads.' + config['head_name'])
endpoints, _ = model.endpoints(img, is_training=False)
with tf.name_scope('head'):
endpoints = head.head(endpoints, config['embedding_dim'], is_training=False)
# Initialize the network/load the checkpoint.
checkpoint = tf.train.latest_checkpoint(config['experiment_root'])
print('Restoring from checkpoint: {}'.format(checkpoint))
tf.train.Saver().restore(sess, checkpoint)
raw_img = cv2.imread('<img>')
raw_img = cv2.resize(raw_img, net_input_size)
raw_img = np.swapaxes(raw_img, 0, 1)
raw_img = np.expand_dims(raw_img, axis=0)
emb = sess.run(endpoints['emb'], feed_dict={img: raw_img})[0]
But the result for a same image with my code and your code are not the same.
Note that there is no any augmentation added when I compute the embedding vector.
Am I missing anything here? Thanks you for the help
Metadata
Metadata
Assignees
Labels
No labels