File size: 2,801 Bytes
fb22aff
2d277f1
802af7d
cd3702a
4db0b44
71b6d09
548bfe8
6faa464
0f7dc33
cd3702a
2d277f1
 
cd3702a
 
 
4376b22
3f40137
 
 
 
 
 
 
 
7bb7530
3f40137
c0e3ee4
3f40137
 
 
 
 
7bb7530
3f40137
c0e3ee4
3f40137
 
 
 
7bb7530
 
c0e3ee4
 
 
 
7a1c0c2
 
c0e3ee4
 
 
 
 
 
7a1c0c2
 
c0e3ee4
 
 
 
7a1c0c2
c0e3ee4
7a1c0c2
 
c0e3ee4
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
from keras.datasets import mnist
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential,Model
import matplotlib.pyplot as plt
m = MinMaxScaler()
from tensorflow import keras
model = keras.models.load_model('cnn_lenet.keras')
from keras.layers import Conv2D,MaxPooling2D,AveragePooling2D,InputLayer,Dense,Flatten
option = st.sidebar.selectbox("Datasets",["Select dataset","Hand Writen Digit Dataset"])
if option == "Hand Writen Digit Dataset":
    (x_train,y_train),(x_test,y_test) = mnist.load_data()
    st.write("Successfully Load the Dataset")
if st.button("Train"):
    fig, axs = plt.subplots(6, 1, figsize=(8, 6))
    col1,col2,col3,col4,col5,col6 = st.columns(6)
    with col1:
        st.write("Filters")
        for i in range(6):
            axs[i].imshow(
                m.fit_transform(model.layers[0].weights[0][:, :, :, i][:, :, 0]),
                cmap="gray"
            )
            axs[i].axis("off")
        st.pyplot(fig)
    with col2:
        st.write("Conv2D Layer-1")
        sub = Model(inputs=model.inputs[0],outputs=model.layers[0].output)
        fig,ax = plt.subplots(6,1,figsize=(8,6))
        for i in range(6):
            ax[i].imshow(sub.predict(x_train[0:1,:].reshape(1,28,28,1))[0,:,:,i],cmap="gray")
            ax[i].axis("off")
        st.pyplot(fig)
    with col3:
        st.write("Average Pooling Layer-1")
        max1 = Model(inputs=model.inputs[0],outputs=model.layers[1].output)
        fig,ax1 = plt.subplots(6,1,figsize=(8,6))
        for i in range(6):
            ax1[i].imshow(max1.predict(x_train[0:1,:].reshape(1,28,28,1))[0,:,:,i],cmap="gray")
            ax1[i].axis("off")
        st.pyplot(fig)
    
    with col4:
        st.write("Conv2D Layer-2")
        sub1 = Model(inputs=model.inputs[0],outputs=model.layers[2].output)
        fig,ax2 = plt.subplots(16,1,figsize=(8,6))
        for i in range(16):
            ax2[i].imshow(sub1.predict(x_train[0:1,:].reshape(1,28,28,1))[0,:,:,i],cmap="gray")
            ax2[i].axis("off")
        st.pyplot(fig)
    with col5:
        st.write("Average Pooling Layer-2")
        max2 = Model(inputs=model.inputs[0],outputs=model.layers[3].output)
        fig,ax3 = plt.subplots(16,1,figsize=(8,6))
        for i in range(16):
            ax3[i].imshow(max2.predict(x_train[0:1,:].reshape(1,28,28,1))[0,:,:,i],cmap="gray")
            ax3[i].axis("off")
        st.pyplot(fig)
    with col6:
        st.write("Conv2D Layer-3")
        sub3 = Model(inputs=model.inputs[0],outputs=model.layers[4].output)
        fig,ax4 = plt.subplots(120,1,figsize=(8,6))
        for i in range(120):
            ax4[i].imshow(sub3.predict(x_train[0:1,:].reshape(1,28,28,1))[0,:,:,i],cmap="gray")
            ax4[i].axis("off")
        st.pyplot(fig)