import kagglehub

# Download latest version
path = kagglehub.dataset_download("mikoajfish99/lions-or-cheetahs-image-classification")

print("Path to dataset files:", path)
ls $path
from tensorflow.keras.utils import image_dataset_from_directory

train_data, test_data = image_dataset_from_directory(
    path + '/images',
    subset='both',
    validation_split=0.3,
    seed=10
)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dense, Flatten
model = Sequential([
    Conv2D(64, (3,3), activation='relu', input_shape=(256,256,3)),
    MaxPool2D((2, 2)),
    Conv2D(32, (3,3), activation='relu', input_shape=(256,256,3)),
    MaxPool2D((2, 2)),
    Flatten(),
    Dense(16, activation='relu'),
    Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
history = model.fit(train_data, epochs=2)
history.history['accuracy']
import matplotlib.pyplot as plt

plt.plot(history.history['loss'],label='loss')
plt.title("Loss History")
plt.show()
import matplotlib.pyplot as plt

plt.plot(history.history['accuracy'],label='accuracy')
plt.title("Accuracy History")
plt.show()
images = []
labels = []

for image_batch, label_batch in test_data:
    images.extend(image_batch.numpy())
    labels.extend(label_batch.numpy())

preds = model.predict(test_data)
import numpy as np
preds = np.round(preds)
preds
preds = preds.reshape(60)
preds
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix

print(accuracy_score(labels, preds) * 100 , "%")
print(classification_report(labels, preds))
from sklearn.metrics import RocCurveDisplay
import matplotlib.pyplot as plt # Ensure matplotlib is imported if not already done in a previous cell run order
import numpy as np # Ensure numpy is imported


# Plot the ROC curve using the true labels and the predicted scores
RocCurveDisplay.from_predictions(
    labels,
    preds
)
plt.plot([0,1],[0,1], color='red', linestyle='--')
plt.show() # Add plt.show() to display the plot
training_images = [images[0], images[1]]
training_labels = [labels[0], labels[1]]

model.fit(np.array(training_images), np.array(training_labels), epochs=2)