I am trying to build a image classifier using a dataset of images, split between two directories, one for each class.
data_dir = 'experimental.data'
batch_size = 9
img_size = (160, 160)
train_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
shuffle=True,
image_size=img_size,
batch_size=batch_size)
val_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="validation",
seed=123,
shuffle=True,
image_size=img_size,
batch_size=batch_size)
class_names = train_ds.class_names
print(class_names)
['false', 'true']
val_batches = tf.data.experimental.cardinality(val_ds)
test_ds = val_ds.take(val_batches // 5)
val_ds = val_ds.skip(val_batches // 5)
When I get to predicting on my test/new images, I want to map the image paths to a pandas dataframe, along with predictions, so I can the use python to create a directory with a copy of the classed images.
file_paths = train_ds.file_paths
Calling the file_paths argument works fine on the train dataset, however after splitting the test/val datasets with skip/take, I get an error.
file_paths = test_ds.file_paths
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-129-3a6769d8217f> in <module>
----> 1 file_paths = test_ds.file_paths
AttributeError: 'TakeDataset' object has no attribute 'file_paths'
Is there a way to make this work using file_paths?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.