【问题标题】:I do not know what is wrong with my function我不知道我的功能有什么问题
【发布时间】:2022-01-09 10:39:37
【问题描述】:

我有这个代码。但是我无法将其作为函数运行。

def verify_result_same():
    if verify_result_same.is_identical() & verify_result_same.confidence() > 0.5:
            face_client.face.verify_face_to_face(source_image1_id, detected_faces_ids[0])
            print('Faces from {} & {} are of the same person, with confidence: {}'
            .format(source_image_file_name1, target_image_file_names[0], verify_result_same.confidence))
            print("Valid face verification")

    else: 
            print('Faces from {} & {} are of a different person, with confidence: {}'
            .format(source_image_file_name1, target_image_file_names[0], verify_result_same.confidence))
            print("Invalid face verification")
            text = "Face verification is not valid. Please try again."
            send_msg(text)

我收到如下错误:

AttributeError: 'function' object has no attribute 'is_identical'
AttributeError: 'function' object has no attribute 'confidence'

有人可以帮忙吗?

【问题讨论】:

  • is_identicalconfidence 是什么?你为什么要从verify_result_same给他们打电话?
  • 我不明白为什么这会起作用?这些变量声明在哪里,更重要的是,你不应该能够从函数中访问它们,也不能元调用函数并访问它。
  • 你在检查什么是 is_identicalconfidence,这个给定的函数?请扩展您的问题。
  • 使用f 字符串:f"some text {some_var}"

标签: python function attributes 3-tier


【解决方案1】:
if verify_result_same.is_identical() & verify_result_same.is_confident() < 0.5:

这里你使用了“verify_result_same”对象,它与你在上一行中定义的函数相同。

【讨论】:

    【解决方案2】:

    verify_result_same 是一个函数,您可能已经定义了一个名为verify_result_same 的类。因此,您应该将函数名称从 verify_result_same 重命名为其他名称。

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 2015-09-11
      • 2020-11-21
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多