从python函数检索结果

时间:2019-02-13 10:45:02

标签: python python-3.x function

我对python很陌生。任何帮助将不胜感激。

extension String{ func convertHtmlToAttributedString() -> NSAttributedString{ guard let data = data(using: .utf8) else { return NSAttributedString() } do{ return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil) }catch{ return NSAttributedString() } } } 的输入是图像verifyFace,所以我要从函数format.jpg中检索euclidean_distance的结果

verifyFace

这就是我想要的(示例):

epsilon = 6.384185791015625e-08
import matplotlib.pyplot as plt
import numpy as np

第二个问题检索完两个元素后,我如何仅选择第二个元素恢复

x = from verifyFace get euclidean_distance

1 个答案:

答案 0 :(得分:1)

if (cosine_similarity < epsilon):块位于函数定义内部,而不位于外部。另外,您需要在函数内部传递epsilon

def verifyFace(img1, img2, epsilon):
    img1_representation = vgg_face_descriptor.predict(preprocess_image(img1))[0, :]
    img2_representation = vgg_face_descriptor.predict(preprocess_image(img2))[0, :]

    cosine_similarity = findCosineSimilarity(img1_representation, img2_representation)
    euclidean_distance = findEuclideanDistance(img1_representation, img2_representation)

    if (cosine_similarity < epsilon):
        print("verified... they are same person")
        return '1', euclidean_distance 
    else:
        print("unverified! they are not same person!")
        return '0', euclidean_distance 

编辑:

如果要从函数返回多个值:

return '1', euclidean_distance 

并且在收到时:

ret_val, euclidean_distance = verifyFace(your_img1, your_img2, your_epsilon)