File size: 18,690 Bytes
a3a53e1 801b22c f40d471 a3a53e1 d3bd4e5 a3a53e1 d3bd4e5 b829bf9 603cf5e b829bf9 603cf5e d3bd4e5 603cf5e d3bd4e5 9985466 a3a53e1 801b22c a3a53e1 d3bd4e5 a3a53e1 f614789 a3a53e1 6fcd656 a3a53e1 6fcd656 a3a53e1 6fcd656 a3a53e1 f614789 a3a53e1 6fcd656 a3a53e1 6fcd656 d3bd4e5 6fcd656 a3a53e1 f614789 a3a53e1 6fcd656 801b22c 6fcd656 a3a53e1 6fcd656 801b22c 6fcd656 a3a53e1 6fcd656 801b22c 6fcd656 a3a53e1 d3bd4e5 a3a53e1 e833d1e 6b86935 603cf5e 07e5bbb a3a53e1 d3bd4e5 a3a53e1 8ba1c85 603cf5e 7cfdc8b a3a53e1 d3bd4e5 a3a53e1 8ba1c85 603cf5e 7cfdc8b |
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 183 184 185 186 187 188 189 190 191 192 193 |
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(page_title="ViWoBra - Hệ thống phân loại ngực phụ nữ Việt Nam", page_icon="💮", layout='wide', initial_sidebar_state="collapsed")
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] == [0]):
return 'the small breast group'
elif (prediction[0] == [1]):
return 'the medium breast group'
else:
return 'the large breast group'
st.markdown("<h1 style='text-align: center;'>Breast group classification system for female in Northern Vietnam</h1>", unsafe_allow_html=True)
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='Measurement 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 girth (vnt) (cm):', value=82.00, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Bust girth (vn) (cm):', value=82.40, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Underbust circumference (vcn) (cm):', value=73.10, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=9.30, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Volume of right breast (ttp) (cm3):', value=325.6, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (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 girth (vnt) (cm):', value=77.20, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Bust girth (vn) (cm):', value=78.60, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Underbust circumference (vcn) (cm):', value=66.50, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=12.10, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Volume of right breast (ttp) (cm3):', value=388.80, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (cm3):', value=324.60, min_value=0.00, step=0.01)
else:
vtn = container_col_1.number_input(label='Upper-bust girth (vnt) (cm):', value=86.50, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Bust girth (vn) (cm):', value=88.00, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Underbust circumference (vcn) (cm):', value=74.00, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=14.00, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Volume of right breast (ttp) (cm3):', value=451.30, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (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='Measurement 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 (ttp) (cm3):', value=287.50, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=7.00, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=8.50, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Bust girth (vn) (cm):', value=74.50, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Upper-bust girth (vnt) (cm):', value=74.00, min_value=0.00, step=0.01)
cnnt = container_col_2.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=8.90, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Inner arch of the right breast (cntp) (cm):', value=8.50, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Underbust circumference (vcn) (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 (ttp) (cm3):', value=489.60, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=13.00, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=12.40, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Bust girth (vn) (cm):', value=78.30, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Upper-bust girth (vnt) (cm):', value=77.20, min_value=0.00, step=0.01)
cnnt = container_col_2.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=11.60, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Inner arch of the right breast (cntp) (cm):', value=8.70, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Underbust circumference (vcn) (cm):', value=65.30, min_value=0.00, step=0.01)
else:
ttp = container_col_1.number_input(label='Volume of right breast (ttp) (cm3):', value=568.2, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=13.7, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=14.0, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Bust girth (vn) (cm):', value=88.7, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Upper-bust girth (vnt) (cm):', value=86.5, min_value=0.00, step=0.01)
cnnt = container_col_2.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=12.5, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Inner arch of the right breast (cntp) (cm):', value=10.7, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Underbust circumference (vcn) (cm):', value=75.0, min_value=0.00, step=0.01)
else:
sample_options_21 = header_col_2.selectbox(label='Measurement 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 (h) (cm):', value=158.50, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Weight (w) (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 girth (vtn) (cm): ', value=75.40, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Bust girth (vn) (cm):', value=81.10, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Underbust circumference (vcn) (cm):', value=74.80, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Distance between 2 nipples (cn) (cm):', value=14.50, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=13.80, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=14.40, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Inner arch of the right breast (cntp) (cm):', value=8.60, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='The inner bow of the left breast (cntt) (cm):', value=8.40, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Under right breast arc length (ccnp) (cm):', value=21.50, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Under left breast arc length (ccnt) (cm):', value=21.20, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Upper breast height (snt) (cm):', value=8.90, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Lower right breast height (sndp) (cm):', value=6.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Lower left breast height (sndt) (cm):', value=6.50, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Sternum to nipple right breast (xup) (cm):', value=21.80, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Sternum to nipple left breast (xut) (cm):', value=21.10, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=6.30, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Volume of right breast (ttp) (cm3):', value=325.10, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (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 (h) (cm):', value=163.00, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Weight (w) (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 girth (vtn) (cm): ', value=76.00, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Bust girth (vn) (cm):', value=79.00, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Underbust circumference (vcn) (cm):', value=64.00, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Distance between 2 nipples (cn) (cm):', value=16.50, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=13.10, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=12.60, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Inner arch of the right breast (cntp) (cm):', value=9.20, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='The inner bow of the left breast (cntt) (cm):', value=9.10, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Under right breast arc length (ccnp) (cm):', value=19.80, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Under left breast arc length (ccnt) (cm):', value=18.20, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Upper breast height (snt) (cm):', value=8.40, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Lower right breast height (sndp) (cm):', value=3.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Lower left breast height (sndt) (cm):', value=3.70, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Sternum to nipple right breast (xup) (cm):', value=21.00, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Sternum to nipple left breast (xut) (cm):', value=20.50, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=15.00, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Volume of right breast (ttp) (cm3):', value=521.60, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (cm3):', value=513.50, min_value=0.00, step=0.01)
else:
h = container_col_1.number_input(label='Height (h) (cm):', value=152.00, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Weight (w) (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 girth (vtn) (cm): ', value=77.50, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Bust girth (vn) (cm):', value=85.50, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Underbust circumference (vcn) (cm):', value=70.40, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Distance between 2 nipples (cn) (cm):', value=18.90, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Outer arch of the right thorax (cnnp) (cm):', value=13.50, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Outer arch of the left breast (cnnt) (cm):', value=12.50, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Inner arch of the right breast (cntp) (cm):', value=10.30, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='The inner bow of the left breast (cntt) (cm):', value=10.50, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Under right breast arc length (ccnp) (cm):', value=20.40, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Under left breast arc length (ccnt) (cm):', value=20.10, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Upper breast height (snt) (cm):', value=8.50, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Lower right breast height (sndp) (cm):', value=5.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Lower left breast height (sndt) (cm):', value=4.20, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Sternum to nipple right breast (xup) (cm):', value=19.50, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Sternum to nipple left breast (xut) (cm):', value=20.50, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Difference between bust girth and underbust circumference (cl) (cm):', value=15.10, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Volume of right breast (ttp) (cm3):', value=625.80, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Volume of left breast (ttt) (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(y_6)
y_pred_6 = convert_prediction(y_6)
# styled_text = f"<h3 style='text-align: center;'>We recommend you choosing <span style='color: red; font-weight: bold;'>{y_pred_6}</span> size!</h3>"
styled_text = f"<h3 style='text-align: center;'>You belong to <span style='color: red; font-weight: bold;'>{y_pred_6}</span> !</h3>"
st.markdown(styled_text, unsafe_allow_html=True)
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)
y_pred_8 = convert_prediction(np.argmax(y_8, axis=1))
# styled_text = f"<h3 style='text-align: center;'>We recommend you choosing <span style='color: red; font-weight: bold;'>{y_pred_8}</span> size!</h3>"
styled_text = f"<h3 style='text-align: center;'>You belong to <span style='color: red; font-weight: bold;'>{y_pred_8}</span> !</h3>"
st.markdown(styled_text, unsafe_allow_html=True)
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)
y_pred_21 = convert_prediction(np.argmax(y_21, axis=1))
# styled_text = f"<h3 style='text-align: center;'>We recommend you choosing <span style='color: red; font-weight: bold;'>{y_pred_21}</span> size!</h3>"
styled_text = f"<h3 style='text-align: center;'>You belong to <span style='color: red; font-weight: bold;'>{y_pred_21}</span> !</h3>"
st.markdown(styled_text, unsafe_allow_html=True) |