Want to convert images in directory to tensors in tf.dataset.Dataset format, so => tf.keras.utils.image_dataset_from_directory: Generates a tf.data.Dataset from image files in a directory
labels: Either "inferred" (labels are generated from the directory structure), None (no labels), or a list/tuple of integer labels of the same size as the number of image files found in the directory. Labels should be sorted according to the alphanumeric order of the image file paths (obtained via os.walk(directory) in Python). [From docs]
First I encoded the labels
from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
y_train = encoder.fit_transform(list(y_train["breed"]))
then while using
train_ds = tf.keras.utils.image_dataset_from_directory(
TRAIN_IMG_PATH,
labels=y_train,
label_mode='int',
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size
)
got error
/opt/conda/lib/python3.7/site-packages/keras/utils/image_dataset.py:163: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if labels not in ("inferred", None):
...
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()