Skip to content

orbant12/Skincancer_binary-classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skin Cancer Binary Classification( Malignant or Bening )

1.) Dataset

Collected Images from isic cli - Shared on my google drive

https://drive.google.com/drive/folders/1RdlCSJl6IwPfvVNwzX6PDbz1KCXHwysM?usp=sharing

Total Images: 3297

Malignant: 1 496

Beingn: 1 801

download download (1) download (2)


2.) Simple Image Decoding

def decode_image(filepath, label): img = tf.io.read_file(filepath) img = tf.image.decode_jpeg(img) img = tf.image.resize(img, [224, 224]) img = tf.cast(img, tf.float32) / 255.0 return img, label


3.) Model Architecture

Screenshot 2024-05-22 at 17 24 32


4.) Results

Loss

download (3)

Accuracy - 0.92

download (4)


+.) Google Cloud

1.) Export Model to Json

    !pip install tensorflowjs
!tensorflowjs_converter \
    --input_format=keras \
    my_model.h5 \
    drive/MyDrive/ML/my_tfjs_model_new

2.) Upload to cloud then load model with Node - @tensorflow-tfjs

const modelUrl = "https://firebasestorage.googleapis.com/v0/....";
const model = await tf.loadLayersModel(modelUrl);

3.) Single Input Base64String - Preprocessing for the model

async function decodeBase64ToTensor(base64String) {
    try {
        const buffer = Buffer.from(base64String, 'base64');
        const { data, info } = await sharp(buffer)
            .resize(224, 224)
            .raw()
            .toBuffer({ resolveWithObject: true });

        const { width, height, channels } = info;
        if (width !== 224 || height !== 224 || channels !== 3) {
            throw new Error('Image is not the correct size or number of channels.');
        }

        const imageTensor = tf.tensor3d(new Uint8Array(data), [height, width, channels]);
        return imageTensor;
    } catch (error) {
        console.error("Error in decodeBase64ToTensor function:", error);
        throw error;
    }
}

function preprocessImage(imageTensor) {
    try {
        // Normalize the image tensor to have values in [0, 1] and add batch dimension
        const normalizedTensor = imageTensor.div(tf.scalar(255.0)).expandDims(0);
        return normalizedTensor;
    } catch (error) {
        console.error("Error in preprocessImage function:", error);
        throw error;
    }
}

4.) Predict Image Tensor

async function predict(model, imageTensor) {
    try {
        // Perform prediction using the loaded model
        const prediction = model.predict(imageTensor);
        const predictionData = await prediction.data();
        return predictionData;
    } catch (error) {
        console.error("Error in predict function:", error);
        throw error;
    }
}

+.) Problems and Solutions

Problem: New moles from the mobile app is very inaccurate, but images from the dataset uploaded trough the app is accurate

1.) Hypothesis: Model does better on the data it has been trained on - Overfitting

Proven wrong by:
    - Creating a validation set with 20% of the full dataset
    - Validation has 0.92 accuracy 
        Therfore this hypothesis is WRONG

2.) Hypothesis: Commonly expected images from the app differs significantly from the images in the dataset

Solution:
    - Collecting each mole image carefully from ISIC ARCHIVE 
        with the following statment: "Could this picture be taken with a phone"
Screenshot 2024-06-05 at 11 17 15

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages