def compute_inception_score(self): self.generator.eval() imgs = [] while(len(imgs) < self.inception_nsamples): ztest = self.zdist.sample((self.batch_size,)) ytest = self.ydist.sample((self.batch_size,)) samples, _ = self.generator(ztest, ytest) samples = [s.data.cpu().numpy() for s in samples] imgs.extend(samples) inception_imgs = imgs[:self.inception_nsamples] score, score_std = inception_score( inception_imgs, device=self.device, resize=True, splits=10, batch_size=self.batch_size) fid_imgs = np.array(imgs[:self.fid_sample_size]) if self.fid_real_samples is not None: fid = calculate_fid_given_images( self.fid_real_samples, fid_imgs, batch_size=self.batch_size, cuda=True) return score, score_std, fid
def compute_inception_score(self): imgs, _ = self.get_fake_real_samples(self.inception_nsamples) imgs = [img.numpy() for img in imgs] score, score_std = inception_score(imgs, device=self.device, resize=True, splits=1) return score, score_std
def compute_inception_score(self, inception_nsamples): imgs = [] while(len(imgs) < inception_nsamples): ztest = self.zdist.sample((self.cfg.train.batch_size,)).to(self.device) ytest = self.ydist.sample((self.cfg.train.batch_size,)).to(self.device) samples = self.generator(ztest, ytest) samples = [s.data.cpu().numpy() for s in samples] imgs.extend(samples) imgs = imgs[:inception_nsamples] score, score_std = inception_score( imgs, device=self.device, resize=True, splits=10 ) return score, score_std
def compute_inception_score(self, inception_model=None): self.generator.eval() imgs = [] while (len(imgs) < self.inception_nsamples): ztest = self.zdist.sample((self.batch_size, )) ytest = self.ydist.sample((self.batch_size, )) samples = self.generator(ztest, ytest) samples = [s.data.cpu().numpy() for s in samples] imgs.extend(samples) imgs = imgs[:self.inception_nsamples] score, score_std = inception_score( imgs, device=self.device, resize=True, splits=10, inception_model=inception_model, ) return score, score_std
def compute_inception_score_MeRGAN(self, task_id=-1, is_FID=True, exit_real_ms=False, real_m=0, real_s=0): self.generator.eval() imgs = [] while (len(imgs) < self.inception_nsamples): ztest = self.zdist.sample((self.batch_size, )) ytest = self.ydist.sample((self.batch_size, )) y = ytest * 0 + task_id + 1 # samples,_ = self.generator(ztest, ytest) samples, _ = self.generator(ztest, y, task_id=task_id, is_FID=is_FID) samples = [s.data.cpu().numpy() for s in samples] imgs.extend(samples) inception_imgs = imgs[:self.inception_nsamples] score, score_std = inception_score(inception_imgs, device=self.device, resize=True, splits=10, batch_size=self.batch_size) fid_imgs = np.array(imgs[:self.fid_sample_size]) if exit_real_ms: fid = 0 else: if self.fid_real_samples is not None: fid = calculate_fid_given_images(self.fid_real_samples, fid_imgs, batch_size=self.batch_size, cuda=True) return score, score_std, fid