简体   繁体   English

在谷歌云存储中访问 Spacy 的训练模型/文件夹

[英]Access Spacy's trained model/folder in google cloud storage

I was deploying a python application which uses Spacy's custom trained model on GAE.我正在部署一个 python 应用程序,它在 GAE 上使用 Spacy 的自定义训练 model。 I have also uploaded model folder in Google Cloud Storage but am facing issues in getting only folder from storage bucket and using that to load in spacy.我还在 Google Cloud Storage 中上传了 model 文件夹,但在仅从存储桶中获取文件夹并使用它加载 spacy 时遇到了问题。

Right now, if I am trying to get a blob, I can get only one file, not a folder.现在,如果我试图获取一个 blob,我只能获取一个文件,而不是一个文件夹。

Please help me.请帮我。

FYI, Spacy's custom trained and saved model is a folder that contains multiple files.仅供参考,Spacy 的自定义训练和保存 model 是一个包含多个文件的文件夹。 Thanks谢谢

EDIT 1:编辑 1:

This is the directory structure of saved model这是model保存的目录结构

在此处输入图像描述

Google Cloud Storage doesn't have folders in the reality, what you see as folders are just a representation, you can see a more detailed explanation here .谷歌云存储在现实中并没有文件夹,你看到的文件夹只是一种表象,你可以在这里看到更详细的解释。

What you have to do is to fetch all the files inside of a "folder" recursively.您要做的是递归地获取“文件夹”内的所有文件。 ie: IE:

import sys
from google.cloud import storage
from google.cloud.storage.blob import Blob


client = storage.Client()
for blob in client.list_blobs('mybucket', prefix='sofolder'):
    blobname = blob.name
    blobstring = str(blobname)
    blobcleaname = blobstring.rsplit('/', 1)[-1]
    if not blobstring.endswith('/'):
        blob.download_to_filename('./' + str(blobcleaname))
        print(blobstring)

Update 1:更新 1:

So I did a quick reproduction of your use case by just printing to console the name of my bucket.所以我通过打印来快速复制你的用例来控制我的存储桶的名称。 I have a structure similar to yours:我有一个类似于你的结构:

bucketname
    -filexxx 
    -folderyyy
    -sofolder <--- the folder i'm interested in
      -file1.png
      -folder_a
        -fileinfolder_a.png
      -folder_b
        -fileinfolder_b.png
      -folder_c
        -fileinfolder_c.png

and by runnning this:通过运行这个:

import sys
from google.cloud import storage
from google.cloud.storage.blob import Blob

client = storage.Client()
for blob in client.list_blobs('bucketname', prefix='sofolder'):
    blobname = blob.name
    blobstring = str(blobname)
    if not blobstring.endswith('/'):
        print(blobstring)

I'm getting this output:我收到这个 output:

sofolder/
sofolder/file1.png
sofolder/folder_a/fileinfolder_a.png
sofolder/folder_b/fileinfolder_b.png
sofolder/folder_c/fileinfolder_c.png

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM