Ejemplo n.º 1
0
from nolearn.lasagne import NeuralNet
from nolearn.lasagne import visualize
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
import sklearn

from lasagne.layers import InputLayer, Conv2DLayer, DenseLayer, MaxPool2DLayer, InverseLayer

### DATASET
dataSet = myTools.loadImages('../../images', 1024, 1024, 4)

dataSet = myTools.oneDimension(dataSet)

dataSet = dataSet.astype(numpy.uint8)

dataSet = myTools.cropCenter(dataSet, 80)

dataSet = myTools.augmentData(dataSet,
                              numOfTiles=4,
                              overlap=False,
                              imageWidth=819,
                              imageHeight=819)

dataSet = dataSet.astype(numpy.float32)
#plt.show(plt.imshow(dataSet[0][0], cmap=cm.binary))

### MASKS
masks = myTools.loadImages('../../masks', 819, 819, 1)

for x in numpy.nditer(masks, op_flags=['readwrite']):
    if x > 0:
Ejemplo n.º 2
0
#open the image
image = Image.open(imagePath)
#image as numpy array
image = numpy.asarray(image)
#keep only one dimension
image = image[:, :, 0]
#most needed type casting
image = image.astype(numpy.uint8)
#crop the center
image = myTools.cropCenter1(image, 100)
#this step is mysteriously needed
image = myTools.augmentMasks(image.reshape(1, 1, image.shape[0],
                                           image.shape[1]),
                             numOfTiles=1,
                             overlap=False,
                             imageWidth=image.shape[0],
                             imageHeight=image.shape[1])
#another vital type casting
image = image.astype(numpy.float32)
#setting parameters for the network
data_size = (None, 1, image[0][0].shape[0], image[0][0].shape[1])
#load the pretrained network
myNet = myTools.createPretrainedNN(data_size)
#make predictions for the image
res = myNet(image)
#crop the center of the mask
res = myTools.cropCenter(res, 80)

plt.show(plt.imshow(res[0][0], cmap=cm.binary))
scipy.misc.imsave(outName, res[0][0])
Ejemplo n.º 3
0
image=numpy.asarray(image)
#keep only one dimension
image=image[:,:,0]
#most needed type casting
image=image.astype(numpy.uint8)
#crop the center
image=myTools.cropCenter1(image, 83.1)
#split image to 4
splits=myTools.augmentData(image.reshape(1,1,image.shape[0],image.shape[1]), numOfTiles=4, overlap=False, imageWidth=image.shape[0], imageHeight=image.shape[1])
#another vital type casting
splits=splits.astype(numpy.float32)
#keep only the 4 original tiles
splits=splits[0:4,:,:,:]
#setting parameters for the network
data_size=(None,1,splits[0][0].shape[0],splits[0][0].shape[1])
#load the pretrained network
myNet=myTools.createPretrainedNN(data_size)
#make predictions for the 4 tiles
print(splits.dtype)
res=myNet(splits)
#crop the center of the predictions
res=myTools.cropCenter(res, 93)
#concatenate on the x axis
top=np.concatenate((res[0][0],res[2][0]),axis=1)
bot=np.concatenate((res[1][0],res[3][0]),axis=1)
#concatenate the two halves to get the full image
res=np.concatenate((top,bot),axis=0)

plt.show(plt.imshow(res, cmap=cm.binary))
scipy.misc.imsave(outName, res)
Ejemplo n.º 4
0
#this step is mysteriously needed
image=myTools.augmentData(image.reshape(1,1,image.shape[0],image.shape[1]), numOfTiles=1, overlap=False, imageWidth=image.shape[0], imageHeight=image.shape[1])
#another vital type casting
image=image.astype(numpy.float32)
#setting parameters for the network
data_size=(None,1,image[0][0].shape[0],image[0][0].shape[1])

imageMean=numpy.mean(image, keepdims=True)
image=image-imageMean

#load the pretrained network
myNet1=myTools.createPretrainedNN2(data_size, modelFile='myModel102Plus90.npz', filters=32)
#make predictions for the image
res1=myNet1(image)
#crop the center of the mask
res1=myTools.cropCenter(res1, 80)

#load the pretrained network
myNet2=myTools.createPretrainedNN2(data_size, modelFile='myModel103Plus90.npz', filters=32)
#make predictions for the image
res2=myNet2(image)
#crop the center of the mask
res2=myTools.cropCenter(res2, 80)

#load the pretrained network
myNet3=myTools.createPretrainedNN2(data_size, modelFile='myModel104Plus90.npz', filters=32)
#make predictions for the image
res3=myNet3(image)
#crop the center of the mask
res3=myTools.cropCenter(res3, 80)
'''
Ejemplo n.º 5
0
#another vital type casting
image = image.astype(numpy.float32)
#setting parameters for the network
data_size = (None, 1, image[0][0].shape[0], image[0][0].shape[1])

imageMean = numpy.mean(image, keepdims=True)
image = image - imageMean

#load the pretrained network
myNet1 = myTools.createPretrainedNN2(data_size,
                                     modelFile='myModel102Plus90.npz',
                                     filters=32)
#make predictions for the image
res1 = myNet1(image)
#crop the center of the mask
res1 = myTools.cropCenter(res1, 80)

#load the pretrained network
myNet2 = myTools.createPretrainedNN2(data_size,
                                     modelFile='myModel103Plus90.npz',
                                     filters=32)
#make predictions for the image
res2 = myNet2(image)
#crop the center of the mask
res2 = myTools.cropCenter(res2, 80)

#load the pretrained network
myNet3 = myTools.createPretrainedNN2(data_size,
                                     modelFile='myModel104Plus90.npz',
                                     filters=32)
#make predictions for the image
Ejemplo n.º 6
0
image=image.astype(numpy.uint8)
#crop the center
#image=myTools.cropCenter1(image, 100)
#this step is mysteriously needed
image=myTools.augmentMasks(image.reshape(1,1,image.shape[0],image.shape[1]), numOfTiles=1, overlap=False, imageWidth=image.shape[0], imageHeight=image.shape[1])
#another vital type casting
image=image.astype(numpy.float32)
#setting parameters for the network
data_size=(None,1,image[0][0].shape[0],image[0][0].shape[1])

#load the pretrained network
myNet1=myTools.createPretrainedNN2(data_size, modelFile='model020New.npz', filters=64)
#make predictions for the image
res1=myNet1(image)
#crop the center of the mask
res1=myTools.cropCenter(res1, 80)

#load the pretrained network
myNet2=myTools.createPretrainedNN2(data_size, modelFile='model20NewsallLR688images.npz', filters=64)
#make predictions for the image
res2=myNet2(image)
#crop the center of the mask
res2=myTools.cropCenter(res2, 80)

#load the pretrained network
myNet3=myTools.createPretrainedNN2(data_size, modelFile='model20NewSmallLR.npz', filters=64)
#make predictions for the image
res3=myNet3(image)
#crop the center of the mask
res3=myTools.cropCenter(res3, 80)
Ejemplo n.º 7
0
from nolearn.lasagne import visualize
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
import sklearn

from lasagne.layers import InputLayer, Conv2DLayer, DenseLayer, MaxPool2DLayer, InverseLayer


### DATASET
dataSet=myTools.loadImages('../../images', 1024, 1024, 4)

dataSet=myTools.oneDimension(dataSet)

dataSet=dataSet.astype(numpy.uint8)

dataSet=myTools.cropCenter(dataSet, 80)

dataSet=myTools.augmentData(dataSet, numOfTiles=4, overlap=False, imageWidth=819, imageHeight=819)
	
dataSet=dataSet.astype(numpy.float32)
#plt.show(plt.imshow(dataSet[0][0], cmap=cm.binary))

### MASKS
masks=myTools.loadImages('../../masks', 819, 819, 1)

for x in numpy.nditer(masks, op_flags=['readwrite']):
     if x>0:
             x[...]=1

masks=masks.astype(numpy.float32)
Ejemplo n.º 8
0
                             overlap=False,
                             imageWidth=image.shape[0],
                             imageHeight=image.shape[1])
#another vital type casting
image = image.astype(numpy.float32)
#setting parameters for the network
data_size = (None, 1, image[0][0].shape[0], image[0][0].shape[1])

#load the pretrained network
myNet1 = myTools.createPretrainedNN2(data_size,
                                     modelFile='model020New.npz',
                                     filters=64)
#make predictions for the image
res1 = myNet1(image)
#crop the center of the mask
res1 = myTools.cropCenter(res1, 80)

#load the pretrained network
myNet2 = myTools.createPretrainedNN2(data_size,
                                     modelFile='model20NewsallLR688images.npz',
                                     filters=64)
#make predictions for the image
res2 = myNet2(image)
#crop the center of the mask
res2 = myTools.cropCenter(res2, 80)

#load the pretrained network
myNet3 = myTools.createPretrainedNN2(data_size,
                                     modelFile='model20NewSmallLR.npz',
                                     filters=64)
#make predictions for the image
Ejemplo n.º 9
0
image=numpy.asarray(image)
#keep only one dimension
image=image[:,:,0]
#most needed type casting
image=image.astype(numpy.uint8)
#crop the center
#image=myTools.cropCenter1(image, 100)
#this step is mysteriously needed
image=myTools.augmentData(image.reshape(1,1,image.shape[0],image.shape[1]), numOfTiles=1, overlap=False, imageWidth=image.shape[0], imageHeight=image.shape[1])
#another vital type casting
image=image.astype(numpy.float32)

imageMean=numpy.mean(image, keepdims=True)


image=image-imageMean


#setting parameters for the network
data_size=(None,1,image[0][0].shape[0],image[0][0].shape[1])
#load the pretrained network
myNet=myTools.createPretrainedNN2(data_size, modelFile=modelFilename, filters=numberOfFilters)
#make predictions for the image
res=myNet(image)
#crop the center of the mask
res=myTools.cropCenter(res, 83.1)


plt.show(plt.imshow(res[0][0], cmap=cm.binary))
scipy.misc.imsave(outName, res[0][0])
Ejemplo n.º 10
0
argEpochs=int(sys.argv[3])

print('Learning rate: %f' % (argLR))
print('Weight decay: %f' % (argWD))
print('Number of epochs: %d' % (argEpochs))

random.seed(123)

### DATASET
dataSet=myTools.loadImages('../../images', 1024, 1024, 4)

dataSet=myTools.oneDimension(dataSet)

dataSet=dataSet.astype(numpy.uint8)

dataSet=myTools.cropCenter(dataSet, 83.1)#81.2 83.1

dataSet=myTools.augmentData(dataSet, numOfTiles=1, overlap=False, imageWidth=850, imageHeight=850)#830 850

dataSet=dataSet.astype(numpy.float32)


imageMeans=numpy.mean(dataSet, axis=(1,2,3), keepdims=True)


dataSet=dataSet-imageMeans



### MASKS
masks=myTools.loadImages('../../masksExpertBig', 850, 850, 1)