[英]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.