Esempio n. 1
0
        def save_clustering_results(self, i, kernel_stack, centroids, idx):
            _, kh, kw = kernel_stack.size()
            k_kernels = centroids.size(0)

            savedir = '../experiment/{}/results'.format(args.save)
            clustering.save_kernels(
                centroids,
                '{}/iter000_c{:0>2}.png'.format(savedir, i)
            )
            clustering.save_distribution(
                idx,
                '{}/distribution_{:0>2}.pdf'.format(savedir, i)
            )
            torch.save(
                idx,
                '{}/labels_{:0>2}.pt'.format(savedir, i)
            )
            # visualize full kernels and their centroids
            if args.debug:
                for t in range(k_kernels):
                    mask = (idx == t)
                    mask_idx = torch.arange(len(kernel_stack))
                    mask_idx = mask_idx.masked_select(mask).long()

                    ref = centroids[t].view(1, kh, kw)
                    collect = torch.cat((ref, kernel_stack[mask_idx]), dim=0)
                    clustering.save_kernels(
                        collect,
                        '{}/vis_c{:0>2}_{:0>4}.png'.format(savedir, i, t),
                        highlight=True
                    )
Esempio n. 2
0
        def save_clustering_results(self, i, kernel_stack, centroids, idx):
            _, kh, kw = kernel_stack.size()
            k_kernels = centroids.size(0)
            savedir = os.path.join(args.dir_save, args.save,
                                   'clustering_results')
            # savedir = '/scratch_net/ofsoundof/yawli/srbasis/{}/clustering_results'.format(args.save)
            if not os.path.exists(savedir):
                os.makedirs(savedir)
            clustering.save_kernels(
                centroids, '{}/iter000_c{:0>2}.png'.format(savedir, i))
            clustering.save_distribution(
                idx, '{}/distribution_{:0>2}.pdf'.format(savedir, i))
            torch.save(idx, '{}/labels_{:0>2}.pt'.format(savedir, i))
            # visualize full kernels and their centroids
            if args.debug:
                for t in range(k_kernels):
                    mask = (idx == t)
                    mask_idx = torch.arange(len(kernel_stack))
                    # print('222222222222222222')
                    # embed()
                    mask_idx = mask_idx.masked_select(mask).long()

                    ref = centroids[t].view(1, kh, kw)
                    collect = torch.cat((ref, kernel_stack[mask_idx]), dim=0)
                    clustering.save_kernels(collect,
                                            '{}/vis_c{:0>2}_{:0>4}.png'.format(
                                                savedir, i, t),
                                            highlight=True)
 def save_results(self, epoch, m):
     m = m.get_model()
     if hasattr(m, 'split'):
         from model import clustering
         for i in set(v for v in m.split['map'].values()):
             centroids = getattr(m, 'centroids_{}'.format(i), None)
             if centroids is not None:
                 clustering.save_kernels(
                     centroids, '{}/results/iter{:0>3}_c{:0>2}.png'.format(
                         self.dir, epoch, i))