Ejemplo n.º 1
0
    def classify_image(self, img, normMean=None, norm_std=None):
        start_time = time.clock()
        
        row_range = 1
        img = normalizeImage(img)
        imSize = np.shape(img)
        membraneProbabilities = np.zeros(np.shape(img))
        patchSize = np.int(np.sqrt(self.hiddenLayers[0].W.eval().shape[0]))
        
        data_shared = shared_single_dataset(np.zeros((imSize[0]*row_range,patchSize**2)), borrow=True)

        classify = theano.function(
            [],
            self.p_y_given_x,
            givens={x: data_shared}
        )
        for row in xrange(0,1024,row_range):
            if row%100 == 0:
                print row
            data = generate_patch_data_rows(img, rowOffset=row, rowRange=row_range, patchSize=patchSize, imSize=imSize, data_mean=normMean, data_std=norm_std)
            data_shared.set_value(np.float32(data))
            result = classify()
            membraneProbabilities[row,:] = result[:,1]
            
        end_time = time.clock()
        total_time = (end_time - start_time)
        print >> sys.stderr, ('Running time: ' +
                              '%.2fm' % (total_time / 60.))
        
        return np.array(membraneProbabilities)
Ejemplo n.º 2
0
Archivo: mlp.py Proyecto: Rhoana/icon
    def predict_image(self, x, img, normMean=None, norm_std=None):
        start_time = time.clock()

        row_range = 1
        img = normalizeImage(img)
        imSize = np.shape(img)
        membraneProbabilities = np.zeros(1024*1024, dtype=int )
        patchSize = np.int(np.sqrt(self.hiddenLayers[0].W.eval().shape[0]))

        data_shared = shared_single_dataset(np.zeros((imSize[0]*row_range,patchSize**2)), borrow=True)

        classify = theano.function(
            [],
            self.logRegressionLayer.y_pred,
            givens={x: data_shared}
        )
        for row in xrange(0,1024,row_range):
            if row%100 == 0:
                print row
            data = generate_patch_data_rows(img, rowOffset=row, rowRange=row_range, patchSize=patchSize, imSize=imSize, data_mean=normMean, data_std=norm_std)
            data_shared.set_value(np.float32(data))
            membraneProbabilities[row*1024:row*1024+row_range*1024] = classify()

        end_time = time.clock()
        total_time = (end_time - start_time)
        print >> sys.stderr, ('Running time: ' +
                              '%.2fm' % (total_time / 60.))

        return np.array(membraneProbabilities)
Ejemplo n.º 3
0
    def debug_whole_image_classification(self, img, normMean=None, norm_std=None):
        start_time = time.clock()

        row_range = 1
        img = normalizeImage(img)
        imSize = np.shape(img)
        membraneProbabilities = np.zeros(np.shape(img))
        patchSize = self.patchSize
        
        data_shared = shared_single_dataset(np.zeros((imSize[0]*row_range,patchSize**2)), borrow=True)

        classify = theano.function(
            [],
            self.debug_x,
            givens={x: data_shared}
        )


        for row in xrange(0,33,row_range):
            if row%100 == 0:
                print row
            data = generate_patch_data_rows(img, rowOffset=row, rowRange=row_range, patchSize=patchSize, imSize=imSize, data_mean=normMean, data_std=norm_std)
            data_shared.set_value(np.float32(data))
            result = classify()
            #membraneProbabilities[row,:] = result[:,1]
            membraneProbabilities = result

        end_time = time.clock()
        total_time = (end_time - start_time)
        
        print "Image classification took %f seconds" % (total_time)
        
        return np.array(membraneProbabilities)
Ejemplo n.º 4
0
Archivo: mlp.py Proyecto: Rhoana/icon
    def classify(self, image, mean=None, std=None):

        #imSize = (1024,1024)
        imSize = np.shape(image)
        print 'imSize:', imSize
        image = Utility.pad_image( image, self.patchSize )
        imSizePadded = np.shape(image)

        print 'mlp.classify mean:', mean, 'std:', std
        start_time = time.clock()

        row_range = 1
        #imSize = np.shape(image)
        #membraneProbabilities = np.zeros(np.shape(image))
        membraneProbabilities = np.zeros(imSize)
        patchSize = np.int(np.sqrt(self.hiddenLayers[0].W.eval().shape[0]))

        print 'imSize:', imSize
        print 'imSizePadded:', imSizePadded
        print 'mp:', np.shape(membraneProbabilities)

        data_shared = shared_single_dataset(np.zeros((imSize[0]*row_range,patchSize**2)), borrow=True)

        classify = theano.function(
            [],
            self.p_y_given_x,
            givens={self.x: data_shared}
        )

        for row in xrange(0,1024,row_range):
            if row%100 == 0:
                print row

            #data = Utility.get_patch(image, row, row_range, patchSize ) 

            #print 'data shape:', data.shape  
            '''
            data = Utility.generate_patch_data_rows(
                    image,
                    rowOffset=row,
                    rowRange=row_range,
                    patchSize=patchSize,
                    imSize=imSizePadded,
                    data_mean=mean,
                    data_std=std)
            '''
            data = Utility.get_patch(
                    image, 
                    row, 
                    row_range, 
                    patchSize,
                    data_mean=mean,
                    data_std=std)

            #print 'data:', np.shape(data)
            data_shared.set_value(np.float32(data))
            result = classify()
            #print 'results:', np.shape(result)
            membraneProbabilities[row,:] = result[:,0]

        end_time = time.clock()
        total_time = (end_time - start_time)
        print >> sys.stderr, ('Running time: ' +
                              '%.2fm' % (total_time / 60.))

        return np.array(membraneProbabilities)
Ejemplo n.º 5
0
Archivo: mlp.py Proyecto: afcarl/icon
    def classify(self, image, mean=None, std=None):

        #imSize = (1024,1024)
        imSize = np.shape(image)
        print 'imSize:', imSize
        image = Utility.pad_image(image, self.patchSize)
        imSizePadded = np.shape(image)

        print 'mlp.classify mean:', mean, 'std:', std
        start_time = time.clock()

        row_range = 1
        #imSize = np.shape(image)
        #membraneProbabilities = np.zeros(np.shape(image))
        membraneProbabilities = np.zeros(imSize)
        patchSize = np.int(np.sqrt(self.hiddenLayers[0].W.eval().shape[0]))

        print 'imSize:', imSize
        print 'imSizePadded:', imSizePadded
        print 'mp:', np.shape(membraneProbabilities)

        data_shared = shared_single_dataset(np.zeros(
            (imSize[0] * row_range, patchSize**2)),
                                            borrow=True)

        classify = theano.function([],
                                   self.p_y_given_x,
                                   givens={self.x: data_shared})

        for row in xrange(0, 1024, row_range):
            if row % 100 == 0:
                print row

            #data = Utility.get_patch(image, row, row_range, patchSize )

            #print 'data shape:', data.shape
            '''
            data = Utility.generate_patch_data_rows(
                    image,
                    rowOffset=row,
                    rowRange=row_range,
                    patchSize=patchSize,
                    imSize=imSizePadded,
                    data_mean=mean,
                    data_std=std)
            '''
            data = Utility.get_patch(image,
                                     row,
                                     row_range,
                                     patchSize,
                                     data_mean=mean,
                                     data_std=std)

            #print 'data:', np.shape(data)
            data_shared.set_value(np.float32(data))
            result = classify()
            #print 'results:', np.shape(result)
            membraneProbabilities[row, :] = result[:, 0]

        end_time = time.clock()
        total_time = (end_time - start_time)
        print >> sys.stderr, ('Running time: ' + '%.2fm' % (total_time / 60.))

        return np.array(membraneProbabilities)