├── Brain MRI Image Classifier using Teachable Machine ├── labels.txt ├── requirements.txt ├── test.png ├── keras_model.h5 ├── test.py └── app.py ├── README.md ├── LICENSE └── .gitignore /Brain MRI Image Classifier using Teachable Machine/labels.txt: -------------------------------------------------------------------------------- 1 | 0 No 2 | 1 Yes 3 | -------------------------------------------------------------------------------- /Brain MRI Image Classifier using Teachable Machine/requirements.txt: -------------------------------------------------------------------------------- 1 | tensorflow-cpu 2 | numpy 3 | pillow 4 | streamlit -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI-for-Non-Tech 2 | AI for Non Tech is the repository for all the low code and no code based AI/ML. 3 | -------------------------------------------------------------------------------- /Brain MRI Image Classifier using Teachable Machine/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AI-for-Non-Tech/main/Brain MRI Image Classifier using Teachable Machine/test.png -------------------------------------------------------------------------------- /Brain MRI Image Classifier using Teachable Machine/keras_model.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AI-for-Non-Tech/main/Brain MRI Image Classifier using Teachable Machine/keras_model.h5 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 AI Anytime 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Brain MRI Image Classifier using Teachable Machine/test.py: -------------------------------------------------------------------------------- 1 | from keras.models import load_model 2 | from PIL import Image, ImageOps #Install pillow instead of PIL 3 | import numpy as np 4 | 5 | # Disable scientific notation for clarity 6 | np.set_printoptions(suppress=True) 7 | 8 | # Load the model 9 | model = load_model('keras_model.h5', compile=False) 10 | 11 | # Load the labels 12 | class_names = open('labels.txt', 'r').readlines() 13 | 14 | # Create the array of the right shape to feed into the keras model 15 | # The 'length' or number of images you can put into the array is 16 | # determined by the first position in the shape tuple, in this case 1. 17 | data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32) 18 | 19 | # Replace this with the path to your image 20 | image = Image.open('test.png').convert('RGB') 21 | 22 | #resize the image to a 224x224 with the same strategy as in TM2: 23 | #resizing the image to be at least 224x224 and then cropping from the center 24 | size = (224, 224) 25 | image = ImageOps.fit(image, size, Image.Resampling.LANCZOS) 26 | 27 | #turn the image into a numpy array 28 | image_array = np.asarray(image) 29 | 30 | # Normalize the image 31 | normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1 32 | 33 | # Load the image into the array 34 | data[0] = normalized_image_array 35 | 36 | # run the inference 37 | prediction = model.predict(data) 38 | index = np.argmax(prediction) 39 | class_name = class_names[index] 40 | confidence_score = prediction[0][index] 41 | 42 | print('Class:', class_name, end='') 43 | print('Confidence score:', confidence_score) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /Brain MRI Image Classifier using Teachable Machine/app.py: -------------------------------------------------------------------------------- 1 | from keras.models import load_model 2 | from PIL import Image, ImageOps #Install pillow instead of PIL 3 | import numpy as np 4 | import streamlit as st 5 | 6 | def teachable_machine_classification(img): 7 | # Disable scientific notation for clarity 8 | np.set_printoptions(suppress=True) 9 | 10 | # Load the model 11 | model = load_model('keras_model.h5', compile=False) 12 | 13 | # Load the labels 14 | class_names = open('labels.txt', 'r').readlines() 15 | 16 | # Create the array of the right shape to feed into the keras model 17 | # The 'length' or number of images you can put into the array is 18 | # determined by the first position in the shape tuple, in this case 1. 19 | data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32) 20 | 21 | # Replace this with the path to your image 22 | image = Image.open('test.png').convert('RGB') 23 | 24 | #resize the image to a 224x224 with the same strategy as in TM2: 25 | #resizing the image to be at least 224x224 and then cropping from the center 26 | size = (224, 224) 27 | image = ImageOps.fit(image, size, Image.Resampling.LANCZOS) 28 | 29 | #turn the image into a numpy array 30 | image_array = np.asarray(image) 31 | 32 | # Normalize the image 33 | normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1 34 | 35 | # Load the image into the array 36 | data[0] = normalized_image_array 37 | 38 | # run the inference 39 | prediction = model.predict(data) 40 | index = np.argmax(prediction) 41 | class_name = class_names[index] 42 | confidence_score = prediction[0][index] 43 | 44 | # print('Class:', class_name, end='') 45 | # print('Confidence score:', confidence_score) 46 | 47 | return class_name, confidence_score 48 | 49 | def main(): 50 | st.title("Image Classification with Google's Teachable Machine") 51 | st.header("Brain Tumor MRI Classification") 52 | st.text("Upload a brain MRI image for classification as tumor or no-tumor.") 53 | 54 | uploaded_file = st.file_uploader("Choose a brain MRI....", type="png") 55 | if uploaded_file is not None: 56 | image_file = Image.open(uploaded_file) 57 | st.image(image_file, caption="Uploaded MRI Image", use_column_width=True) 58 | st.write("") 59 | label, confidence_score = teachable_machine_classification(image_file) 60 | if label == "1 Yes\n": 61 | st.error("MRI scan has brain tumor.") 62 | else: 63 | st.success("No brain tumor found in the MRI image.") 64 | 65 | if __name__ == "__main__": 66 | main() --------------------------------------------------------------------------------