https://drive.google.com/drive/folders/1RdlCSJl6IwPfvVNwzX6PDbz1KCXHwysM?usp=sharing
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
!pip install tensorflowjs
!tensorflowjs_converter \
--input_format=keras \
my_model.h5 \
drive/MyDrive/ML/my_tfjs_model_new
const modelUrl = "https://firebasestorage.googleapis.com/v0/....";
const model = await tf.loadLayersModel(modelUrl);
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;
}
}
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;
}
}
Problem: New moles from the mobile app is very inaccurate, but images from the dataset uploaded trough the app is accurate
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](https://private-user-images.githubusercontent.com/124793231/336772999-b1d52ffe-f4e7-4477-a1b9-490aae58fda0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwOTcwNTksIm5iZiI6MTcyNjA5Njc1OSwicGF0aCI6Ii8xMjQ3OTMyMzEvMzM2NzcyOTk5LWIxZDUyZmZlLWY0ZTctNDQ3Ny1hMWI5LTQ5MGFhZTU4ZmRhMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMVQyMzE5MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xMDE4NDhiOGEyMzBiM2ZiNzU5M2VkODgzZDA2NTg4MjEyNmYxM2I5N2M5Y2I4YjljODE2MmQ4OTYzOWE4ZDllJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.si9WdqIq2L-0syZkMbHU8lo6ULbUX0NJN8szUd607W0)