Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "comparable-williams",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import numpy as np\n",
"import tensorflow as tf\n",
"import keras"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ongoing-things",
"metadata": {},
"outputs": [],
"source": [
"from django.urls import path\n",
"from PIL import Image\n",
"from skimage import transform\n",
"\n",
"from tensorflow.compat.v1 import ConfigProto\n",
"from tensorflow.compat.v1 import InteractiveSession\n",
"\n",
"config = ConfigProto()\n",
"config.gpu_options.allow_growth = True\n",
"session = InteractiveSession(config=config)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "underlying-baker",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"#change directory to where you want image to be written\n",
"dire = r'C:\\Users\\jaych\\Documents\\Senior Design\\test_images\\image5.jpg'\n",
"recieve = requests.get('https://www.statnews.com/wp-content/uploads/2020/07/1-s2.0-S0735675720302746-gr1_lrg.jpg')\n",
"with open(dire,'wb') as f:\n",
" f.write(recieve.content)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "amended-vector",
"metadata": {},
"outputs": [],
"source": [
"model = keras.models.load_model(r'C:\\Users\\jaych\\Documents\\Senior Design\\covid_fine_tuned.h5')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "lovely-platform",
"metadata": {},
"outputs": [],
"source": [
"#preprocess the image so it can be evaluated by the model with the proper dimensions, includes rescaling\n",
"\n",
"def load(filename):\n",
" np_image = Image.open(filename)\n",
" np_image = np.array(np_image).astype('float32')/255\n",
" np_image = transform.resize(np_image, (218, 178, 3))\n",
" np_image = np.expand_dims(np_image, axis=0)\n",
" return np_image"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "hired-poison",
"metadata": {},
"outputs": [],
"source": [
"img = load(dire)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "extensive-payday",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 218, 178, 3)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"img.shape"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "grand-employee",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.83280176\n"
]
}
],
"source": [
"pred = model.predict(img)[0, 0]\n",
"print(pred)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "important-search",
"metadata": {},
"outputs": [],
"source": [
"def result(num):\n",
" if round(num) == 1:\n",
" print(\"Image registers as positive for COVID-19\")\n",
" elif round(num) == 0:\n",
" print(\"Image registers as negative for COVID-19\")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "sophisticated-fancy",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Image registers as positive for COVID-19\n"
]
}
],
"source": [
"result(pred)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "amber-albany",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}