Embed a single image
See original GitHub issueHi, 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
How to Embed an Image to Get a Self-Contained Web Page
Embedding a picture into a self-contained web page does not prevent people from copying your images. The usual way of saving an image...
Read more >How to embed an image onto different sources - Canto
Open Google Photos; Locate the image you wish to embed; Click the image to open it; Find the 'share' icon in the upper...
Read more >3 Ways to Embed Pictures - wikiHow
1. Decide what type of image you want to embed. You can add a picture, graphic, clip art, or chart. You can also...
Read more >Embedding Novel Views in a Single JPEG Image - arXiv
We propose a novel approach for embedding novel views in a single JPEG image while preserving the perceptual fidelity of the modified JPEG...
Read more >Embedding a Video, Image or Other Content - Easy WP Guide
To embed something into your Post or Page, simply paste the URL into your content area. The URL needs to be on its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The only thing that comes to mind right now, is that by the default we use test time augmentation, which you don’t. But that depends on how you are using our embed script to create comparable embeddings in this’ll case.
On Mon, Jun 3, 2019, 10:20 Hoàng Tùng Lâm (Linus) notifications@github.com wrote:
@lamhoangtung I think I figured out the first problem.
So, to get cv2 load embeddings close to the
embed.py
values, I did the following.If you want to get the exactly same values you can load the image with TF instead of CV2
I got almost identical embeddings this way