Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsanvil committed Oct 3, 2023
1 parent 9f7c72e commit 825fdff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
6 changes: 0 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
FROM python:3.8-buster

# Make sure pip and git are installed
RUN apt-get update && apt-get install -y python3-pip && apt-get install -y git

# Upgrade pip
RUN pip3 install --upgrade pip

# Add the project folder to the container
ADD app /app

Expand Down
25 changes: 14 additions & 11 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#---------------------------------#
# Data preprocessing and Model building

@st.cache(allow_output_mutation=True)
@st.cache_data
def read_ecg_preprocessing(uploaded_ecg):

FS = 300
Expand All @@ -67,14 +67,14 @@ def read_ecg_preprocessing(uploaded_ecg):
model_path = 'models/weights-best.hdf5'
classes = ['Normal','Atrial Fibrillation','Other','Noise']

@st.cache(allow_output_mutation=False,ttl=24*60*60)
@st.cache_resource
def get_model(model_path):
model = load_model(f'{model_path}')
return model

@st.cache(allow_output_mutation=True,show_spinner=False)
def get_prediction(data,model):
prob = model(data)
@st.cache_resource
def get_prediction(data,_model):
prob = _model(data)
ann = np.argmax(prob)
#true_target =
#print(true_target,ann)
Expand All @@ -84,7 +84,7 @@ def get_prediction(data,model):


# Visualization --------------------------------------
@st.cache(allow_output_mutation=True,show_spinner=False)
@st.cache_resource
def visualize_ecg(ecg,FS):
fig = plot_ecg(uploaded_ecg=ecg, FS=FS)
return fig
Expand Down Expand Up @@ -181,15 +181,18 @@ def visualize_ecg(ecg,FS):
st.subheader('2. Model Predictions')
with st.spinner(text="Running Model..."):
pred,conf = get_prediction(ecg,model)
mkd_pred_table = """
| Rhythm Type | Confidence |
| --- | --- |
""" + "\n".join([f"| {classes[i]} | {conf[0][i]*100:.2f}% |" for i in range(len(classes))])
mkd_pred_table = [
"| Rhythm Type | Confidence |",
"| --- | --- |"
]
for i in range(len(classes)):
mkd_pred_table.append(f"| {classes[i]} | {conf[0,i]*100:3.1f}% |")
mkd_pred_table = "\n".join(mkd_pred_table)

st.write("ECG classified as **{}**".format(pred))
pred_confidence = conf[0,np.argmax(conf)]*100
st.write("Confidence of the prediction: **{:3.1f}%**".format(pred_confidence))
st.write(f"**Likelihoods:**")
st.markdown(mkd_pred_table, unsafe_allow_html=False)
st.markdown(mkd_pred_table)

# st.line_chart(np.concatenate(ecg).ravel().tolist())
7 changes: 4 additions & 3 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# tensorflow>=2.5.1
keras==2.4
tensorflow>=2.5.1
keras
streamlit
scipy
matplotlib
git+https://github.com/simonsanvil/subplotted.git
-e .
-e .
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ awscli
flake8
python-dotenv>=0.5.1
tensorflow>=2.5.1
keras==2.4
keras
streamlit
matplotlib
git+https://github.com/simonsanvil/subplotted.git

0 comments on commit 825fdff

Please sign in to comment.