機器學習中用於對面板癌的檢測技術

面板癌是美國最常見的疾病之一。在過去的一年中,據報道有多達400萬例死於面板癌的病例。在本文中,我將使用機器學習建立面板癌分類模型。

機器學習對面板癌的分類

這是機器學習演算法在面板癌分類中起作用的地方。正如之前提到的,面板癌在疾病的早期階段很容易治癒,但很多人都不清楚是否患了該疾病。

因此,這個分類演算法,可以幫助那些人坐在家裡時確定他們是否患有面板癌。該機器學習演算法主要基於卷積神經網路(CNN)。

CNN層分類用於面板癌檢測

讓我們從匯入庫開始

import numpy as npfrom skimage import ioimport matplotlib。pyplot as plt

現在,我將簡單地上傳影象,以使用python中的skimage庫來訓練我們的機器學習模型。

imgb = io。imread(‘bimg-1049。png’)imgm = io。imread(‘mimg-178。png’)imgb = io。imread(‘bimg-721。png’)imgm = io。imread(‘mimg-57。png’)

您可以從下面下載這些影象

連結:https://pan。baidu。com/s/17UB13G3NckDH4mXW7Bf25w

提取碼:nh9p

這些影象是良性痣和惡性痣的樣本影象,這是一種面板問題。

展示這些影象

plt。figure(figsize=(10,20))plt。subplot(121)plt。imshow(imgb)plt。axis(‘off’)plt。subplot(122)plt。imshow(imgm)plt。axis(‘off’)

機器學習中用於對面板癌的檢測技術

訓練模型以進行進一步分類

from keras。models import load_modelmodel = load_model(‘BM_VA_VGG_FULL_DA。hdf5’)from keras import backend as Kdef activ_viewer(model, layer_name, im_put): layer_dict = dict([(layer。name, layer) for layer in model。layers]) layer = layer_dict[layer_name] activ1 = K。function([model。layers[0]。input, K。learning_phase()], [layer。output,]) activations = activ1((im_put, False)) return activationsdef normalize(x): # utility function to normalize a tensor by its L2 norm return x / (K。sqrt(K。mean(K。square(x))) + 1e-5)def deprocess_image(x): # normalize tensor: center on 0。, ensure std is 0。1 x -= x。mean() x /= (x。std() + 1e-5) x *= 0。1 # clip to [0, 1] x += 0。5 x = np。clip(x, 0, 1) # convert to RGB array x *= 255 if K。image_data_format() == ‘channels_first’: x = x。transpose((1, 2, 0)) x = np。clip(x, 0, 255)。astype(‘uint8’) return xdef plot_filters(filters): newimage = np。zeros((16*filters。shape[0],8*filters。shape[1])) for i in range(filters。shape[2]): y = i%8 x = i//8 newimage[x*filters。shape[0]:x*filters。shape[0]+filters。shape[0], y*filters。shape[1]:y*filters。shape[1]+filters。shape[1]] = filters[:,:,i] plt。figure(figsize = (10,20)) plt。imshow(newimage) plt。axis(‘off’)

面板癌分類模型

要檢視我們訓練有素的模型的總結,我們將執行以下程式碼

model。summary()

model。summary()

_________________________________________________________________Layer (type) Output Shape Param # ======================================================input_1 (InputLayer) (None, 128, 128, 3) 0 _________________________________________________________________block1_conv1 (Conv2D) (None, 128, 128, 64) 1792 _________________________________________________________________block1_conv2 (Conv2D) (None, 128, 128, 64) 36928 _________________________________________________________________block1_pool (MaxPooling2D) (None, 64, 64, 64) 0 _________________________________________________________________block2_conv1 (Conv2D) (None, 64, 64, 128) 73856 _________________________________________________________________block2_conv2 (Conv2D) (None, 64, 64, 128) 147584 _________________________________________________________________block2_pool (MaxPooling2D) (None, 32, 32, 128) 0 _________________________________________________________________block3_conv1 (Conv2D) (None, 32, 32, 256) 295168 _________________________________________________________________block3_conv2 (Conv2D) (None, 32, 32, 256) 590080 _________________________________________________________________block3_conv3 (Conv2D) (None, 32, 32, 256) 590080 _________________________________________________________________block3_pool (MaxPooling2D) (None, 16, 16, 256) 0 _________________________________________________________________block4_conv1 (Conv2D) (None, 16, 16, 512) 1180160 _________________________________________________________________block4_conv2 (Conv2D) (None, 16, 16, 512) 2359808 _________________________________________________________________block4_conv3 (Conv2D) (None, 16, 16, 512) 2359808 _________________________________________________________________block4_pool (MaxPooling2D) (None, 8, 8, 512) 0 _________________________________________________________________block5_conv1 (Conv2D) (None, 8, 8, 512) 2359808 _________________________________________________________________block5_conv2 (Conv2D) (None, 8, 8, 512) 2359808 _________________________________________________________________block5_conv3 (Conv2D) (None, 8, 8, 512) 2359808 _________________________________________________________________block5_pool (MaxPooling2D) (None, 4, 4, 512) 0 _________________________________________________________________sequential_3 (Sequential) (None, 1) 2097665 ====================================================Total params: 16,812,353Trainable params: 16,812,353Non-trainable params: 0

視覺化我們訓練過的模型的輸出

activ_benign = activ_viewer(model,‘block2_conv1’,imgb。reshape(1,128,128,3))img_benign = deprocess_image(activ_benign[0])plot_filters(img_benign[0])plt。figure(figsize=(20,20))for f in range(128): plt。subplot(8,16,f+1) plt。imshow(img_benign[0,:,:,f]) plt。axis(‘off’)

縮放和視覺化一些過濾器

plt。figure(figsize=(10,10))plt。subplot(121)plt。imshow(img_benign[0,:,:,49])plt。axis(‘off’)plt。subplot(122)plt。imshow(img_malign[0,:,:,49])plt。axis(‘off’)

機器學習中用於對面板癌的檢測技術

測試模型

現在讓我們視覺化並測試我們訓練後的模型的實際能力

def plot_filters32(filters): newimage = np。zeros((16*filters。shape[0],16*filters。shape[1])) for i in range(filters。shape[2]): y = i%16 x = i//16 newimage[x*filters。shape[0]:x*filters。shape[0]+filters。shape[0], y*filters。shape[1]:y*filters。shape[1]+filters。shape[1]] = filters[:,:,i] plt。figure(figsize = (15,25)) plt。imshow(newimage) activ_benign = activ_viewer(model,‘block3_conv3’,imgb。reshape(1,128,128,3))img_benign = deprocess_image(activ_benign[0])plot_filters32(img_benign[0])

機器學習中用於對面板癌的檢測技術

原文連結:https://blog。csdn。net/huangmingleiluo/article/details/117357650

TAG: