Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中使用AzureCognitiveServices中经过培训的分类器与Keras_Python_Azure_Tensorflow_Keras_Azure Cognitive Services - Fatal编程技术网

如何在Python中使用AzureCognitiveServices中经过培训的分类器与Keras

如何在Python中使用AzureCognitiveServices中经过培训的分类器与Keras,python,azure,tensorflow,keras,azure-cognitive-services,Python,Azure,Tensorflow,Keras,Azure Cognitive Services,我对认知视觉API模型进行了培训,并将其导出(尝试了两种格式:TensorFlow和SavedModel) 现在我想用Python脚本加载这个导出的模型,理想情况下使用Keras而不是本机Tensorflow。我想打印出模型的summary(),并复制层以在自定义Python脚本中重新训练它 然而,我似乎无法实现这一点: 使用SavedModel格式加载此文件 使用以下代码: 将tensorflow导入为tf loaded=tf.saved\u model.load(导出\u dir='mydi

我对认知视觉API模型进行了培训,并将其导出(尝试了两种格式:TensorFlow和SavedModel)

现在我想用Python脚本加载这个导出的模型,理想情况下使用Keras而不是本机Tensorflow。我想打印出模型的
summary()
,并复制层以在自定义Python脚本中重新训练它

然而,我似乎无法实现这一点:

使用SavedModel格式加载此文件

使用以下代码:

将tensorflow导入为tf
loaded=tf.saved\u model.load(导出\u dir='mydir/savedmodel')
已加载。摘要()
我得到以下异常:
'AutoTrackable'对象没有属性“summary”
,并且似乎load方法返回了一个
AutoTrackable
,而不是一个模型

使用GraphDef

从下面的代码中,创建了一个TensorFlow特定的类型,我真的不知道如何转换为Keras模型

将tensorflow导入为tf
导入操作系统
graph_def=tf.compat.v1.GraphDef()
标签=[]
#这些将设置为导出模型的默认名称,并根据需要进行更新。
文件名='mydir/tf/model.pb'
labels\u filename=“mydir/tf/labels.txt”
#导入TF图
将tf.io.gfile.gfile(文件名“rb”)作为f:
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def,name='')
#创建标签列表。
将打开的标签(文件名为“rt”)作为lf:
对于lf中的l:
labels.append(l.strip())

TensorFlow保存的模型​ 格式化以在运行时加载模型。

可以使用Python脚本导出模型,该脚本加载模型,创建签名,然后以保存的模型格式保存模型

当我们上传并读取文件进行注册时将其保存。如果您使用./output将文件发送到output,则在train.py脚本中,您只需执行以下操作:

#persist the model to the local machine
tf.saved_model.save(model,'./outputs/model/')

#register the model with run object
run.register_model(model_name,'./outputs/model/')
我发现下面的链接显示我可以将估计器导出为tf.saved_模型


能否共享用于将TensorFlow签出导出为保存模型的脚本。导出模型脚本执行许多操作以准备模型进行推断:创建并验证服务签名将变量转换为常量(也称为图形冻结)。输出保存的模型