modules.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:visualize-tsne 作者: YontiLevin 项目源码 文件源码
def _grid(self):
        tsne_norm = self.tsne_vectors[:, ] / float(self.ratio)
        used_imgs = np.equal(self.tsne_vectors[:, 0], None)
        image = np.ones((self.output_img_size, self.output_img_size, 3)) * self.background_color
        for x in tqdm(range(self.ratio)):
            x0 = x * self.each_img_size
            x05 = (x + 0.5) * self.each_img_size
            for y in range(self.ratio):
                y0 = y * self.each_img_size
                y05 = (y + 0.5) * self.each_img_size
                tmp_tsne = tsne_norm - [x05, y05]
                tmp_tsne[used_imgs] = 99999  # don't use the same img twice
                tsne_dist = np.hypot(tmp_tsne[:, 0], tmp_tsne[:, 1])
                min_index = np.argmin(tsne_dist)
                used_imgs[min_index] = True
                img_path = self.image_list[min_index]
                small_img, x1, y1, dx, dy = get_image(img_path, self.each_img_size)
                if small_img is None:
                    y -= 1
                    continue
                if x < 1 and all(side < self.each_img_size for side in [x1, y1]):
                    self.each_img_size = min(x1, y1)
                    dx = int(ceil(x1 / 2))
                    dy = int(ceil(y1 / 2))
                image[x0 + dx:x0 + dx + x1, y0 + dy:y0 + dy + y1] = small_img

        return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号