title: U-Net与胰腺分割学习(1)
date: 2020-08-29 08:15:02
tags:
- CNN
- 前馈神经网络
- 图像识别
- U-Net
- 胰腺分割
categories: - 医学图像处理与医学软件
TCIA (The Cancer Imaging Archive)
TCIA是一个包含常见肿瘤(肺癌、前列腺癌等)医学图像及相应临床信息(治疗方案细节、基因、病理等)的大规模公用数据库,其影像模态包括MRI、CT等,图像格式均为DICOM,并且网站内数据在持续增加。所有数据都是由TCIA整理并管理。
网址:http://www.cancerimagingarchive.net/
通过点击Download下载,在电脑上得到后缀名为’.tcia’的文件,注意该文件必须通过‘NBIA DATA Retriever’软件打开,打开后就可以通过选择保存路径,开始下载数据集;(需要VPN)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-foJhm3wK-1642241531467)(/images/image-20200829081625498.png)]
管理conda
conda添加到环境变量
1. 验证conda已被安装
conda --version
2. 获取当前环境中已安装的包信息
conda list
Python包安装错误的解决办法
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: C:\ProgramData\Anaconda3
无法写入错误:当前的用户没有写入到该路径文件的权限
以管理员身份启动Anaconda(Anaconda Navigator或者Anaconda Prompt)
安装Pydicom
conda install -c conda-forge pydicom
安装完毕
ImportError:通过“import dicom”的Pydicom已经在Pydicom 1.0版本中被删除,请安装dicom包来恢复依赖于Pydicom 0.9的代码的功能或更早。例如,pip install dicom交替,大多数代码可以轻松转换为pydicom>1.0通过改变import 1ines从import dicom到import pydicomiSee过渡指南
pip install dicom
DICOM转换为Numpy数组数据
python dicom2npy.py
执行Python文件
import numpy as np
import os
import pydicom
N = 82
W = 512
H = 512
path1 = 'DOI'
path2 = 'images'
if not os.path.exists(path2):
os.makedirs(path2)
for n in range(N):
volumeID = '{:0>4}'.format(n + 1)
# 宽度 :后带填充的字符 0001~0082
print ('Processing File ' + volumeID)
print ('正在处理文件' + volumeID)
# Processing File 0001 ~0082
filename1 = 'PANCREAS_' + volumeID
# PANCREAS_0001 ~PANCREAS_0082
directory1 = os.path.join(path1, filename1)
print ('directory1:' + directory1)
# 把目录和文件名合成一个路径 directory1 = DOI/PANCREAS_0001/
filename2 = volumeID + '.npy'
# filename2 = 0001.npy ~0082.npy
for path_, _, file_ in os.walk(directory1):
#for dirpath, _dirnames,filenames in os.walk(path):
print (path_,_,file_)
# 文件夹的绝对路径,dirpath 文件夹下的子文件夹的名字,dirnames 文件夹的文件的名字,filenames
#注意,函数会自动改变root的值使得遍历所有的子文件夹。、
#所以返回的三元元组的个数为所有子文件夹(包括子子文件夹,子子子文件夹等等)加上1(根文件夹)。
L = len(file_)
# 文件夹内文件的个数 files 同样是 list , 内容是该文件夹中所有的文件(不包括子目录)
if L > 0:
print (' ' + str(L) + ' slices along the axial view.')
#沿轴向视图切片
data = np.zeros((W, H, L), dtype = np.int16)
for f in sorted(file_):
file1 = os.path.abspath(os.path.join(path_, f)) #绝对路径
print ('file1:' + file1)
image = pydicom.read_file(file1)
sliceID = image.data_element("InstanceNumber").value - 1
if image.pixel_array.shape[0] != 512 or image.pixel_array.shape[1] != 512:
exit(' Error: DICOM image does not fit ' + str(W) + 'x' + str(H) + ' size!')
data[:, :, sliceID] = image.pixel_array
file2 = os.path.join(path2, filename2)
np.save(file2, data)
print ('File ' + volumeID + ' is saved in ' + file2 + ' .')
Nibabel
conda install -c conda-forge nibabel
然后我发现他这个执行脚本是Linux的…
在VMware安装Ubuntu的时候发现下载异常的慢,然后上网搜要跳过SKIP(- -)换源
在Ubuntu里安装Anaconda
cd /mnt/hgfs/UbuntuSharedFolder
bash Anaconda3-2020.07-Linux-x86_64.sh
Anaconda3的安装目录
退出终端,重新进来就出现了(base)
,则安装成功。
source ~/anaconda3/bin/activate root
anaconda-navigator
出现anaconda图形界面加载一会儿,就可以将其添加到任务栏或收藏夹上,下次可直接点击该图标即可实现可视化anaconda图形界面的操作。
然后安装Pydicom和上面步骤一样
更改脚本里的文件夹路径
DIR="/mnt/hgfs/UbuntuSharedFolder/images"
CUDA安装
不知道为什么CUDA安装完虚拟机就崩了,崩溃中…虚拟机方案失败,接下来试试子系统
网上搜索了一下好像虚拟机不能用CUDA加速,难道真的要安装双系统了吗…
先来试一试Windows的Ubuntu子系统看能不能使用物理显卡加速深度学习计算
先试试结果怎么样,真要用服务器计算的话就之后再说
Win10安装Ubuntu子系统
关于Linux的安装位置
WindowsAPP拒绝访问的解决办法
其中我把Administrator换为了Everyone
找到了Ubuntu安装位置
换源
cd /etc/apt
sudo cp /etc/apt/sources.list /etc/apt/sources.list_b
sudo nano sources.list
Ctrl+K全删完
- 中科大镜像
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
sudo apt-get update
sudo apt-get upgrade
-------------------------------废弃
安装VcXsrv
https://sourceforge.net/projects/vcxsrv/
其余默认下一步
保存设置到桌面直接启动
Ubuntu内安装桌面环境
sudo apt-get install ubuntu-desktop unity compizconfig-settings-manager
------------------------------------------废弃
尝试之后发现XcXsrv并不好用,还报了很多错,放弃。
通过本机远程桌面
安装xorg(包括显卡驱动、图形环境库等等一系列软件包)
sudo apt-get install xorg
安装xfce4(运行在类Unix操作系统上,提供轻量级桌面环境)
sudo apt-get install xfce4
安装xrdp(一种开源的远程桌面协议(RDP)服务器)
sudo apt-get install xrdp
配置xrdp(配置端口)
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini
向.xsession中写入xfce4-session
sudo echo xfce4-session >~/.xsession
重启xrdp服务
sudo service xrdp restart
在Cortana中搜索远程桌面连接,点击进入,计算机栏输入【本机IP:端口】,用户名栏输入子系统用户名,点击连接。
127.0.0.1:3390
PiP设置
临时使用 加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider
mkdir ~/.pip
cd .pip
touch pip.conf
nano pip.conf
pip.conf内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
Tensenflow安装
安完Ubuntu没有pip,先安装pip
sudo apt-get install python3-dev python-scipy python-numpy python-matplotlib python-pandas python-nose
# Requires the latest pip 升级pip
pip install --upgrade pip
# Current stable release for CPU and GPU
pip install tensorflow
sudo apt-get install python-pip
pip install tensorflow
# 系统升级
sudo apt update
sudo apt upgrade
# 安装python基础开发包
sudo apt install -y python-dev python-pip python-nose gcc g++ git gfortran vim
- 安装运算加速库 打开
终端
输入:
sudo apt install -y libopenblas-dev liblapack-dev libatlas-base-dev
CUDA开发环境的搭建
https://developer.nvidia.com/cuda-downloads
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-ubuntu1604.pin
sudo mv cuda-ubuntu1604.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda-repo-ubuntu1604-11-0-local_11.0.3-450.51.06-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604-11-0-local_11.0.3-450.51.06-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1604-11-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
- 将CUDA路径添加至环境变量 在
终端
输入:
sudo gedit /etc/profile
在profile
文件中添加:
export CUDA_HOME=/usr/local/cuda-11.0
export PATH=/usr/local/cuda-11.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
之后source /etc/profile
即可
- 测试 在
终端
输入:
nvcc -V
会得到相应的nvcc编译器相应的信息,那么CUDA配置成功了。(记得重启系统)
如果要进行cuda性能测试
,可以进行:
cd /usr/local/cuda/samples
sudo make -j8
编译完成后,可以进samples/bin/.../.../...
的底层目录,运行各类实例。
no CUDA-capable device is detected
请问win10下的ubuntu子系统可以配置gpu深度学习环境吗?
win10下使用Ubuntu子系统调用GPU失败,下一个方案,docker调用GPU搭建深度学习环境
Keras安装
sudo pip install keras
Win10安装Ubuntu子系统及图形化界面详细教程
Win10系统下WindowsApps文件夹拒绝访问如何获取权限
win10 linux Ubuntu 18.04更换国内源