Facenet: Incompatible matrix size while calculating embedding for a single image

Created on 25 Jul 2018  路  3Comments  路  Source: davidsandberg/facenet

I was going through issue #503 #321 #278 and #234 regarding generation of embedding for a single image. Although I didn't see any issue reported for the following error.

I am trying to generate embeddings for a single image. My error is as follows:

InvalidArgumentError (see above for traceback): Matrix size-incompatible: In[0]: [1,7168], In[1]: [1792,512]
     [[Node: InceptionResnetV1/Bottleneck/MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Logits/Dropout/cond/Merge, `InceptionResnetV1/Bottleneck/weights/read)]]

Why is this happening?

I have used the frozen graph definition provided by the author too! My code is as follows:

I am passing the aligned image as input

with tf.Session() as sess:
        #Load the model
        print('Loading feature extraction model')
        facenet.load_model('../../frozen_graph.pb')
        #Get input and output tensors
        images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
        embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
        phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
        embedding_size = embeddings.get_shape()[1]
        # Run forward pass to calculate embeddings
        print('Calculating features for images')
        nrof_images = 1
        nrof_batches_per_epoch = int(math.ceil(1.0*nrof_images / 90))
        emb_array = np.zeros((nrof_images, embedding_size))
        for i in range(nrof_batches_per_epoch):
            start_index = i*90
            end_index = min((i+1)*90, nrof_images)
            feed_dict = { images_placeholder:images, phase_train_placeholder:False }
            emb_array[start_index:end_index,:] = sess.run(embeddings, feed_dict=feed_dict)


image = misc.imread('<image_path>')
aligned_image = align_image.align_img(image) #calling align image code provided by author
images = np.zeros((1, 182, 182, 3))
images[0,:,:,:] = aligned_image

Passing this '_images_' to the Tensorflow session.

Most helpful comment

Resize input image 160 * 160 @priyakansal

All 3 comments

Also, 7168 is exactly 4 times 1792!

@tamaghnadutta
Hi,
I am facing the same issue.
Have you find the solution?
If yes, Please suggest how to rectify this?

Resize input image 160 * 160 @priyakansal

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonybaigang picture tonybaigang  路  3Comments

allahbaksh picture allahbaksh  路  3Comments

helloyide picture helloyide  路  4Comments

Leedonggeon picture Leedonggeon  路  3Comments

billtiger picture billtiger  路  3Comments