{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ecg_neuropathy_app.ipynb", "provenance": [], "authorship_tag": "ABX9TyMIic3avbqiU7X9WZYMaSfB", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "source": [ "# ARE YOU TIRED OF SPENDING ALL YOUR TIME DOING NEUROPATHY EXAMINATIONS WHEN YOU COULD BE PLAYING GOLF?\n", "# THEN YOU HAVE COME TO THE RIGHT PLACE!\n", "Welcome to the best in clinical decision support for the ~~lazy~~/~~unsafe~~/busy diabetologist: \n", "\n", "Simply take a photo of one of the leads in your diabetes patient's ECG, and the power of MACHINE LEARNING, AI, COMPUTER VISION and BIG DATA will tell you if your patient has diabetic neuropathy!\n", "\n", "(preferable a photo of V1, V2, V5 or V6, as that's all this tool knows!)\n", "\n", "(a coin toss may be just as good a predictor)" ], "metadata": { "id": "B_0BLi6KDomq" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "MMj41BHv8pMi" }, "outputs": [], "source": [ "from fastai.vision.all import *\n", "from fastai.vision.widgets import *" ] }, { "cell_type": "code", "source": [ "path = Path()\n", "learn_inf = load_learner(path/'learn_resnet_randomsplit_5.pkl', cpu=True)\n", "btn_upload = widgets.FileUpload()\n", "out_pl = widgets.Output()\n", "lbl_pred = widgets.Label()" ], "metadata": { "id": "-korA6j99RXv" }, "execution_count": 14, "outputs": [] }, { "cell_type": "code", "source": [ "def on_data_change(change):\n", " lbl_pred.value = ''\n", " img = PILImage.create(btn_upload.data[-1])\n", " out_pl.clear_output()\n", " with out_pl: display(img.to_thumb(128,128))\n", " pred,pred_idx,probs = learn_inf.predict(img)\n", " lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'" ], "metadata": { "id": "mXl5S9Qg9U_u" }, "execution_count": 15, "outputs": [] }, { "cell_type": "code", "source": [ "btn_upload.observe(on_data_change, names=['data'])" ], "metadata": { "id": "RyzZhTag9XdV" }, "execution_count": 16, "outputs": [] }, { "cell_type": "code", "source": [ "display(VBox([widgets.Label('Please take a photo of a lead in the ECG of your patient to infer neuropathy risk:'), btn_upload, out_pl, lbl_pred]))" ], "metadata": { "id": "GZoNeiIS9Z1-" }, "execution_count": null, "outputs": [] } ] }