What is the python code to load dataset from my hard disk

Viewed 395

I try to learn machine learning from the TensorFlow official tutorial.

But most tutorials do the download in command prompt.

I can't find any tutorial about loading my own image dataset from my own disk.

Would be great if you can give me a direct answer.

I put the image data set on my window 10 desktop:

C:\Users\User\Desktop\DataSet\coins\data

\test (label 1-211)

\train (label 1-211)

\validation (label 1-211)
2 Answers

You can use image_dataset_from_directory for this where you just have to pass in the path to the files in the argument directory.

from tensorflow.keras.preprocessing import image_dataset_from_directory

train_dataset = image_dataset_from_directory(
    directory=TRAIN_DIR,
    labels="inferred",
    label_mode="categorical",
    image_size=SIZE,
    seed=SEED,
    subset=None,
    interpolation="bilinear",
    follow_links=False,
)

validation_dataset = image_dataset_from_directory(
    directory=VALIDATION_DIR,
    labels="inferred",
    label_mode="categorical",
    image_size=SIZE,
    seed=SEED,
    subset=None,
    interpolation="bilinear",
    follow_links=False,
)

test_dataset = image_dataset_from_directory(
    directory=TEST_DIR,
    labels="inferred",
    label_mode="categorical",
    image_size=SIZE,
    seed=SEED,
    subset=None,
    interpolation="bilinear",
    follow_links=False,
)
Related