File size: 7,330 Bytes
4ab4688
942c848
 
 
 
 
 
 
a02dedb
942c848
 
 
 
 
 
8ea1ecf
942c848
 
8ea1ecf
 
942c848
 
 
 
 
 
 
643257d
942c848
 
 
 
 
8ea1ecf
 
 
942c848
8ea1ecf
942c848
 
8ea1ecf
 
942c848
 
 
 
 
8ea1ecf
 
942c848
 
8ea1ecf
942c848
 
8ea1ecf
942c848
8ea1ecf
 
 
 
 
 
 
942c848
8ea1ecf
942c848
 
8ea1ecf
942c848
8ea1ecf
942c848
 
8ea1ecf
942c848
57c8c48
942c848
8ea1ecf
942c848
8ea1ecf
942c848
8ea1ecf
 
 
942c848
8ea1ecf
942c848
8ea1ecf
 
 
 
 
 
 
942c848
8ea1ecf
 
 
 
 
 
 
 
 
 
942c848
8ea1ecf
 
942c848
 
8ea1ecf
 
 
 
 
 
 
 
 
 
942c848
166661f
942c848
8ea1ecf
 
 
 
 
942c848
 
8ea1ecf
942c848
8ea1ecf
 
942c848
8ea1ecf
 
 
942c848
 
8ea1ecf
942c848
 
8ea1ecf
942c848
8ea1ecf
942c848
 
69913c6
942c848
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

import streamlit as st
import numpy as np
import sys

import time
import math
import pandas as pd
from utils import *

def main():
    st.markdown(
        """
        <style>
        [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
        width: 400px;
    }
        [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
        width: 400px;
        margin-left: -400px;
        }
        </style>
        """,
        unsafe_allow_html=True,
    )
    
    germanShepherdHeaderColumns = st.columns((1))
    germanShepherdHeaderColumns[0].title("Introducing the German Shepherd's Database Collection!")
    germanShepherdHeaderColumns[0].markdown(
        """
        Created by [Abhinit Sundar](https://github.com/asundar0128)
        """)
    
    germanShepherdEvaluationMethod = germanShepherdHeaderColumns[-1].button('Intrigued with German Shepherds?')
    if germanShepherdEvaluationMethod:
        germanShepherdExplainMethod()
    else:
        germanShepherdEvaluation()

        
def germanShepherdExplainMethod():
    st.button('Traverse Back to German Shepherd Dog Photos')
    
    st.markdown(
        """
        Dataset:
        
        - We used German Shepherd Dog images from random online sources and fed them into the neural network using ResNet-50 to train the model accuractely. Afterwards, this model is representative of every German Shepherd and is an accurate classifier and predictor for the entire dataset, or paramter of interest, which is the German Shepherd breed of dogs.                                                         
        Created by [Abhinit Sundar](https://github.com/asundar0128)                      
         """
    )
    st.button('Traverse Back to German Shepherd Dog Photos', key='German Shepherd')

    
def germanShepherdEvaluation():

    germanShepherdSimilarityMeasureIndex = ['maximum correlation and maximum similarity', 'least correlation and least similarity']
    germanShepherdNearestValues = [w**2 for w in range(4, 11)]
    germanShepherdMaximumProximity = 1000
    germanShepherdPixel = [96, 152, 256]
    germanShepherdModelVersions = ['v1', 'v2']
    germanShepherdMinimalIndex = 2500
    germanShepherdModelStartTime = time.time()

    with st.sidebar.expander('Germam Shepherd Similarity Search Instructions'):
        st.markdown(
                """
                **Select a photo of a particular German Shepherd of interest!**
                
                Click the 'Find German Shepherd' button.
                """
            )
    germanshepherdNumNearest = st.sidebar.select_slider('Total Quantity of Similar German Shepherds to Show', germanShepherdNearestValues)

    germanShepherdEvaluatePixel = st.sidebar.select_slider('Picture Size (In Pixels)', germanShepherdPixel, value=germanShepherdPixel[1])

    germanShepherdModelVersion = st.sidebar.select_slider('German Shepherd Current Model Version', germanShepherdModelVersions, value=germanShepherdModelVersions[-1])
    
    germanShepherdQuantitySimilarElements = 1000

    germanShepherdSimilarityMetric = False
    germanShepherdBeginSearch = st.sidebar.button('Enter your search parameter of interest for German Shepherd')
    germanShepherdBeginRandomSearch = st.sidebar.button('Evaluate Random German Shepherd Images')

    germanShepherdNumberTotal = germanShepherdCategory['Total Number of German Shepherds']

    if germanShepherdBeginSearch or germanShepherdRandomSearch:
        if germanShepherdRandomSearch:
            
            germanShepherdMaximumIndex = germanShepherdNumberTotal-1
            germanShepherdRandomIndex = 0
            while (germanShepherdRandomIndex < germanShepherdMinimalIndex) or (germanShepherdRandomIndex > germanShepherdMaximumIndex):
                germanShepherdRandomIndex = int(np.random.lognormal(12., 3.))

        germanShepherdLinks = urls_from_coordinates(germanShepherdSimilarityValue, germanShepherdPixelValue=germanShepherdEvaluatePixel)
        germanShepherdSimilarityValue['Link to German Shepherd'] = np.array(germanShepherdLink)        
        germanShepherdNumberColumns = min(11, int(math.ceil(np.sqrt(germanshepherdNumNearest))))
        germanShepherdNumberRows    = int(math.ceil(germanshepherdNumNearest/germanShepherdNumberColumns))

        germanShepherdLabel = 'Traverse Through German Shepherd'
        germanShepherdLabelRawDecimal = 'RA, Dec = ({:.4f}, {:.4f})'.format(germanShepherdSimilarityValue['Raw German Shepherd Image'][0], germanShepherdSimilarityValue['Decimal German Shepherd Image'][0])
        germanShepherdColumns = st.columns([2]+[1*germanShepherdNumberColumns])
        germanShepherdColumns[0].subheader(lab)
        germanShepherdColumns[1].subheader('Closest German Shepherd Photos')
        
        germanShepherdColumns = st.columns([2]+[1]*germanShepherdNumberColumns)
        germanShepherdColumns[0].image(germanShepherdLink[0],
                      use_column_width='always',
                      caption=lab_radec)#use_column_width='auto')
        
        germanShepherdIndexImage = 1 
        for germanShepherdIndexRow in range(germanShepherdNumberRows):
            for germanShepherdIndexColumn in range(germanShepherdNumberColumns):
                germanShepherdLink = germanShepherdLinks[germanShepherdIndexImage]
                germanShepherdLabelValue = 'German Shepherd Similarity Value={:.2f}\n'.format(germanShepherdSimilarityValue['German Shepherd Similarity'][germanShepherdIndexImage])
                if germanShepherdNumberColumns > 5:
                    germanShepherdLabelValue = None
                germanShepherdColumns[germanShepherdIndexColumn+1].image(germanShepherdLink, caption=lab, use_column_width='always')
                germanShepherdIndexImage += 1

        germanShepherdValueatIndex = ['g', 'r', 'z']

        germanShepherdSimilarityValueOutput = {}
        for q, x in germanShepherdSimilarityValue.items():
            if x.ndim == 2:
                for germanShepherdIndexValues in range(v.shape[1]):
                    germanShepherdSimilarityValueOutput['{:s}_{:s}'.format(q, germanShepherdValueatIndex[germanShepherdIndexValues])] = x[:, germanShepherdIndexValues]

            else:
                germanShepherdSimilarityValueOutput[q] = x

        germanShepherdSimilarityValueOutput['German Shepherd Source Value'] = germanShepherdSimilarityValueOutput['German Shepherd Source Value'].astype('str')
        germanShepherdDataFrame = pd.DataFrame.from_dict(germanShepherdSimilarityValueOutput)

        cols_leading = ['German Shepherd Raw Pixel Value', 'German Shepherd Decimal Pixel Value', 'German Shepherd Similarity Index']
        cols = cols_leading  + [germanShepherdColumn for germanShepherdColumn in df if germanShepherdColumn not in germanShepherdLeadingColumn]
        germanShepherdDatFrame = germanShepherdDataFrame[germanShepherdColumns]
        
        # display table
        st.write(df.head(germanShepherdMaximumProximity))

        # show a downloadable link
        st.markdown(get_table_download_link(germanShepherdDataFrame), unsafe_allow_html=True)

        germanShepherdTendency = time.time()

st.set_page_config(
    page_title='GermanShepherdDogFinder',
    layout="wide",
    initial_sidebar_state="expanded",
)


if __name__ == '__main__':    

    main()