简体   繁体   English

在tensorflow / keras中加载自定义数据集

[英]Load custom dataset in tensorflow/keras

So in this code author is using MNIST dataset and i wanna use my own dataset which consist of images. 所以在这段代码中,作者正在使用MNIST数据集,我想使用我自己的数据集,其中包含图像。 I dont know how can give path to my own dataset here? 我不知道如何在这里提供我自己的数据集的路径?

(train_images, _), (test_images, _) = tf.keras.datasets.mnist.load_data()



# Load the dataset
(train_images, _), (test_images, _) = tf.keras.datasets.mnist.load_data()
train_images = train_images.reshape(train_images.shape[0], 
                                            config.raw_size,
                                            config.raw_size,
                                            config.channels)
# Add noise for condition input
train_inputs = artefacts.add_gaussian_noise(train_images, stdev=0.2, data_range=(0, 255)).astype('float32')
train_inputs = data_processing.normalise(train_inputs, (-1, 1), (0, 255))
train_images = data_processing.normalise(train_images, (-1, 1), (0, 255))
train_labels = train_images.astype('float32')

train_dataset = tf.data.Dataset.from_tensor_slices((train_inputs, train_labels))\
            .shuffle(config.buffer_size).batch(config.batch_size)

# Test set
test_images = test_images.reshape(test_images.shape[0], 
                                        config.raw_size,
                                        config.raw_size,
                                        config.channels)
test_inputs = artefacts.add_gaussian_noise(test_images, stdev=0.2, data_range=(0, 255)).astype('float32')
test_inputs = data_processing.normalise(test_inputs, (-1, 1), (0, 255))
test_images = data_processing.normalise(test_images, (-1, 1), (0, 255))
test_labels = test_imag

es.astype('float32')

If you have a data set of images in a folder named foldername of type .jpeg , would the following solution meet your needs? 如果您在名为foldername的类型为.jpeg的文件夹中有图像数据集,那么以下解决方案是否满足您的需求?

import glob

import numpy as np
from matplotlib.pyplot import imread

foldername = "YOUR FOLDER NAME"

# load in the images as a numpy array of shape (number images x width x height x channels)
image_array = np.array([imread(im) for im in glob.glob(f"{foldername}/*.jpeg")])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM