NotFoundError:找不到目录C://Users/Admin/Downloads/assignment2/train

huangapple go评论67阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月10日 22:59:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定