使用 S3FS

问题描述

我正在构建一个 TFX 管道,其中包含来自 S3 存储桶的输入图像。在 TF 转换组件步骤中,我尝试读取一系列图像,其 URL 以 TFX 的 SparseTensor 格式存储。我正在尝试使用 S3FS Python 模块来执行此操作,因为我一直在将它用于管道的其他组件,并且听说同时使用 Boto3 和 S3FS 会导致问题(我认为这与此无关)。>

无论如何,我已经建立了与 S3 存储桶的连接,并正在尝试读取图像。这是我的代码(或者至少是我认为与问题密切相关的部分):

  s3 = s3fs.S3FileSystem()

  with s3.open(str(inputs[key]),'rb') as f:
    for key in CV_FEATURES:
      img = np.array(Image.open(io.BytesIO(f.read())))
      img = tf.image.rgb_to_grayscale(img)
      img = tf.divide(img,255)
      img = tf.image.resize_with_pad(img,224,224)
      outputs[_fill_in_missing(key)] = img

  s3.clear_instance_cache()

运行此命令为我提供了我在尝试访问包含无效字符的存储桶时看到的标准错误消息:

ParamValidationError:参数验证失败: 无效的存储桶名称 "SparseTensor(indices=Tensor("inputs": Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" 或者是匹配正则表达式 "^arn: (aws).:(s3|s3-object-lambda):[az-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9- ]{1,63}$|^arn:(aws).:s3-outposts:[az-0-9]+:[0-9]{12}:outpost[/:][a- zA-Z0-9-]{1,63}[/:]接入点[/:][a-zA-Z0-9-]{1,63}$"

错误表明问题出在 with s3.open(str(inputs[key]),'rb') as f: 行上,所以我需要以某种方式正确表示 S3 URL。 URL 以 bucket_name\key\file.jpg 格式存储在原始 CSV 数据集中名为 image_path 的列中(在此之前转换为 SparseTensor,在上面的代码中表示为 inputs[key]) .

我认为问题不在于 SparseTensor 格式,而在于 URL。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)