In the part 1 of the article I write about the model by variable, in this part I will write about the breast diagnosis by image.
It's important to note that to create a model for image the quantity of the sample matter, for the web-app was used 160,000 images, 80,000 for each pathology: metastasis and ductal carcinoma. Also the 80,000 images are divided between Normal and Malign, giving an accuracy of the model of more than 95%.
The object is not to substitute the medical analysis, but help to decrease the False Positive and False Negative. So, we must consider the machine learning like a support for decision, but not to make the decision by itself.
The model was build with Tensorflow, using Sequential model. Once the model is build came the part to use the same to generate the percent by analyzing sample/uploaded image. The web-app: share.streamlit.io/felipelx/hackathon/IDC_D..
I tested with images from internet, and works properly.
Normal to metastasis:
Malign to metastasis:
Transforming the image to be useful for the model.
image_uploaded = tf.keras.preprocessing.image.load_img(uploaded_file, target_size=(96,96),
grayscale = False, interpolation = 'nearest', color_mode = 'rgb', keep_aspect_ratio = False)
# image_uploaded = tf.keras.applications.mobilenet.preprocess_input(image_uploaded)
input_arr = tf.keras.preprocessing.image.img_to_array(image_uploaded)
imput_arr = np.expand_dims(input_arr, axis=0)
imput_arr /= 255
c.image(image_uploaded, channels="RGB")
Showing the result for the user.
@st.cache(allow_output_mutation=True)
def loadMetModel():
model_met = load_model('pages/models/Metastatic_model.h5', compile=True)
model_met.summary()
return model_met
model = loadMetModel()
probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])
prediction = probability_model.predict(input_arr.reshape(1,96,96,3))
dict_pred = {0: 'Benigno/Normal', 1: 'Maligno'}
result = dict_pred[np.argmax(prediction)]
value = 0
if result == 'Benigno/Normal':
value = str(((prediction[0][0])*100).round(2)) + '%'
else:
value = str(((prediction[0][1])*100).round(2)) + '%'
c.metric('Predição', result, delta=value, delta_color='normal')
More than extend myself to explain the application, I invite you to visit the repository and try to use the web-app for your own. Images can be collect from internet when you looks for image like above to breast metastasis or breast carcinoma.
Webapp: share.streamlit.io/felipelx/hackathon/IDCDetector.py Repository: github.com/felipeLx/hackathon/blob/master/p..%F0%9F%94%AC_Metastase_Detector.py