NumPy’s linalg.norm is useful for computing the Euclidean distance. The similarity between the query image and target database can be computed between the images by calculating the Euclidean distances between the features as shown here:

dist = np.linalg.norm(np.asarray(query_feature) - np.asarray(target_feature))

Running this command should print the following:


This is the metric that can be used for similarity calculation. The smaller the Euclidean distance between the query and the target image is, the more similar the images are. Hence, computing the Euclidean distance is a measurement of similarity. Using the features for computing the Euclidean distance is based on the assumption that the features are learned during the training of the model. Scaling this computation for millions of images is not efficient. In a production system, it is expected to return the results in milliseconds.