File size: 16,423 Bytes
a3a53e1
 
 
 
801b22c
 
 
 
 
a3a53e1
 
 
 
 
 
d3bd4e5
 
a3a53e1
 
d3bd4e5
 
 
 
 
 
 
 
a3a53e1
 
801b22c
 
a3a53e1
 
 
d3bd4e5
a3a53e1
 
 
 
 
801b22c
 
 
 
 
 
a3a53e1
801b22c
 
 
 
 
 
a3a53e1
801b22c
 
 
 
 
 
a3a53e1
 
 
 
 
801b22c
 
 
 
 
 
 
 
a3a53e1
801b22c
 
 
 
 
 
 
 
d3bd4e5
801b22c
 
 
 
 
 
 
 
a3a53e1
 
 
 
801b22c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3a53e1
801b22c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3a53e1
801b22c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3a53e1
 
 
 
 
 
 
 
d3bd4e5
a3a53e1
 
d3bd4e5
a3a53e1
d3bd4e5
a3a53e1
 
d3bd4e5
a3a53e1
d3bd4e5
a3a53e1
 
d3bd4e5
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import pickle
import numpy as np
import streamlit as st
from tensorflow.keras.models import load_model
import warnings

warnings.filterwarnings("ignore", category=UserWarning)

st.set_page_config(layout='wide')

def load_essential_models(scaler_6_path, scaler_8_path, scaler_full_path, clf_6_path, clf_8_path, clf_full_path):
    scaler_6 = pickle.load(open(file=scaler_6_path, mode='rb'))
    scaler_8 = pickle.load(open(file=scaler_8_path, mode='rb'))
    scaler_21 = pickle.load(open(file=scaler_full_path, mode='rb'))
    clf_6 = pickle.load(open(file=clf_6_path, mode='rb'))
    clf_8 = load_model(clf_8_path, compile=False)
    clf_21 = load_model(clf_full_path, compile=False)
    return scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21

def convert_prediction(prediction):
    if prediction == [0]:
        return 'S'
    elif prediction == [1]:
        return 'M'
    else:
        return 'L'

st.title('Demo System for Vietnamese Woman Bra Size Classifier')

scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21 = load_essential_models(scaler_6_path='./Models/6/scaler.pkl', scaler_8_path='./Models/8/scaler.pkl', scaler_full_path='./Models/21/scaler.pkl', clf_6_path='./Models/6/svc_fs_tune.pkl', clf_8_path='./Models/8/ANN_8.h5', clf_full_path='./Models/21/ANNs_full.h5')

header_col_1, header_col_2 = st.columns([3, 2])
num_of_features = header_col_1.selectbox(label='Please select the number of measurements you have:', options=['6 measurements', '8 measurements', '21 measurements'])

# h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt = [0.0]*21

if num_of_features == '6 measurements':
    sample_options_6 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
    container_col_1, container_col_2, container_col_3 = st.columns([1, 1, 1])
    if sample_options_6 == 'Sample 1 (Small)':
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=82.00, min_value=0.00, step=0.01)
        vn = container_col_2.number_input(label='Bust circumference (cm):', value=82.40, min_value=0.00, step=0.01)
        vcn = container_col_3.number_input(label='Chest circumference (cm):', value=73.10, min_value=0.00, step=0.01)
        cl = container_col_1.number_input(label='Size difference (cm):', value=9.30, min_value=0.00, step=0.01)
        ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=325.6, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=325.6, min_value=0.00, step=0.01)
    elif sample_options_6 == 'Sample 2 (Medium)':
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=77.20, min_value=0.00, step=0.01)
        vn = container_col_2.number_input(label='Bust circumference (cm):', value=78.60, min_value=0.00, step=0.01)
        vcn = container_col_3.number_input(label='Chest circumference (cm):', value=66.50, min_value=0.00, step=0.01)
        cl = container_col_1.number_input(label='Size difference (cm):', value=12.10, min_value=0.00, step=0.01)
        ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=388.80, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=324.60, min_value=0.00, step=0.01)
    else:
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=86.50, min_value=0.00, step=0.01)
        vn = container_col_2.number_input(label='Bust circumference (cm):', value=88.00, min_value=0.00, step=0.01)
        vcn = container_col_3.number_input(label='Chest circumference (cm):', value=74.00, min_value=0.00, step=0.01)
        cl = container_col_1.number_input(label='Size difference (cm):', value=14.00, min_value=0.00, step=0.01)
        ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=451.30, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=471.60, min_value=0.00, step=0.01)

elif num_of_features == '8 measurements':
    sample_options_8 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
    container_col_1, container_col_2, container_col_3, container_col_4 = st.columns([1, 1, 1, 1])
    if sample_options_8 == 'Sample 1 (Small)':
        ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=287.50, min_value=0.00, step=0.01)
        cl = container_col_2.number_input(label='Size difference (cm):', value=7.00, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=8.50, min_value=0.00, step=0.01)
        vn = container_col_4.number_input(label='Bust circumference (cm):', value=74.50, min_value=0.00, step=0.01)
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=74.00, min_value=0.00, step=0.01)
        cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=8.90, min_value=0.00, step=0.01)
        cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=8.50, min_value=0.00, step=0.01)
        vcn = container_col_4.number_input(label='Chest circumference (cm):', value=67.50, min_value=0.00, step=0.01)
    elif sample_options_8 == 'Sample 2 (Medium)':
        ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=489.60, min_value=0.00, step=0.01)
        cl = container_col_2.number_input(label='Size difference (cm):', value=13.00, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=12.40, min_value=0.00, step=0.01)
        vn = container_col_4.number_input(label='Bust circumference (cm):', value=78.30, min_value=0.00, step=0.01)
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=77.20, min_value=0.00, step=0.01)
        cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=11.60, min_value=0.00, step=0.01)
        cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=8.70, min_value=0.00, step=0.01)
        vcn = container_col_4.number_input(label='Chest circumference (cm):', value=65.30, min_value=0.00, step=0.01)
    else:
        ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=568.2, min_value=0.00, step=0.01)
        cl = container_col_2.number_input(label='Size difference (cm):', value=13.7, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=14.0, min_value=0.00, step=0.01)
        vn = container_col_4.number_input(label='Bust circumference (cm):', value=88.7, min_value=0.00, step=0.01)
        vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=86.5, min_value=0.00, step=0.01)
        cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=12.5, min_value=0.00, step=0.01)
        cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=10.7, min_value=0.00, step=0.01)
        vcn = container_col_4.number_input(label='Chest circumference (cm):', value=75.0, min_value=0.00, step=0.01)
else:
    sample_options_21 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
    container_col_1, container_col_2, container_col_3, container_col_4, container_col_5 = st.columns([1, 1, 1, 1, 1])
    if sample_options_21 == 'Sample 1 (Small)':
        h = container_col_1.number_input(label='Height (cm):', value=158.50, min_value=0.00, step=0.01)
        w = container_col_2.number_input(label='Weight (kg):', value=44.00, min_value=0.00, step=0.01)
        bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=17.50, min_value=0.00, step=0.01)
        vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=75.40, min_value=0.00, step=0.01)
        vn = container_col_5.number_input(label='Bust circumference (cm):', value=81.10, min_value=0.00, step=0.01)
        vcn = container_col_1.number_input(label='Chest circumference (cm):', value=74.80, min_value=0.00, step=0.01)
        cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=14.50, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.80, min_value=0.00, step=0.01)
        cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=14.40, min_value=0.00, step=0.01)
        cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=8.60, min_value=0.00, step=0.01)
        cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=8.40, min_value=0.00, step=0.01)
        ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=21.50, min_value=0.00, step=0.01)
        ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=21.20, min_value=0.00, step=0.01)
        snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.90, min_value=0.00, step=0.01)
        sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=6.50, min_value=0.00, step=0.01)
        sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=6.50, min_value=0.00, step=0.01)
        xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=21.80, min_value=0.00, step=0.01)
        xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=21.10, min_value=0.00, step=0.01)
        cl = container_col_4.number_input(label='Size difference (cm):', value=6.30, min_value=0.00, step=0.01)
        ttp = container_col_5.number_input(label='Volume of right breast (cm3):', value=325.10, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=335.70, min_value=0.00, step=0.01)
    elif sample_options_21 == 'Sample 2 (Medium)':
        h = container_col_1.number_input(label='Height (cm):',  value=163.00, min_value=0.00, step=0.01)
        w = container_col_2.number_input(label='Weight (kg):', value=43.00, min_value=0.00, step=0.01)
        bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=16.20, min_value=0.00, step=0.01)
        vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=76.00, min_value=0.00, step=0.01)
        vn = container_col_5.number_input(label='Bust circumference (cm):', value=79.00, min_value=0.00, step=0.01)
        vcn = container_col_1.number_input(label='Chest circumference (cm):', value=64.00, min_value=0.00, step=0.01)
        cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=16.50, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.10, min_value=0.00, step=0.01)
        cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=12.60, min_value=0.00, step=0.01)
        cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=9.20, min_value=0.00, step=0.01)
        cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=9.10, min_value=0.00, step=0.01)
        ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=19.80, min_value=0.00, step=0.01)
        ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=18.20, min_value=0.00, step=0.01)
        snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.40, min_value=0.00, step=0.01)
        sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=3.50, min_value=0.00, step=0.01)
        sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=3.70, min_value=0.00, step=0.01)
        xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=21.00, min_value=0.00, step=0.01)
        xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=20.50, min_value=0.00, step=0.01)
        cl = container_col_4.number_input(label='Size difference (cm):', value=15.00, min_value=0.00, step=0.01)
        ttp = container_col_5.number_input(label='Volume of right breast (cm3):',  value=521.60, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):',  value=513.50, min_value=0.00, step=0.01)
    else:
        h = container_col_1.number_input(label='Height (cm):', value=152.00, min_value=0.00, step=0.01)
        w = container_col_2.number_input(label='Weight (kg):', value=46.00, min_value=0.00, step=0.01)
        bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=19.90, min_value=0.00, step=0.01)
        vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=77.50, min_value=0.00, step=0.01)
        vn = container_col_5.number_input(label='Bust circumference (cm):', value=85.50, min_value=0.00, step=0.01)
        vcn = container_col_1.number_input(label='Chest circumference (cm):', value=70.40, min_value=0.00, step=0.01)
        cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=18.90, min_value=0.00, step=0.01)
        cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.50, min_value=0.00, step=0.01)
        cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=12.50, min_value=0.00, step=0.01)
        cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=10.30, min_value=0.00, step=0.01)
        cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=10.50, min_value=0.00, step=0.01)
        ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=20.40, min_value=0.00, step=0.01)
        ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=20.10, min_value=0.00, step=0.01)
        snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.50, min_value=0.00, step=0.01)
        sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=5.50, min_value=0.00, step=0.01)
        sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=4.20, min_value=0.00, step=0.01)
        xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=19.50, min_value=0.00, step=0.01)
        xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=20.50, min_value=0.00, step=0.01)
        cl = container_col_4.number_input(label='Size difference (cm):', value=15.10, min_value=0.00, step=0.01)
        ttp = container_col_5.number_input(label='Volume of right breast (cm3):', value=625.80, min_value=0.00, step=0.01)
        ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=585.40, min_value=0.00, step=0.01)

col_1, col_2, col_3, col_4, col_5 = st.columns([1, 1, 1, 1, 1])

with col_3:
    predict = st.button(label='Predict', use_container_width=True)

if predict:
    if num_of_features == '6 measurements':
        X_6 = np.array([[vtn, vn, vcn, cl, ttp, ttt]])
        X_6 = scaler_6.transform(X_6)
        y_6 = clf_6.predict(X_6)
        st.success(f'We recommend you choosing {convert_prediction(y_6)} size!')
    elif num_of_features == '8 measurements':
        X_8 = np.array([[ttp, cl, cnnp, vn, vtn, cnnt, cntp, vcn]])
        X_8 = scaler_8.transform(X_8)
        y_8 = clf_8.predict(X_8)
        st.success(f'We recommend you choosing {convert_prediction(np.argmax(y_8, axis=1))} size!')
    else:
        X_21 = np.array([[h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt]])
        X_21 = scaler_21.transform(X_21)
        y_21 = clf_21.predict(X_21)
        st.success(f'We recommend you choosing {convert_prediction(np.argmax(y_21, axis=1))} size!')