Closed BENHABI13 closed 1 year ago
Hi @BENHABI13, can you please try using
from tensorflow.keras.utils import to_categorical
labels = to_categorical(le.transform(labels), 2)
in place of
labels = np_utils.to_categorical(le.transform(labels), 2)
Hi @ vikaskookna , I have tested your solution but it generates the same error : ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() have a nice da
Hi @BENHABI13, I think you're not using the right versions for scikit-learn or TensorFlow. Are you a member of PyImageSearch University, if not I would suggest joining for full support on tutorial codes and get pre-configured jupyter notebooks for all tutorials https://pyimagesearch.com/pyimagesearch-university/
I'm trying to detect the smile by neural networks in python but when I launch the learning of the network I get this error in return "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
and this is my code in python:
data = [] labels = [] path=('/content/drive/MyDrive/smiles detection') for imagePath in sorted(list(paths.list_images(path))):
for imagePath in sorted('/content/drive/MyDrive/smiles detection/positives)'):
load the image, pre-process it, and store it in the data list
extract the class label from the image path and update the
labels list
data = np.array(data, dtype="float") / 255.0 labels = np.array(labels) le = LabelEncoder().fit(labels) labels = np_utils.to_categorical(le.transform(labels), 2)
classTotals = labels.sum(axis=0) classWeight = classTotals.max() / classTotals
(trainX, testX, trainY, testY) = train_test_split(data,labels, test_size=0.20, stratify=labels, random_state=42)
print("[INFO] compiling model...") model.compile(loss="binary_crossentropy", optimizer="adam",metrics=["accuracy"])
print("[INFO] training network...") H = model.fit((trainX, trainY), validation_data=(testX, testY),class_weight=classWeight, batch_size=64, epochs=15, verbose=1)