Kid-Liet / Reg-GAN

149 stars 21 forks source link

如何将数据归一化[-1,1](文中提及的) #21

Closed LOUEY233 closed 1 year ago

LOUEY233 commented 2 years ago

请问文中提及的归一化数据[-1,1], 是用的什么公式?是 (x-x.mean())/(x.max()-x.min())吗. Thank you in advance.

Kid-Liet commented 2 years ago

你好。是(x-x.min())/(x.max()-x.min()),不是x.mean(). 但也可以先统计整个数据集的分布,去选取固定的最大值最小值,然后clip到这个范围,再做归一化

LOUEY233 commented 2 years ago

(x-x.min())/(x.max()-x.min()) 没有办法归一到[-1,0]这个区间。 如果用这个归一化,区间范围[0,1],对模型精度有影响吗~

Kid-Liet commented 2 years ago

在(0,1)的基础上,做一个(*2-1)就到(-1,1)了,之所以这样是为了切合模型,因为一般生成器网络最后一层选用tan做为激活函数了

zhongniuniu commented 1 year ago

在(0,1)的基础上,做一个(*2-1)就到(-1,1)了,之所以这样是为了切合模型,因为一般生成器网络最后一层选用tan做为激活函数了

我查看了一下您的npy数据类型为float64,可是我用自己的数据变为float64类型的npy文件,它却报这样子的错误,这是为什么呢?我用的为这个函数im2 = np.array(im1,dtype=np.float64) Setting up a new session... Traceback (most recent call last): File "train.py", line 40, in main() File "train.py", line 32, in main trainer.train() File "/public2/zhongyutian/reg/trainer/CycTrainer.py", line 91, in train for i, batch in enumerate(self.dataloader): File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 521, in next data = self._next_data() File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data return self._process_data(data) File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data data.reraise() File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/_utils.py", line 425, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/public2/zhongyutian/reg/trainer/datasets.py", line 21, in getitem item_A = self.transform1(np.load(self.files_A[index % len(self.files_A)]).astype(np.float32)) File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 60, in call img = t(img) File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 179, in call return F.to_pil_image(pic, self.mode) File "/public2/zhongyutian/zhongyutian/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 290, in to_pil_image raise TypeError('Input type {} is not supported'.format(npimg.dtype)) TypeError: Input type float32 is not supported