Python 如何将图像数据集加载到TensorFlow中?
我是TensorFlow的新手,我正试图在Google Colaboratory中构建一个小型神经网络。该网络的目标是根据图像识别个人的职业。我有900张不同的图片,每一张都是针对10个不同的工作的,作为我的培训数据,还有200张来自这些工作的图片作为我的测试数据。测试和培训数据都下载到我的电脑上。如果您有任何帮助,我们将不胜感激。请先将您的谷歌硬盘安装到CollaboratoryPython 如何将图像数据集加载到TensorFlow中?,python,python-3.x,image,tensorflow,tensorflow2.0,Python,Python 3.x,Image,Tensorflow,Tensorflow2.0,我是TensorFlow的新手,我正试图在Google Colaboratory中构建一个小型神经网络。该网络的目标是根据图像识别个人的职业。我有900张不同的图片,每一张都是针对10个不同的工作的,作为我的培训数据,还有200张来自这些工作的图片作为我的测试数据。测试和培训数据都下载到我的电脑上。如果您有任何帮助,我们将不胜感激。请先将您的谷歌硬盘安装到Collaboratory from google.colab import drive drive.mount('/content/driv
from google.colab import drive
drive.mount('/content/drive')
培训和测试数据所在目录的路径
train_dir = '/content/drive/Training'
test_dir = '/content/drive/Testing'
创建用于培训和测试的数据生成器
train_datagen = ImageDataGenerator(**datagen_kwargs)
test_datagen = ImageDataGenerator(**datagen_kwargs)
train_data = train_datagen.flow_from_directory(
train_dir,
target_size = (img_width, img_height),
shuffle=True,
batch_size = batch_size,
classes = list(class_names))
test_data = test_datagen.flow_from_directory(
test_dir,
target_size = (img_width, img_height),
shuffle=True,
batch_size = batch_size,
classes = list(class_names))
有关更多信息,请参阅此首先将您的Google Drive装载到Collaboratory
from google.colab import drive
drive.mount('/content/drive')
培训和测试数据所在目录的路径
train_dir = '/content/drive/Training'
test_dir = '/content/drive/Testing'
创建用于培训和测试的数据生成器
train_datagen = ImageDataGenerator(**datagen_kwargs)
test_datagen = ImageDataGenerator(**datagen_kwargs)
train_data = train_datagen.flow_from_directory(
train_dir,
target_size = (img_width, img_height),
shuffle=True,
batch_size = batch_size,
classes = list(class_names))
test_data = test_datagen.flow_from_directory(
test_dir,
target_size = (img_width, img_height),
shuffle=True,
batch_size = batch_size,
classes = list(class_names))
有关更多信息,请参阅此,这是否回答了您的问题?这回答了你的问题吗@noahmessijr,如果答案回答了你的问题,你能接受并投票表决吗。感谢You@noahmessijr,如果答案能回答你的问题,请你接受并投赞成票。非常感谢。