Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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:UsersUserDesktopDataSetcoinsdata

est (label 1-211)

rain (label 1-211)

validation (label 1-211)
question from:https://stackoverflow.com/questions/65850525/what-is-the-python-code-to-load-dataset-from-my-hard-disk

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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,
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...