我如何加载本地图像以在张量流中训练模型

How can i Load local images to train model in tensorflow

我正在尝试构建一个 CNN 来区分汽车和自行车。但是,我在此处的劳伦斯示例中看到了马和人的相同示例。但是我没有从某个库中加载数据,而是下载了近 5000 张汽车和自行车的图像,并将它们按照视频中建议的文件夹进行隔离。但是如何加载本地文件来训练我的模型呢?我正在尝试使用以下代码。但它给了我一个找不到文件的异常。 Here is the link to my colab am trying to do.

import os

# Directory with our training cycle pictures
train_cycle_dir = os.path.join('C:/Users/User/Desktop/Tensorflow/PrivateProject/Images/training/cycle')

# Directory with our training car pictures
train_car_dir = os.path.join('C:/Users/User/Desktop/Tensorflow/PrivateProject/Images/training/cars')

# Directory with our training cycle pictures
validation_cycle_dir = os.path.join('C:/Users/User/Desktop/Tensorflow/PrivateProject/Images/validation/cycle')

# Directory with our training car pictures
validation_car_dir = os.path.join('C:/Users/User/Desktop/Tensorflow/PrivateProject/Images/validation/cars')

您无法直接从 colab 访问计算机上的文件。如果您的 google 驱动器上有足够的 space,您可以将它们上传到您的 google 驱动器并像 here or with the "Mount Drive" button on the files sidebar. There's also a button to upload files from your computer there. But if you upload them to colab, you have to do it again after 12 hours when the runtime resets. (you can read it here)

一样安装它