예제 #1
0
    def visualize_meta_features(self,pic_name=None,color=False):
        # W is a [H,F+1] matrix
        meta_features = self._input.W[:,1:].transpose() # [F,H] matrix

        # display_patch will treat each column as a single image patch
        if color:
            display.display_color_patches(meta_features,pic_name)
        else:
            display.display_patches(meta_features,pic_name)
예제 #2
0
파일: models.py 프로젝트: npinto/hdl
    def display(self,save_string=None,save=True,normalize_A=True,max_factors=64,zerophasewhiten=True):

        if self.patch_sz is None:
            raise NotImplemented

        from display import display_color_patches

        output = {}
        if hasattr(self.A,'get_value'):
            A = self.A.get_value()
        else:
            A = self.A

        if self.whiten:
            A = np.dot(self.dewhitenmatrix,A)
            if zerophasewhiten:
                A = np.dot(self.zerophasewhitenmatrix,A)

        # plot the vectors in A
        NN = min(self.NN,2*max_factors)

        patches = np.zeros((self.patch_sz,self.patch_sz,3,2*NN))
        count = 0
        for nn in range(NN):
            if normalize_A:
                Ann = A[...,nn]
                Ann /= np.abs(Ann).max() / 127.5
                Ann += 127.5
            else:
                Ann = A[...,nn]
            patches[...,count  ] = Ann.reshape(6,self.patch_sz,self.patch_sz)[:3,...].T
            patches[...,count+1] = Ann.reshape(6,self.patch_sz,self.patch_sz)[3:,...].T
            count += 2

        patches = patches.reshape((self.patch_sz*self.patch_sz*3,2*NN))

        array = display_color_patches(patches,self.patch_sz,fig_num=1,normalize=False)

        output['A'] = array

        plt.draw()

        if save:
            from config import state_dir, tstring
            savepath = os.path.join(state_dir,self.model_name + '_' + self.tstring)
            if not os.path.isdir(savepath): os.makedirs(savepath)

            if save_string is None:
                save_string = tstring()
            plt.figure(1)
            fname = os.path.join(savepath, 'A_' + save_string + '.png')
            plt.savefig(fname)

        return output
예제 #3
0
파일: models.py 프로젝트: npinto/hdl
    def display_whitening(self,save_string=None,save=True,normalize_A=True,max_factors=64,zerophasewhiten=True):

        if self.patch_sz is None:
            raise NotImplemented

        from display import display_color_patches

        output = {}
        if zerophasewhiten:
            A = self.zerophasewhitenmatrix
        else:
            A = self.whitenmatrix
        if hasattr(A,'get_value'):
            A = A.get_value()

        A = A.T # make the columns the filters

        # plot the vectors in A
        NN = min(A.shape[1],2*max_factors)
        patches = np.zeros((self.patch_sz,self.patch_sz,3,2*NN))
        count = 0
        for nn in range(NN):
            patches[...,count  ] = A[...,nn].reshape(6,self.patch_sz,self.patch_sz)[:3,...].T
            patches[...,count+1] = A[...,nn].reshape(6,self.patch_sz,self.patch_sz)[3:,...].T
            count += 2

        patches = patches.reshape((self.patch_sz*self.patch_sz*3,2*NN))
        array = display_color_patches(patches,self.patch_sz,fig_num=1,normalize=normalize_A)

        output['whitenmatrix'] = array
        plt.draw()

        if save:
            from config import state_dir, tstring
            savepath = os.path.join(state_dir,self.model_name + '_' + self.tstring)
            if not os.path.isdir(savepath): os.makedirs(savepath)

            if save_string is None:
                save_string = tstring()
            plt.figure(1)
            fname = os.path.join(savepath, 'whitenmatrix_' + save_string + '.png')
            plt.savefig(fname)

        return output
예제 #4
0
def plot_patches(imageset,topK,filename=None):
    # imageset is organized by row, but display_color_patches expect image on column
    display.display_color_patches(imageset[:topK].T,filename)