Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Projects/Projects list/Project 0/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Project Name
Project description
# Medical x-ray detection using cnn
Prediction of x-ray chest to tell it's normal or pneumonia affected.

# What will you learn
By doing this project you will learn how to build...
This project much good in learning CNN application and it's a good project to showcase

# Dataset for the project
About the dataset and how to download it
Dataset used in this project is taken from kaggle and I used Kaggle API to connect Json file downloaded to authorize connection of dataset to Google colab.The dataset contain normal and pneumonia affected X-ray images,using this apply CNN to predict whether given X-ray is Normal or not.

# What algorithms and frameworks you could use
Suggestion for algorithms and tools to use to do the project
Expand Down
Binary file added Projects/Projects list/Project 0/download.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions Projects/Projects list/Project 0/test_project_xray.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "test project xray.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "_t4OZ9M4Ll1m"
},
"source": [
"import numpy as np\n"
],
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 231
},
"id": "av141GiALqcy",
"outputId": "1684788d-63c5-489b-d7ee-27db751cdbe9"
},
"source": [
"# Testing with sample Chest X-Ray\n",
"hardik_path = '/content/download.jpeg'\n",
"from tensorflow.keras.preprocessing import image\n",
"hardik_img = image.load_img(hardik_path, target_size=(500, 500),color_mode='grayscale')# Preprocessing the image\n",
"pp_hardik_img = image.img_to_array(hardik_img)\n",
"pp_hardik_img = pp_hardik_img/255\n",
"pp_hardik_img = np.expand_dims(pp_hardik_img, axis=0)#predict\n",
"hardik_preds= cnn.predict(pp_hardik_img)#print\n",
"plt.figure(figsize=(6,6))\n",
"plt.axis('off')\n",
"if hardik_preds>= 0.5: \n",
" out = ('I am {:.2%} percent confirmed that this is a Pneumonia case'.format(hardik_preds[0][0]))\n",
" \n",
"else: \n",
" out = ('I am {:.2%} percent confirmed that this is a Normal case'.format(1-hardik_preds[0][0]))\n",
"plt.imshow(np.squeeze(pp_hardik_img))\n",
"plt.show()"
],
"execution_count": 5,
"outputs": [
{
"output_type": "error",
"ename": "NameError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-bb93a755dcbb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mpp_hardik_img\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpp_hardik_img\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m255\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mpp_hardik_img\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpand_dims\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpp_hardik_img\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;31m#predict\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mhardik_preds\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mcnn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpp_hardik_img\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;31m#print\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'off'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'cnn' is not defined"
]
}
]
}
]
}
162 changes: 162 additions & 0 deletions Tasks/Binu/Day_3_task.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Day 3 task.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_7y2KboYO0wK",
"outputId": "8346f8cc-4819-4de7-b3d5-fa5b0cd96301"
},
"source": [
"pip install -q -U tensorflow-text"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[K |████████████████████████████████| 4.4 MB 4.3 MB/s \n",
"\u001b[?25h"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "tPFEUKXqOgxT"
},
"source": [
"import tensorflow as tf\n",
"import tensorflow_text as text\n",
"import functools\n",
"import pathlib\n",
"import collections\n",
"import re\n",
"import string\n",
"\n",
"from tensorflow.keras import layers\n",
"from tensorflow.keras import losses\n",
"from tensorflow.keras import preprocessing\n",
"from tensorflow.keras import utils\n",
"from tensorflow.keras.layers.experimental.preprocessing import TextVectorization\n",
"\n",
"import tensorflow_datasets as tfds"
],
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "x6hxZff8O6G0",
"outputId": "5b2a2b09-3ea6-452c-b07d-870b5ed1bf45"
},
"source": [
"directory_url = 'https://storage.googleapis.com/download.tensorflow.org/data/illiad/'\n",
"file_names = ['cowper.txt', 'derby.txt', 'butler.txt']\n",
"\n",
"#for name in FILE_NAMES:\n",
" #text_dir = utils.get_file(name, origin=DIRECTORY_URL + name)\n",
"\n",
"#parent_dir = pathlib.Path(text_dir).parent\n",
"#list(parent_dir.iterdir())\n",
"\n",
"file_paths = [\n",
" tf.keras.utils.get_file(file_name, directory_url + file_name)\n",
" for file_name in file_names\n",
"]\n",
"\n",
"dataset = tf.data.TextLineDataset(file_paths)\n",
"for line in dataset.take(5):\n",
" print(line.numpy())\n"
],
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/cowper.txt\n",
"819200/815980 [==============================] - 0s 0us/step\n",
"827392/815980 [==============================] - 0s 0us/step\n",
"Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/derby.txt\n",
"811008/809730 [==============================] - 0s 0us/step\n",
"819200/809730 [==============================] - 0s 0us/step\n",
"Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/butler.txt\n",
"811008/807992 [==============================] - 0s 0us/step\n",
"819200/807992 [==============================] - 0s 0us/step\n",
"b\"\\xef\\xbb\\xbfAchilles sing, O Goddess! Peleus' son;\"\n",
"b'His wrath pernicious, who ten thousand woes'\n",
"b\"Caused to Achaia's host, sent many a soul\"\n",
"b'Illustrious into Ades premature,'\n",
"b'And Heroes gave (so stood the will of Jove)'\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Tw_cGtrfmMWg",
"outputId": "d600c40e-f0f7-4c96-a0e1-8df30f1df534"
},
"source": [
"dataset = tf.data.TextLineDataset(file_paths)\n",
"for line in dataset.take(5):\n",
" print(line.numpy().decode(\"utf-8\"))"
],
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Achilles sing, O Goddess! Peleus' son;\n",
"His wrath pernicious, who ten thousand woes\n",
"Caused to Achaia's host, sent many a soul\n",
"Illustrious into Ades premature,\n",
"And Heroes gave (so stood the will of Jove)\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "TUQOFwdfRTQy"
},
"source": [
"text.normalize_utf8(\n",
" input, normalization_form='NFKC', name=None\n",
")"
],
"execution_count": null,
"outputs": []
}
]
}
94 changes: 94 additions & 0 deletions Tasks/Binu/task_5_tinkerhub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-
"""task 5 tinkerhub.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1nCcARJPP5je46FNNBR_M0ccHif_Xm2LL
"""

from tensorflow.keras import layers
from tensorflow.keras import models
import tensorflow_datasets as tfds
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.keras.callbacks import EarlyStopping
import math

import tensorflow.keras.backend as K
import numpy as np



from tensorflow.keras.callbacks import LambdaCallback


from lrfinder import LRFinder

(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True,
with_info=True,
)

def normalize_img(image, label):
"""Normalizes images: `uint8` -> `float32`."""
return tf.cast(image, tf.float32) / 255., label

ds_train = ds_train.map(
normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
ds_train = ds_train.cache()
ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples)
ds_train = ds_train.batch(128)
ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)

ds_test = ds_test.map(
normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
ds_test = ds_test.batch(128)
ds_test = ds_test.cache()
ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)

model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128,activation='relu'),
tf.keras.layers.Dense(10)
])

model.compile(
optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()],
)

BATCH = 128

lr_finder = LRFinder(model)
STEPS_PER_EPOCH = np.ceil(len(ds_train) / BATCH)
lr_finder.find(ds_train, start_lr=1e-6, end_lr=1, epochs=5,
steps_per_epoch=STEPS_PER_EPOCH)
learning_rates = lr_finder.get_learning_rates()
losses = lr_finder.get_losses()
best_lr = lr_finder.get_best_lr(sma=20)
print(best_lr)
K.set_value(model.optimizer.lr, best_lr)

def plot_loss(learning_rates, losses, n_skip_beginning=10, n_skip_end=5, x_scale='log'):
f, ax = plt.subplots()
ax.set_ylabel("loss")
ax.set_xlabel("learning rate (log scale)")
ax.plot(learning_rates[n_skip_beginning:-n_skip_end],
losses[n_skip_beginning:-n_skip_end])
ax.set_xscale(x_scale)
return(ax)

axs = plot_loss(learning_rates, losses)
axs.axvline(x=lr_finder.get_best_lr(sma=20), c='r', linestyle='-.')
plt.show()
earlystop_callback = EarlyStopping(
monitor='val_loss', min_delta=0, patience=3)

history = model.fit(ds_train, epochs=10, validation_data=ds_test, callbacks=[earlystop_callback])
Loading