TroglodyteDerivations's picture
Updated lines 15-16 with: [notation]
f88145a verified
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
# Streamlit app
st.title('Rick & Morty Classification Vis 3')
st.image('rm_title.jpeg')
st.set_option('deprecation.showPyplotGlobalUse', False)
# Create class mappings
# Produce the visualization with the .npy files
class_names = ['jerry', 'morty', 'rick', 'summer']
# Load the numpy files
all_images_train_ds = np.load('all_images_train_ds.npy')
all_labels_train_ds = np.load('all_labels_train_ds.npy')
all_images_test_ds = np.load('all_images_test_ds.npy')
all_labels_test_ds = np.load('all_labels_test_ds.npy')
# Create the subplots
_, ax = plt.subplots(ncols=3, figsize=(20, 14))
# Plotting training data types
class_counts_train = [list(all_labels_train_ds).count(label) for label in set(all_labels_train_ds)]
ax[0].set_title('Training Data')
ax[0].pie(
class_counts_train,
labels=class_names,
colors=['#ccff00','#fdff00','#b9f2ff', '#e6e6fa'],
autopct=lambda p: '{:.2f}%\n{:,.0f}'.format(p, p * sum(class_counts_train) / 100),
explode=(0.01, 0.01,0.01,0.01),
textprops={'fontsize': 13}
)
# Plotting distribution of train test split
ax[1].set_title('Train Test Split')
ax[1].pie(
[len(all_images_train_ds), len(all_images_test_ds)],
labels=['Train','Test'],
colors=['#318ce7', '#ff9f00'],
autopct=lambda p: '{:.2f}%\n{:,.0f}'.format(p, p * sum([len(all_images_train_ds), len(all_images_test_ds)]) / 100),
explode=(0.1, 0),
startangle=85,
textprops={'fontsize': 13}
)
# Plotting testing data types
class_counts_test = [list(all_labels_test_ds).count(label) for label in set(all_labels_test_ds)]
ax[2].set_title('Testing Data')
ax[2].pie(
class_counts_test,
labels=class_names,
colors=['#ccff00','#fdff00','#b9f2ff', '#e6e6fa'],
autopct=lambda p: '{:.2f}%\n{:,.0f}'.format(p, p * sum(class_counts_test) / 100),
explode=(0.01, 0.01,0.01,0.01),
textprops={'fontsize': 13}
)
st.pyplot(plt.show())