【问题标题】:Data loader for a mounted drive on google colabgoogle colab 上已安装驱动器的数据加载器
【发布时间】:2020-11-10 04:38:19
【问题描述】:

我将 colab 与已安装的谷歌驱动器一起使用,其中我有一个包含 2000 张图像的文件夹作为数据集。我正在寻找一种更好的方式来加载它们,因为即使在第一个时期,以下内容也需要花费大量时间。谢谢大家:)。

def decode_img(img):
  img = tf.image.decode_jpeg(img,channels=3)
  img = tf.image.convert_image_dtype(img, tf.float32)
  img = (img - 0.5)/0.5
  img = tf.image.resize(img, [IMG_SIZE,IMG_SIZE])
  if tf.random.uniform(()) > 0.5:
    img = tf.image.flip_left_right(img)
  img = tf.image.random_crop(img, size=[IMG_SIZE,IMG_SIZE,3])
  return img

def process_path(file_path):
  img = tf.io.read_file(file_path)
  img = decode_img(img)
  return img

train_dataset = tf.data.Dataset.list_files(data_path+'/*.jpg', shuffle = True)
train_dataset = train_dataset.map(process_path, num_parallel_calls=tf.data.experimental.AUTOTUNE)
train_dataset = train_dataset.shuffle(BUFFER_SIZE).batch(BATCH_SIZE)

【问题讨论】:

  • 一些消息来源声称谷歌驱动器连接器非常慢,并建议将数据从谷歌驱动器复制到colab:!cp -r $data_path .您可以从那里调用数据加载,它应该更快。

标签: tensorflow dataset google-colaboratory loader drive


【解决方案1】:

我遇到了类似的问题,瓶颈是从 Gdrive 加载我的图像。如果合适,将所有图像加载到 colab 磁盘应该会大大加快速度。将数据上传到 colab 后,此代码会将其加载到磁盘。

!mkdir train_local
!unzip train.zip -d train_local

【讨论】:

    猜你喜欢
    • 2020-07-25
    • 2021-09-01
    • 1970-01-01
    • 2019-12-17
    • 2019-07-17
    • 2018-10-14
    • 2016-05-03
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多