【发布时间】:2020-12-06 02:50:04
【问题描述】:
我在 Google Cloud Storage 上有一个存储桶,其中包含用于 TensorFlow 模型训练的图像。我正在使用tensorflow_cloud 加载存储在名为stereo-train 的存储桶中的图像,并且包含图像的目录的完整URL 是:
gs://stereo-train/data_scene_flow/training/dat
但是在tf.keras.preprocessing.image_dataset_from_directory函数中使用这个路径,我在谷歌云控制台的日志中得到错误:
FileNotFoundError: [Errno 2] No such file or directory: 'gs://stereo-train/data_scene_flow/training/dat'
如何解决这个问题?
代码:
GCP_BUCKET = "stereo-train"
kitti_dir = os.path.join("gs://", GCP_BUCKET, "data_scene_flow")
kitti_training_dir = os.path.join(kitti_dir, "training", "dat")
ds = tf.keras.preprocessing.image_dataset_from_directory(kitti_training_dir, image_size=(375,1242), batch_size=batch_size, shuffle=False, label_mode=None)
即使我使用以下内容,它也不起作用:
filenames = np.sort(np.asarray(os.listdir(kitti_train))).tolist()
# Make a Dataset of image tensors by reading and decoding the files.
ds = list(map(lambda x: tf.io.decode_image(tf.io.read_file(kitti_train + x)), filenames))
tf.io.read_file 而不是 keras 函数,我得到了同样的错误。如何解决这个问题?
【问题讨论】:
-
你不能“修复它”,只是所有的 keras 函数都不接受谷歌云 URL,只有正常的文件系统路径。
-
Keras 函数的替代方案是什么?
-
即使我使用以下内容: filenames = np.sort(np.asarray(os.listdir(kitti_train))).tolist() # 通过读取和解码文件来制作图像张量数据集. ds = list(map(lambda x: tf.io.decode_image(tf.io.read_file(kitti_train + x)), filenames)) 我得到同样的错误。
标签: python tensorflow keras google-cloud-platform