is my confusion matrix is showing differently or is it correctly showing?
I'm totally new to python and machine learning. I have only basic knowledge in both fields. I'm trying to train pre-trained model with other data. 458
Below is my code please look into it. I have warning saying precision value is set to 0 and also my confusion matrix picture is also attached.
And when i check the test data and predicted data using set() function, there is only one label in predicted data. Can any one help me how to solve this? thanks in advance
import pandas as pd
from pathlib import Path
import os.path
from keras.applications.inception_v3 import InceptionV3
from keras.models import Model, load_model
from keras_preprocessing.image import ImageDataGenerator
from sklearn.model_selection import train_test_split
import tensorflow as tf
import numpy as np
from keras.layers import MaxPooling2D, GlobalAveragePooling2D, Dropout, Dense
import matplotlib.pyplot as plt
from sklearn import metrics
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
import seaborn as sns
image_dir = Path('gaussian_filtered_images')
# Get filepaths and labels
filepaths = list(image_dir.glob(r'**/*.png'))
labels = list(map(lambda x: os.path.split(os.path.split(x)[0])[1], filepaths))
filepaths = pd.Series(filepaths, name='image_path').astype(str)
labels = pd.Series(labels, name='stage')
# Concatenate filepaths and labels
image_df = pd.concat([filepaths, labels], axis=1)
# Shuffle the DataFrame and reset index
image_df = image_df.sample(frac=1).reset_index(drop = True)
train_df, test_df = train_test_split(image_df, train_size=0.9, shuffle=True, random_state=1)
train_gen = ImageDataGenerator(
preprocessing_function=tf.keras.applications.inception_v3.preprocess_input,
rotation_range=90,
horizontal_flip=True,
vertical_flip=True,
zoom_range=0.2,
fill_mode='nearest',
validation_split=0.1
)
test_gen = ImageDataGenerator(
preprocessing_function=tf.keras.applications.inception_v3.preprocess_input,
)
train_images = train_gen.flow_from_dataframe(
train_df,
x_col='image_path',
y_col='stage',
shuffle=True,
subset='training',
color_mode='rgb',
class_mode='categorical',
target_size=(224, 224),
batch_size=32,
seed=0
)
validation_images = train_gen.flow_from_dataframe(
train_df,
x_col='image_path',
y_col='stage',
shuffle=True,
subset='training',
color_mode='rgb',
class_mode='categorical',
target_size=(224, 224),
batch_size=32,
seed=0
)
test_images = train_gen.flow_from_dataframe(
test_df,
x_col='image_path',
y_col='stage',
shuffle=False,
color_mode='rgb',
class_mode='categorical',
target_size=(224, 224),
batch_size=32
)
model = load_model('inception_V3.h5')
results = model.evaluate(test_images, verbose=0)
print(" ## Test Loss NORM: {:.5f}".format(results[0]))
print("## Accuracy on the test set NORM: {:.2f}%".format(results[1] * 100))
# Predict the label of the test_images
pred = model.predict(test_images)
pred = np.argmax(pred, axis=1)
# Map the label
labels = train_images. 422