Wednesday, November 13, 2024

Pnemonia Detection Using Resnet 50

        Pnemonia Detection Using Resnet 50

Introduction:

One such architecture is called ResNet-50. ResNet-50 is a convolutional neural network (CNN) that excels at image classification. It's like a highly trained image analyst who can dissect a picture, identify objects and scenes within it, and categorize them accordingly.


Watch In YOUTUBE 😊👇

https://www.youtube.com/watch?v=ZRclV8xclM8




CODE AND DATASET


from fastai import *

from fastai.vision import *

from fastai.metrics import error_rate

import os

import pandas as pd

import numpy as np

from pathlib import Path 

from fastai.vision.all import *



x  = 'C:/Users/Arunnachalam/Downloads/a/pnemonia'

path = Path(x)

path.ls()



np.random.seed(40)

data_block = DataBlock(

    blocks=(ImageBlock, CategoryBlock),     # For image classification

    get_items=get_image_files,              # Get all images in the path

    splitter=RandomSplitter(valid_pct=0.2, seed=40),  # 20% validation split

    get_y=parent_label,                     # Use folder names as labels

    item_tfms=Resize(224),                  # Resize images

    batch_tfms=aug_transforms()             # Apply data augmentations

)



dls = data_block.dataloaders(path, bs=128)   # Set batch size


# Show a batch of images to verify loading

dls.show_batch(max_n=9, figsize=(7, 6))



atOptions = { 'key' : 'ce58cd8ee73c2a7f1378c0c62e645d01', 'format' : 'iframe', 'height' : 90, 'width' : 728, 'params' : {} }; learn = cnn_learner(dls, resnet50, metrics=error_rate)

learn.fine_tune(4)



# Interpret the model results

interp = ClassificationInterpretation.from_learner(learn)


# Plot the confusion matrix

interp.plot_confusion_matrix(figsize=(7,7))


# Load an image and make a prediction

img_path = 'IM-0001-0001.jpeg'  # Path to your image

img = PILImage.create(img_path)  # Open image with PILImage.create


# Predict the class of the image

pred_class, pred_idx, outputs = learn.predict(img)

print(f"Predicted class: {pred_class}")





LINK TO DATASET 😊👇

https://www.kaggle.com/datasets/paultimothymooney/chest-xray-pneumonia


SUPPORT ME 😟

All Courses 😃👇
https://linktr.ee/Freetech2024 All Products 😃👇
https://linktr.ee/rockstararun HP Laptop 🤩👇


No comments:

Post a Comment

SQL INJECTION DETECTION USING RANDOM FOREST CLASSIFIER

  SQL INJECTION DETECTION USING RANDOM FOREST CLASSIFIER