You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have I written custom code (as opposed to using a stock example script provided in Keras): yes
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS Big Sur, version 11.5.1
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below): 2.4.4 and 2.9.1
Python version: 3.8.13
Bazel version (if compiling from source): n/a
GPU model and memory: n/a
Exact command to reproduce: see below
Describe the problem.
Tensorflow 2.4.4's image_dataset_from_directory will output a raw Exception when a dataset is too small for a single image in a given subset (training or validation).
TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string.
Tensorflow 2.9.1's image_dataset_from_directory will output a different and now incorrect Exception under the same circumstances:
ValueError: No images found in directory base_dir. Allowed formats: ('.bmp', '.gif', '.jpeg', '.jpg', '.png')
This is even worse, as the message is misleading that we're not finding the directory. There are actually images in the directory, there's just not enough to make a dataset given the current validation split + subset.
Describe the current behavior.
Stated above.
Describe the expected behavior.
I expect this to raise an Exception saying "not enough images in the directory" or something more precise and related to the actual issue.
Standalone code to reproduce the issue.
The below code block was run with tensorflow~=2.4, Pillow==9.1.1, and numpy~=1.19 to run.
importosimportnumpyasnpimporttensorflowastffromPILimportImagebase_dir="base_dir"label="label"image_path=os.path.join(os.getcwd(), base_dir, label, "1.png")
# Make a randomly-generated PNG imageimage_size=128, 128image_data=np.random.randint(
low=0, high=256, size=image_size[0] *image_size[1] *3, dtype=np.uint8
)
image_data=image_data.reshape(*image_size, 3)
try:
dirname=os.path.split(image_path)[0]
os.makedirs(dirname)
print(f"Made directory path: {dirname}.")
exceptFileExistsError:
pass# Already createdImage.fromarray(image_data, "RGB").save(image_path)
print(f"Saved image at path {image_path}.")
# Convert that image to a Datasetdataset=tf.keras.preprocessing.image_dataset_from_directory(
base_dir, image_size=image_size, seed=42, validation_split=0.2, subset="training"
)
The text was updated successfully, but these errors were encountered:
@jamesbraza Its clearly mentioned in the document that Directory where the data is located. If labels is "inferred", it should contain subdirectories, each containing images for a class. Otherwise, the directory structure is ignored.
Can you please explain the usecase where one image is used or the users run into this scenario. Thank!!
System information.
Describe the problem.
Tensorflow 2.4.4's
image_dataset_from_directory
will output a rawException
when a dataset is too small for a single image in a given subset (training
orvalidation
).See TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string where many people have hit this raw
Exception
message.Tensorflow 2.9.1's
image_dataset_from_directory
will output a different and now incorrectException
under the same circumstances:This is even worse, as the message is misleading that we're not finding the directory. There are actually images in the directory, there's just not enough to make a dataset given the current validation split + subset.
Describe the current behavior.
Stated above.
Describe the expected behavior.
I expect this to raise an
Exception
saying "not enough images in the directory" or something more precise and related to the actual issue.Standalone code to reproduce the issue.
The below code block was run with
tensorflow~=2.4
,Pillow==9.1.1
, andnumpy~=1.19
to run.The text was updated successfully, but these errors were encountered: