Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit abb553c

Browse files
committed
IntelCaffe release_1.1.4
2 parents 7010334 + 7f06baf commit abb553c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+236309
-136
lines changed

docker/standalone/cpu-centos/Dockerfile

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ RUN rpm -iUvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-rel
1212
redhat-rpm-config \
1313
tar \
1414
findutils \
15-
make \
1615
gcc-c++ \
1716
cmake \
1817
git \
@@ -26,30 +25,12 @@ RUN rpm -iUvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-rel
2625
net-tools \
2726
ufw \
2827
iptables \
29-
atlas-devel \
30-
boost-devel \
31-
gflags-devel \
32-
glog-devel \
33-
hdf5-devel \
34-
leveldb-devel \
35-
lmdb-devel \
36-
opencv-devel \
37-
protobuf-devel \
38-
snappy-devel \
39-
protobuf-compiler \
40-
freetype-devel \
41-
libpng-devel \
42-
python-devel \
43-
python-numpy \
44-
python-pip \
45-
python-scipy \
46-
gcc-gfortran \
47-
libjpeg-turbo-devel && \
28+
gcc-gfortran && \
4829
yum clean all
4930

5031
# Install conda and Intel Caffe conda package
5132
WORKDIR /root/
52-
RUN wget -c https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
33+
RUN wget --no-check-certificate -c https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
5334
bash Miniconda2-latest-Linux-x86_64.sh -b && \
5435
./miniconda2/bin/conda config --add channels intel && \
5536
./miniconda2/bin/conda install -c intel caffe && \

docker/standalone/cpu-ubuntu/Dockerfile

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MAINTAINER [email protected]
66

77
RUN apt-get update && \
88
apt-get install -y --no-install-recommends \
9-
cpio \
9+
bzip2 \
1010
build-essential \
1111
cmake \
1212
git \
@@ -17,31 +17,13 @@ RUN apt-get update && \
1717
vim \
1818
net-tools \
1919
iputils-ping \
20-
screen \
21-
libmlx4-1 libmlx5-1 ibutils rdmacm-utils libibverbs1 ibverbs-utils perftest infiniband-diags \
22-
openmpi-bin libopenmpi-dev \
2320
ufw \
24-
iptables \
25-
libboost-all-dev \
26-
libgflags-dev \
27-
libgoogle-glog-dev \
28-
libhdf5-serial-dev \
29-
libleveldb-dev \
30-
liblmdb-dev \
31-
libopencv-dev \
32-
libprotobuf-dev \
33-
libsnappy-dev \
34-
protobuf-compiler \
35-
python-dev \
36-
python-numpy \
37-
python-pip \
38-
python-setuptools \
39-
python-scipy && \
21+
iptables && \
4022
rm -rf /var/lib/apt/lists/*
4123

4224
# Install conda and Intel Caffe conda package
4325
WORKDIR /root/
44-
RUN wget -c https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
26+
RUN wget --no-check-certificate -c https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh && \
4527
bash Miniconda2-latest-Linux-x86_64.sh -b && \
4628
./miniconda2/bin/conda config --add channels intel && \
4729
./miniconda2/bin/conda install -c intel caffe && \

examples/VNet/DataManager.py

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
import numpy as np
2+
import SimpleITK as sitk
3+
from os import listdir
4+
from os.path import isfile, join, splitext
5+
6+
class DataManager(object):
7+
params=None
8+
srcFolder=None
9+
resultsDir=None
10+
11+
fileList=None
12+
gtList=None
13+
14+
sitkImages=None
15+
sitkGT=None
16+
meanIntensityTrain = None
17+
18+
def __init__(self,srcFolder,resultsDir,parameters):
19+
self.params=parameters
20+
self.srcFolder=srcFolder
21+
self.resultsDir=resultsDir
22+
23+
def createImageFileList(self):
24+
self.fileList = [f for f in listdir(self.srcFolder) if isfile(join(self.srcFolder, f)) and 'segmentation' not in f and 'raw' not in f]
25+
print 'FILE LIST: ' + str(self.fileList)
26+
27+
28+
def createGTFileList(self):
29+
self.gtList=list()
30+
for f in self.fileList:
31+
filename, ext = splitext(f)
32+
self.gtList.append(join(filename + '_segmentation' + ext))
33+
34+
35+
def loadImages(self):
36+
self.sitkImages=dict()
37+
rescalFilt=sitk.RescaleIntensityImageFilter()
38+
rescalFilt.SetOutputMaximum(1)
39+
rescalFilt.SetOutputMinimum(0)
40+
41+
stats = sitk.StatisticsImageFilter()
42+
m = 0.
43+
for f in self.fileList:
44+
self.sitkImages[f]=rescalFilt.Execute(sitk.Cast(sitk.ReadImage(join(self.srcFolder, f)),sitk.sitkFloat32))
45+
stats.Execute(self.sitkImages[f])
46+
m += stats.GetMean()
47+
48+
self.meanIntensityTrain=m/len(self.sitkImages)
49+
50+
51+
def loadGT(self):
52+
self.sitkGT=dict()
53+
54+
for f in self.gtList:
55+
self.sitkGT[f]=sitk.Cast(sitk.ReadImage(join(self.srcFolder, f))>0.5,sitk.sitkFloat32)
56+
57+
58+
59+
def loadTrainingData(self):
60+
self.createImageFileList()
61+
self.createGTFileList()
62+
self.loadImages()
63+
self.loadGT()
64+
65+
66+
def loadTestData(self):
67+
self.createImageFileList()
68+
self.loadImages()
69+
70+
def getNumpyImages(self):
71+
dat = self.getNumpyData(self.sitkImages,sitk.sitkLinear)
72+
return dat
73+
74+
75+
def getNumpyGT(self):
76+
dat = self.getNumpyData(self.sitkGT,sitk.sitkLinear)
77+
78+
for key in dat:
79+
dat[key] = (dat[key]>0.5).astype(dtype=np.float32)
80+
81+
return dat
82+
83+
84+
def getNumpyData(self,dat,method):
85+
ret=dict()
86+
for key in dat:
87+
ret[key] = np.zeros([self.params['VolSize'][0], self.params['VolSize'][1], self.params['VolSize'][2]], dtype=np.float32)
88+
89+
img=dat[key]
90+
91+
#we rotate the image according to its transformation using the direction and according to the final spacing we want
92+
factor = np.asarray(img.GetSpacing()) / [self.params['dstRes'][0], self.params['dstRes'][1],
93+
self.params['dstRes'][2]]
94+
95+
factorSize = np.asarray(img.GetSize() * factor, dtype=float)
96+
97+
newSize = np.max([factorSize, self.params['VolSize']], axis=0)
98+
99+
newSize = newSize.astype(dtype=int)
100+
101+
T=sitk.AffineTransform(3)
102+
T.SetMatrix(img.GetDirection())
103+
104+
resampler = sitk.ResampleImageFilter()
105+
resampler.SetReferenceImage(img)
106+
resampler.SetOutputSpacing([self.params['dstRes'][0], self.params['dstRes'][1], self.params['dstRes'][2]])
107+
resampler.SetSize(newSize)
108+
resampler.SetInterpolator(method)
109+
if self.params['normDir']:
110+
resampler.SetTransform(T.GetInverse())
111+
112+
imgResampled = resampler.Execute(img)
113+
114+
115+
imgCentroid = np.asarray(newSize, dtype=float) / 2.0
116+
117+
imgStartPx = (imgCentroid - self.params['VolSize'] / 2.0).astype(dtype=int)
118+
119+
regionExtractor = sitk.RegionOfInterestImageFilter()
120+
regionExtractor.SetSize(list(self.params['VolSize'].astype(dtype=int)))
121+
regionExtractor.SetIndex(list(imgStartPx))
122+
123+
imgResampledCropped = regionExtractor.Execute(imgResampled)
124+
125+
ret[key] = np.transpose(sitk.GetArrayFromImage(imgResampledCropped).astype(dtype=float), [2, 1, 0])
126+
127+
return ret
128+
129+
130+
def writeResultsFromNumpyLabel(self,result,key):
131+
img = self.sitkImages[key]
132+
133+
toWrite=sitk.Image(img.GetSize()[0],img.GetSize()[1],img.GetSize()[2],sitk.sitkFloat32)
134+
135+
factor = np.asarray(img.GetSpacing()) / [self.params['dstRes'][0], self.params['dstRes'][1],
136+
self.params['dstRes'][2]]
137+
138+
factorSize = np.asarray(img.GetSize() * factor, dtype=float)
139+
140+
newSize = np.max([factorSize, self.params['VolSize']], axis=0)
141+
142+
newSize = newSize.astype(dtype=int)
143+
144+
T = sitk.AffineTransform(3)
145+
T.SetMatrix(img.GetDirection())
146+
147+
resampler = sitk.ResampleImageFilter()
148+
resampler.SetReferenceImage(img)
149+
resampler.SetOutputSpacing([self.params['dstRes'][0], self.params['dstRes'][1], self.params['dstRes'][2]])
150+
resampler.SetSize(newSize)
151+
resampler.SetInterpolator(sitk.sitkNearestNeighbor)
152+
153+
if self.params['normDir']:
154+
resampler.SetTransform(T.GetInverse())
155+
156+
toWrite = resampler.Execute(toWrite)
157+
158+
imgCentroid = np.asarray(newSize, dtype=float) / 2.0
159+
160+
imgStartPx = (imgCentroid - self.params['VolSize'] / 2.0).astype(dtype=int)
161+
162+
for dstX, srcX in zip(range(0, result.shape[0]), range(imgStartPx[0],int(imgStartPx[0]+self.params['VolSize'][0]))):
163+
for dstY, srcY in zip(range(0, result.shape[1]), range(imgStartPx[1], int(imgStartPx[1]+self.params['VolSize'][1]))):
164+
for dstZ, srcZ in zip(range(0, result.shape[2]), range(imgStartPx[2], int(imgStartPx[2]+self.params['VolSize'][2]))):
165+
try:
166+
toWrite.SetPixel(int(srcX),int(srcY),int(srcZ),float(result[dstX,dstY,dstZ]))
167+
except:
168+
pass
169+
170+
171+
resampler.SetOutputSpacing([img.GetSpacing()[0], img.GetSpacing()[1], img.GetSpacing()[2]])
172+
resampler.SetSize(img.GetSize())
173+
174+
if self.params['normDir']:
175+
resampler.SetTransform(T)
176+
177+
toWrite = resampler.Execute(toWrite)
178+
179+
thfilter=sitk.BinaryThresholdImageFilter()
180+
thfilter.SetInsideValue(1)
181+
thfilter.SetOutsideValue(0)
182+
thfilter.SetLowerThreshold(0.5)
183+
toWrite = thfilter.Execute(toWrite)
184+
185+
#connected component analysis (better safe than sorry)
186+
187+
cc = sitk.ConnectedComponentImageFilter()
188+
toWritecc = cc.Execute(sitk.Cast(toWrite,sitk.sitkUInt8))
189+
190+
arrCC=np.transpose(sitk.GetArrayFromImage(toWritecc).astype(dtype=float), [2, 1, 0])
191+
192+
lab=np.zeros(int(np.max(arrCC)+1),dtype=float)
193+
194+
for i in range(1,int(np.max(arrCC)+1)):
195+
lab[i]=np.sum(arrCC==i)
196+
197+
activeLab=np.argmax(lab)
198+
199+
toWrite = (toWritecc==activeLab)
200+
201+
toWrite = sitk.Cast(toWrite,sitk.sitkUInt8)
202+
203+
writer = sitk.ImageFileWriter()
204+
filename, ext = splitext(key)
205+
#print join(self.resultsDir, filename + '_result' + ext)
206+
writer.SetFileName(join(self.resultsDir, filename + '_result' + ext))
207+
writer.Execute(toWrite)
208+

0 commit comments

Comments
 (0)