【发布时间】:2021-07-12 18:46:52
【问题描述】:
我使用 (python) 从我的云存储桶下载我的图像:
storage_client = storage.Client()
bucket = storage_client.get_bucket('mybucket')
blob = bucket.blob('myimage.png')
img = blob.download_as_bytes(raw_download=True)
然后使用张量流,我将图像转换为张量,并返回图像的形状。
image = tf.io.decode_image(img, dtype = tf.dtypes.float32)
image = tf.expand_dims(image, axis=0)
shape = image.shape
return {"1":shape}
当我测试函数时,我收到 {1": ""},就像我在本地机器上运行代码一样,我将收到张量/图像的实际形状 (1, 224 , 224, 3)。我不明白为什么这适用于我的本地机器,但不适用于云功能。
【问题讨论】:
-
你没有问题/错误?这就像如果有一个错误。可能是因为有依赖没有安装或者不兼容
-
我没有任何问题/错误——只返回这个应该是张量形状的“未知”。由于我已经发布了虽然我已经进行了更多调查并且我认为这是因为函数 tf.io.decode- 我索引到 img 字节并正确返回这些,例如 return img[0] 我收到了字节值,但是如果我改为返回 image[0,0,0],我会收到 'stridedslice0'
-
我不确定为什么这个函数不起作用——我指定了包含 tensorflow 2.4 的运行时 2.4。这应该包括 tf.io
-
澄清一下,我收到 { "predictions": "Tensor(\"strided_slice:0\", shape=(), dtype=float32)" }
-
我已经弄清楚了,在这个云环境中,Eager Execution 似乎默认被禁用。所以在解决问题之前调用 tf.compat.v1.enable_eager_execution() 。奇怪的是为什么默认情况下禁用它...
标签: tensorflow google-cloud-platform google-cloud-functions google-cloud-storage google-ai-platform