当前位置: 首页 > news >正文

建立学校网站做营销的有那么网站

建立学校网站,做营销的有那么网站,win主机 wordpress静态,无锡华士镇网站建设文章目录 一、前言二、前期工作1. 介绍2. 加载和预处理数据 二、构建训练和验证集三、数据增强四、数据可视化五、构建3D卷积神经网络模型六、训练模型七、可视化模型性能八、对单次 CT 扫描进行预测 一、前言 我的环境#xff1a; 语言环境#xff1a;Python3.6.5编译器 语言环境Python3.6.5编译器jupyter notebook深度学习环境TensorFlow2.4.1 往期精彩内容 卷积神经网络CNN实现mnist手写数字识别 卷积神经网络CNN多种图片分类的实现卷积神经网络CNN衣服图像分类的实现卷积神经网络CNN鲜花识别卷积神经网络CNN天气识别 卷积神经网络VGG-16识别海贼王草帽一伙卷积神经网络ResNet-50鸟类识别 卷积神经网络AlexNet鸟类识别卷积神经网络(CNN)识别验证码 来自专栏机器学习与深度学习算法推荐 二、前期工作 1. 介绍 本案例将展示通过构建 3D 卷积神经网络 (CNN) 来预测计算机断层扫描 (CT) 中病毒性肺炎是否存在。 2D 的 CNN 通常用于处理 RGB 图像3 个通道。 3D 的 CNN 仅仅是 3D 等价物我们可以将 3D 图像简单理解成 2D 图像的叠加。3D 的 CNN 可以理解成是学习立体数据的强大模型。 import os,zipfile import numpy as np from tensorflow import keras from tensorflow.keras import layersimport tensorflow as tf gpus tf.config.list_physical_devices(GPU)if gpus:tf.config.experimental.set_memory_growth(gpus[0], True) #设置GPU显存用量按需使用tf.config.set_visible_devices([gpus[0]],GPU)# 打印显卡信息确认GPU可用 print(gpus)2. 加载和预处理数据 数据文件是 Nifti扩展名为 .nii。我使用nibabel 包来读取文件你可以通过 pip install nibabel 来安装 nibabel 包。 数据预处理步骤 首先将体积旋转 90 度确保方向是固定的将 HU 值缩放到 0 和 1 之间。调整宽度、高度和深度。 我定义了几个辅助函数来完成处理数据这些功能将在构建训练和验证数据集时使用。 import nibabel as nib from scipy import ndimagedef read_nifti_file(filepath):# 读取文件scan nib.load(filepath)# 获取数据scan scan.get_fdata()return scandef normalize(volume):归一化min -1000max 400volume[volume min] minvolume[volume max] maxvolume (volume - min) / (max - min)volume volume.astype(float32)return volumedef resize_volume(img):修改图像大小# Set the desired depthdesired_depth 64desired_width 128desired_height 128# Get current depthcurrent_depth img.shape[-1]current_width img.shape[0]current_height img.shape[1]# Compute depth factordepth current_depth / desired_depthwidth current_width / desired_widthheight current_height / desired_heightdepth_factor 1 / depthwidth_factor 1 / widthheight_factor 1 / height# 旋转img ndimage.rotate(img, 90, reshapeFalse)# 数据调整img ndimage.zoom(img, (width_factor, height_factor, depth_factor), order1)return imgdef process_scan(path):# 读取文件volume read_nifti_file(path)# 归一化volume normalize(volume)# 调整尺寸 width, height and depthvolume resize_volume(volume)return volume读取CT扫描文件的路径 # “CT-0”文件夹中是正常肺组织的CT扫描 normal_scan_paths [os.path.join(os.getcwd(), MosMedData/CT-0, x)for x in os.listdir(MosMedData/CT-0) ]# “CT-23”文件夹中是患有肺炎的人的CT扫描 abnormal_scan_paths [os.path.join(os.getcwd(), MosMedData/CT-23, x)for x in os.listdir(MosMedData/CT-23) ]print(CT scans with normal lung tissue: str(len(normal_scan_paths))) print(CT scans with abnormal lung tissue: str(len(abnormal_scan_paths)))CT scans with normal lung tissue: 100 CT scans with abnormal lung tissue: 100# 读取数据并进行预处理 abnormal_scans np.array([process_scan(path) for path in abnormal_scan_paths]) normal_scans np.array([process_scan(path) for path in normal_scan_paths])# 标签数字化 abnormal_labels np.array([1 for _ in range(len(abnormal_scans))]) normal_labels np.array([0 for _ in range(len(normal_scans))])二、构建训练和验证集 从类目录中读取扫描并分配标签。对扫描进行下采样以具有 128x128x64 的形状。将原始 HU 值重新调整到 0 到 1 的范围内。最后将数据集拆分为训练和验证子集。 # 按照7:3的比例划分训练集、验证集 x_train np.concatenate((abnormal_scans[:70], normal_scans[:70]), axis0) y_train np.concatenate((abnormal_labels[:70], normal_labels[:70]), axis0) x_val np.concatenate((abnormal_scans[70:], normal_scans[70:]), axis0) y_val np.concatenate((abnormal_labels[70:], normal_labels[70:]), axis0) print(Number of samples in train and validation are %d and %d.% (x_train.shape[0], x_val.shape[0]) )Number of samples in train and validation are 140 and 60.三、数据增强 CT扫描也通过在训练期间在随机角度旋转来增强数据。由于数据存储在Rank-3的形状样本高度宽度深度中因此我们在轴4处添加大小1的尺寸以便能够对数据执行3D卷积。因此新形状样品高度宽度深度1。在那里有不同类型的预处理和增强技术这个例子显示了一些简单的开始。 import random from scipy import ndimagetf.function def rotate(volume):不同程度上进行旋转def scipy_rotate(volume):# 定义一些旋转角度angles [-20, -10, -5, 5, 10, 20]# 随机选择一个角度angle random.choice(angles)volume ndimage.rotate(volume, angle, reshapeFalse)volume[volume 0] 0volume[volume 1] 1return volumeaugmented_volume tf.numpy_function(scipy_rotate, [volume], tf.float32)return augmented_volumedef train_preprocessing(volume, label):volume rotate(volume)volume tf.expand_dims(volume, axis3)return volume, labeldef validation_preprocessing(volume, label):volume tf.expand_dims(volume, axis3)return volume, label在定义训练和验证数据加载器的同时训练数据将进行不同角度的随机旋转。训练和验证数据都已重新调整为具有 0 到 1 之间的值。 # 定义数据加载器 train_loader tf.data.Dataset.from_tensor_slices((x_train, y_train)) validation_loader tf.data.Dataset.from_tensor_slices((x_val, y_val))batch_size 2train_dataset (train_loader.shuffle(len(x_train)).map(train_preprocessing).batch(batch_size).prefetch(2) )validation_dataset (validation_loader.shuffle(len(x_val)).map(validation_preprocessing).batch(batch_size).prefetch(2) )四、数据可视化 import matplotlib.pyplot as pltdata train_dataset.take(1) images, labels list(data)[0] images images.numpy() image images[0] print(Dimension of the CT scan is:, image.shape) plt.imshow(np.squeeze(image[:, :, 30]), cmapgray)Dimension of the CT scan is: (128, 128, 64, 1)def plot_slices(num_rows, num_columns, width, height, data):Plot a montage of 20 CT slicesdata np.rot90(np.array(data))data np.transpose(data)data np.reshape(data, (num_rows, num_columns, width, height))rows_data, columns_data data.shape[0], data.shape[1]heights [slc[0].shape[0] for slc in data]widths [slc.shape[1] for slc in data[0]]fig_width 12.0fig_height fig_width * sum(heights) / sum(widths)f, axarr plt.subplots(rows_data,columns_data,figsize(fig_width, fig_height),gridspec_kw{height_ratios: heights},)for i in range(rows_data):for j in range(columns_data):axarr[i, j].imshow(data[i][j], cmapgray)axarr[i, j].axis(off)plt.subplots_adjust(wspace0, hspace0, left0, right1, bottom0, top1)plt.show()# Visualize montage of slices. # 4 rows and 10 columns for 100 slices of the CT scan. plot_slices(4, 10, 128, 128, image[:, :, :40])五、构建3D卷积神经网络模型 为了使模型更容易理解我将其构建成块。 def get_model(width128, height128, depth64):构建 3D 卷积神经网络模型inputs keras.Input((width, height, depth, 1))x layers.Conv3D(filters64, kernel_size3, activationrelu)(inputs)x layers.MaxPool3D(pool_size2)(x)x layers.BatchNormalization()(x)x layers.Conv3D(filters64, kernel_size3, activationrelu)(x)x layers.MaxPool3D(pool_size2)(x)x layers.BatchNormalization()(x)x layers.Conv3D(filters128, kernel_size3, activationrelu)(x)x layers.MaxPool3D(pool_size2)(x)x layers.BatchNormalization()(x)x layers.Conv3D(filters256, kernel_size3, activationrelu)(x)x layers.MaxPool3D(pool_size2)(x)x layers.BatchNormalization()(x)x layers.GlobalAveragePooling3D()(x)x layers.Dense(units512, activationrelu)(x)x layers.Dropout(0.3)(x)outputs layers.Dense(units1, activationsigmoid)(x)# 定义模型model keras.Model(inputs, outputs, name3dcnn)return model# 构建模型 model get_model(width128, height128, depth64) model.summary()六、训练模型 # 设置动态学习率 initial_learning_rate 1e-4 lr_schedule keras.optimizers.schedules.ExponentialDecay(initial_learning_rate, decay_steps30, decay_rate0.96, staircaseTrue ) # 编译 model.compile(lossbinary_crossentropy,optimizerkeras.optimizers.Adam(learning_ratelr_schedule),metrics[acc], ) # 保存模型 checkpoint_cb keras.callbacks.ModelCheckpoint(3d_image_classification.h5, save_best_onlyTrue ) # 定义早停策略 early_stopping_cb keras.callbacks.EarlyStopping(monitorval_acc, patience15)epochs 100 model.fit(train_dataset,validation_datavalidation_dataset,epochsepochs,shuffleTrue,verbose2,callbacks[checkpoint_cb, early_stopping_cb], )七、可视化模型性能 fig, ax plt.subplots(1, 2, figsize(20, 3)) ax ax.ravel()for i, metric in enumerate([acc, loss]):ax[i].plot(model.history.history[metric])ax[i].plot(model.history.history[val_ metric])ax[i].set_title(Model {}.format(metric))ax[i].set_xlabel(epochs)ax[i].set_ylabel(metric)ax[i].legend([train, val])八、对单次 CT 扫描进行预测 # 加载模型 model.load_weights(3d_image_classification.h5) prediction model.predict(np.expand_dims(x_val[0], axis0))[0] scores [1 - prediction[0], prediction[0]]class_names [normal, abnormal] for score, name in zip(scores, class_names):print(This model is %.2f percent confident that CT scan is %s% ((100 * score), name))This model is 27.88 percent confident that CT scan is normal This model is 72.12 percent confident that CT scan is abnormal
http://www.hkea.cn/news/14311946/

相关文章:

  • 论坛网站模板免费下载提供商城网站制作
  • 国外做外汇网站交流沧州高端网站建设
  • 盐山做网站是一种特色的网络营销方式
  • 北京网站平台建设公司南昌中小企业网站制作
  • 官方网站开发方案网站开发工具 售价
  • 北京便宜做网站视频剪辑线下培训班
  • 网站详情页链接怎么做wordpress 选择用户
  • 结构设计网站推荐企业所得税的计算公式三种
  • 如何查公司网站开发时间wordpress插件doc
  • 网站链接优化怎么做空间网架
  • 郑州logo设计公司泰州整站优化
  • 加强机关网站内容建设电商平台设计公司
  • 做企业网站的尺寸是多少免费开源网站系统有哪些
  • 毕设做网站答辩会要求当场演示吗网络建设包括哪些内容
  • 徐州泉山建设局网站上海中国建设银行招聘信息网站
  • 建设部造价工程师考试网站设计坞官网
  • 乡村旅游网站建设中国建设银行理财网站
  • 网站设计实例教程一个公司怎么做网站都放些什么
  • 甘肃建设厅网站二级建造师报名时间免费的舆情网站不需下载
  • 网站营销目标怎么看网站空间
  • 韩都衣舍网站建设方案全国企业信息公示(全国)
  • 怎么请人做网站家装用什么软件设计
  • 二级域名网站建设规范杭州网站推广方式
  • otc场外交易网站开发邯郸信息港邯郸信息网
  • 本地网站环境搭建施工企业质量管理体系应按照我国
  • 迅睿cms建站教程wordpress不同语言
  • 阜康市建设银行网站html后台网站模板
  • 长沙英文网站建设公司网站怎么做后台
  • 中山网站建设公司哪家好阿里云wordpress root
  • 青岛专业公司网站设计用iis制作简单网站