python - 获取 token 以使用 Python 将表单识别器自定义模型从一个帐户共享到另一个帐户

标签 python azure azure-form-recognizer

Form Recognizer Studio 可以选择共享和导入自定义创建的模型。它为模型生成一个 token ,可以共享该 token 并将其导入到另一个帐户中。

我想使用 Python 脚本获取此 token 。有什么办法可以用Python来完成这个任务吗? 谢谢!

我尝试使用下面的代码

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import FormTrainingClient

client = FormTrainingClient(endpoint, AzureKeyCredential(key))

target = client.get_copy_authorization(resource_id="", resource_region="eastus")

使用此代码,我可以获得 accessToken,但这与资源组相关联。我想获得 token 来共享自定义构建的表单识别器模型。

最佳答案

According to the solution in this github issue, Refer here:- TypeError: in method 'IndexFlat_add', argument 3 of type 'float const *' · Issue #461 · facebookresearch/faiss · GitHub Make sure the generated vector types or array is of numpy.float32

代码 1:-

import numpy as np
d = 128
n = 10000
xb = np.random.rand(n, d).astype(np.float32)

vector = [0.5] * d
vector = np.array(vector).astype(np.float32)

distances = np.linalg.norm(xb - vector, axis=1)

k = 5
indices = np.argsort(distances)[:k]

print("Distances:", distances[indices])
print("Indices:", indices)

上面的代码带有 faiss 库。

import numpy as np
import faiss

d = 128
n = 10000
index = faiss.IndexFlatL2(d)
xb = np.random.rand(n, d).astype(np.float32)

index.add(xb)

vector = [0.5] * d
vector = np.array(vector).astype(np.float32)
k = 5
distances, indices = index.search(np.array([vector]), k)

print("Distances:", distances)
print("Indices:", indices)

输出:-

enter image description here

代码 2:-

import numpy as np

d = 128

n = 10000

x = np.random.rand(n, d).astype(np.float32)

print (x)

输出:-

enter image description here

关于python - 获取 token 以使用 Python 将表单识别器自定义模型从一个帐户共享到另一个帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76032069/

相关文章:

从 SAP Hana 复制到 Data Lake Store 时,Azure Data Pipeline 复制事件丢失列名称

powershell - 如何在 VSTS 任务中使用最新的 AzureRM

azure - 如何将 Microsoft.Azure.CognitiveServices.FormRecognizer v0.8.0-preview API 端点更改为 v.2.0.0?

azure - 保存自定义模型 Azure 表单识别器时出错

python - 根据正则表达式拆分字符串

用于 Visual Studio 和原始突出显示的 python 工具?

python - 在 groupby() Pandas 之后将多索引转换为单索引

c# - Azure 函数忽略的functions.json graphToken 绑定(bind)

azure - 表单识别器标签 - 训练模型

python - 使用 OpenCV 检测灰色事物