AIInAi / tf-insightface

A better tensorflow implementation of deepinsight, aiming at smoothly production ready for cross-platforms. Currently only with inference, training code later.
MIT License
212 stars 61 forks source link

Dropout Rate #2

Open Neltherion opened 6 years ago

Neltherion commented 6 years ago

Hi

Thanks for this Simple and Clean implementation.

I have a question about the Dropout Rate: What is its use? I didn't see something like this in the original implementation (at least I think I didn't see such parameter).

When I change it from 0.5 to 0.1 and then to 0.01 the predictions become more accurate. I'm not sure what value I should choose for it.

Here's my Code:

model = base_server.BaseServer(model_fp=configs.face_describer_model_fp,
                               input_tensor_names=configs.face_describer_input_tensor_names,
                               output_tensor_names=configs.face_describer_output_tensor_names,
                               device=configs.face_describer_device)

# Define input tensors feed to session graph
dropout_rate = 0.1

first_image = cv2.imread('./Images/1.jpg')
first_image = cv2.resize(first_image, (112, 112))
input_data = [np.expand_dims(first_image, axis=0), dropout_rate]
face_descriptor1 = model.inference(data=input_data)
embedding1 = preprocessing.normalize(face_descriptor1[0])

second_image = cv2.imread('./Images/4.jpg')
second_image = cv2.resize(second_image, (112, 112))
input_data = [np.expand_dims(second_image, axis=0), dropout_rate]
face_descriptor2 = model.inference(data=input_data)
embedding2 = preprocessing.normalize(face_descriptor2[0])

dist = np.sum(np.square(embedding1 - embedding2))
print("Distance => %s" % dist)

sim = np.dot(embedding1, embedding2.T)
print("Similarity => %s" % sim)

Thanks

KleinYuan commented 6 years ago
  1. It's in the graph and I found this while freeze the model, check this out

  2. Currently, I got the inference model from this repo and if you see the link there, they put droupout_rate as a tf placeholder, which means you need to provide the value necessarily.

--> To your question, the value could be 1.0

yippeesoft commented 5 years ago

test_img = cv2.imread('tests/test.jpg') test_img2 = cv2.imread('tests/obama.jpg')

Similarity => [[0.9402864]]