![](/img/trans.png)
[英]Getting warning message after importing data into a python IBM watson Studio
[英]Importing scripts into a notebook in IBM WATSON STUDIO
我正在 IBM WATSON Studio 免费版上的 CIFAR 10 图像上进行 PCA,所以我上传了用于在工作室上下载 CIFAR10 的 python 文件
在谷歌上花了一些时间后,我找到了一个解决方案,但我无法理解。 链接https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/add-script-to-notebook.html
the solution is as follows:-
Click the Add Data icon (Shows the Add Data icon), and then browse the script file or drag it into your notebook sidebar.
Click in an empty code cell in your notebook and then click the Insert to code link below the file. Take the returned string, and write to a file in the file system that comes with the runtime session.
To import the classes to access the methods in a script in your notebook, use the following command:
For Python:
from <python file name> import <class name>
我无法理解这一行
` 并写入运行时会话附带的文件系统中的文件。``
在哪里可以找到运行时会话附带的文件? 文件系统位于何处?
任何人都可以帮助我了解在哪里可以找到该文件的详细信息
您有导入错误,因为您要导入的脚本在Python运行时的本地文件系统中不可用。 您上载的文件( cache.py
, cifar10.py
等)被上载到与Watson Studio项目关联的对象存储桶中。 要使用这些文件,您需要使它们可用于Python运行时,例如,将脚本下载到运行时本地文件系统。
更新:同时,有一个选项可以直接插入StreamingBody对象。 这还将包括所有必需的凭据。 如果使用insert StreamingBody object
选项,则可以跳过此操作, writing it to a file in the local runtime filesystem
此答案writing it to a file in the local runtime filesystem
部分。
要么,
您可以使用下面的代码片段读取StreamingBody对象中的脚本:
import types
import pandas as pd
from botocore.client import Config
import ibm_boto3
def __iter__(self): return 0
os_client= ibm_boto3.client(service_name='s3',
ibm_api_key_id='<IBM_API_KEY_ID>',
ibm_auth_endpoint="<IBM_AUTH_ENDPOINT>",
config=Config(signature_version='oauth'),
endpoint_url='<ENDPOINT>')
# Your data file was loaded into a botocore.response.StreamingBody object.
# Please read the documentation of ibm_boto3 and pandas to learn more about the possibilities to load the data.
# ibm_boto3 documentation: https://ibm.github.io/ibm-cos-sdk-python/
# pandas documentation: http://pandas.pydata.org/
streaming_body_1 = os_client.get_object(Bucket='<BUCKET>', Key='cifar.py')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(streaming_body_1, "__iter__"): streaming_body_1.__iter__ = types.MethodType( __iter__, streaming_body_1 )
然后将其写入本地运行时文件系统中的文件。
f = open('cifar.py', 'wb')
f.write(streaming_body_1.read())
这将打开一个具有写访问权的文件,并调用write
方法写入该文件。 然后,您应该能够简单地导入脚本。
import cifar
注:通过单击文件下拉菜单上的“ Insert credentials
选项,可以获取文件的凭证,例如IBM_API_KEY_ID
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.