简体   繁体   English

无法使用 python 从 Azure 数据湖中加载 tensorflow keras model

[英]Trouble loading tensorflow keras model in databricks from Azure data lake using python

I have a model that I saved inside a project_name in a container in azure data lake.我有一个 model,我保存在 azure 数据湖中容器中的 project_name 中。 I am having issues when loading a tensorflow model from databricks.从数据块加载 tensorflow model 时遇到问题。 Everything is already working fine as I tested out in jupyter notebook previously.正如我之前在 jupyter notebook 中测试的那样,一切都已经运行良好。 I have to migrate the code in databricks.我必须迁移数据块中的代码。

This is a code I ran.这是我运行的代码。

model = tf.keras.models.load_model("abfss://dev@abcproddatalake.dfs.core.windows.net/hkay/project_name/model/keras2.tf", compile=False)

This is the error I'm getting.这是我得到的错误。

UnimplementedError                        Traceback (most recent call last)
<command-3129204037083358> in <module>
      3 
      4 ## Loading a model
----> 5 model = tf.keras.models.load_model("abfss://dev@abcproddatalake.dfs.core.windows.net/hkay/project_name/model/keras2.tf", compile=False)

/local_disk0/.ephemeral_nfs/envs/pythonEnv-03228642-df50-44d1-8e0e-f760ea5a0429/lib/python3.8/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

/local_disk0/.ephemeral_nfs/envs/pythonEnv-03228642-df50-44d1-8e0e-f760ea5a0429/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py in file_exists_v2(path)
    288   """
    289   try:
--> 290     _pywrap_file_io.FileExists(compat.path_to_bytes(path))
    291   except errors.NotFoundError:
    292     return False

UnimplementedError: File system scheme 'abfss' not implemented (file: 'abfss://dev@abcproddatalake.dfs.core.windows.net/hkay/project_name/model/keras2.tf')

It was running fine when I ran it in jupyter notebook.当我在 jupyter notebook 中运行它时,它运行良好。 The model was saved locally when I was using jupyter. model是我用jupyter时保存在本地的。

The connection is working because I tested out the connection through reading the files from the path.连接正常,因为我通过从路径读取文件测试了连接。 The size of this model is 1.6 GB.这个 model 的大小是 1.6 GB。 I am not sure why it is not working.我不确定为什么它不起作用。 Anyone has any idea?有人知道吗?

Unfortunately, Keras doesn't understand URIs.不幸的是,Keras 不理解 URI。 it is designed to work only with local files,so you need to use local path saving or loading data.它被设计为仅适用于本地文件,因此您需要使用本地路径保存或加载数据。

Try to use dbutils.fs.cp it will copy data from Storage URL abfss://dev@axxx to local path.尝试使用dbutils.fs.cp它将数据从 Storage URL abfss://dev@axxx到本地路径。

Copy file into /tmp/model.tf and load it.将文件复制到/tmp/model.tf并加载它。

#Setup storage configuration
spark.conf.set("fs.azure.account.key.<storage_account_name>.blob.core.windows.net","<access_key>")

dbutils.fs.cp("abfss://dev@abcproddatalake.dfs.core.windows.net/hkay/project_name/model/keras2.tf","/tmp/Demo_model.tf")

you can check weather model copied or not using below code.您可以使用以下代码检查天气 model 是否已复制。

display(dbutils.fs.ls("/tmp/Demo_model.tf"))

Loading model:正在加载 model:

from tensorflow import keras
model = keras.models.load_model("/tmp/Demo_model.tf")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Databricks 在 Apache Spark 中安装 Azure 数据湖时出错 - Error Mounting Azure Data Lake in Apache Spark using Databricks 从数据湖重命名 Azure Databricks 中的文件时出现问题 - Problem when rename file in Azure Databricks from a data lake Azure 数据湖 - 使用 Python 读取 - Azure data lake - read using Python 如何从Azure Data Lake Store中读取Azure Databricks中的JSON文件 - How to read a JSON file in Azure Databricks from Azure Data Lake Store 从Azure Data Lake将平面文件加载到数据框中时出现问题 - Problem loading a flat file into a data frame from Azure Data Lake 从 Azure Data Lake Storage Gen 2 读取 CSV 到 Pandas Dataframe | 没有数据块 - Read CSV from Azure Data Lake Storage Gen 2 to Pandas Dataframe | NO DATABRICKS 如何将 SQL 查询的结果从 Databricks 导出到 Azure Data Lake Store - How to Export Results of a SQL Query from Databricks to Azure Data Lake Store 使用 tensorflow 创建模型时加载数据时遇到问题 - Trouble loading data for creating models using tensorflow Keras中模型的麻烦加载权重 - Trouble Loading Weights of a model in Keras 使用 python 将文件从 azure 数据湖 Gen 1 移动到临时目录 - move file from azure data lake Gen 1 to a temp directory using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM