英文:
NotFOundError : could not find directory C://Users/Admin/Downloads/assignment2/train
问题
I'm Korean and I'm not good at writing in English.
请理解我的英语不好。
An error occurs.
出现错误。
"NotFoundError: Could not find directory C://Users/Admin/Downloads/assignment2/train"
“NotFoundError: 找不到目录 C://Users/Admin/Downloads/assignment2/train”
如何解决这个问题?
Here is the code that I wrote.
以下是我写的代码。
英文:
I'm Korean and I'm not good at writing in english.
Please understand my poor english.
An error occurs.
"NotFoundError: Could not find directory C://Users/Admin/Downloads/assignment2/train"
how can I solve this problem?
Here is the code that I wrote.
import os
import tensorflow as tf
from tensorflow import keras
base_dir = 'C:/Users/Admin/Downloads/assignment2'
train_dir = os.path.join(base_dir, 'train')
test_dir = os.path.join(base_dir, 'test')
batch_size = 32
num_of_train_imgs = 3934
num_of_test_imgs = 1966
img_height = 50
img_width = 50
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
train_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=num_of_train_imgs)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
train_dir,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=num_of_train_imgs)
test_ds = tf.keras.preprocessing.image_dataset_from_directory(
test_dir,
image_size=(img_height, img_width),
batch_size=num_of_test_imgs)
答案1
得分: 1
这意味着目录 'C://Users/Admin/Downloads/assignment2/train' 不存在。因此,在你得到目录后,请确保它存在,如果不存在,请创建一个。以下是解决方案:
base_dir = 'C:/Users/Admin/Downloads/assignment2'
train_dir = os.path.join(base_dir, 'train')
if not os.path.exists(train_dir):
os.mkdir(train_dir)
test_dir = os.path.join(base_dir, 'test')
if not os.path.exists(test_dir):
os.mkdir(test_dir)
英文:
This means the directory 'C://Users/Admin/Downloads/assignment2/train' is not existed. So, after you have your directory, make sure it is existed, if not, create one. Here is the solution:
base_dir = 'C:/Users/Admin/Downloads/assignment2'
train_dir = os.path.join(base_dir, 'train')
if not os.path.exists(train_dir):
os.mkdir(train_dir)
test_dir = os.path.join(base_dir, 'test')
if not os.path.exists(test_dir):
os.mkdir(test_dir)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论