ไม่สามารถโหลดภาพจากที่เก็บข้อมูล Google Cloud Storage ใน TensorFlow หรือ Keras

Aug 17 2020

ฉันมีที่เก็บข้อมูลบน Google Cloud Storage ที่มีรูปภาพสำหรับการฝึกโมเดล TensorFlow ฉันใช้tensorflow_cloudเพื่อโหลดรูปภาพที่เก็บไว้ในที่เก็บข้อมูลที่เรียกว่าstereo-trainและ URL แบบเต็มไปยังไดเร็กทอรีที่มีรูปภาพคือ:

gs://stereo-train/data_scene_flow/training/dat

แต่เมื่อใช้เส้นทางนี้ในtf.keras.preprocessing.image_dataset_from_directoryฟังก์ชันฉันได้รับข้อผิดพลาดในบันทึกใน Google Cloud Console:

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 ฉันได้รับข้อผิดพลาดเดียวกัน จะแก้ไขได้อย่างไร?

คำตอบ

1 mac13k Aug 17 2020 at 10:03

หากคุณใช้ Linux หรือ OSX คุณสามารถใช้Google Cloud Storage FUSEซึ่งจะช่วยให้คุณติดตั้งที่เก็บข้อมูลในเครื่องและใช้งานได้เหมือนกับระบบไฟล์อื่น ๆ ทำตามคู่มือการติดตั้งจากนั้นติดตั้งถังของคุณไว้ที่ใดที่หนึ่งในระบบของคุณเช่น:

mkdir /mnt/buckets
gcsfuse gs://stereo-train /mnt/buckets

จากนั้นคุณจะสามารถใช้เส้นทางจากจุดเชื่อมต่อในรหัสของคุณและโหลดเนื้อหาจากที่เก็บข้อมูลใน Keras