znxlwm / UGATIT-pytorch

Official PyTorch implementation of U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation
MIT License
2.51k stars 476 forks source link

Error during test: local variable 'A2B' referenced before assignment #15

Open qiuyuchen14 opened 5 years ago

qiuyuchen14 commented 5 years ago

I could successfully train the model on my own dataset, and I can see that the trained models are saved in the model folder already. However, I got the following error when I ran test code "python main.py --dataset experiment1 --phase test --light True". Do you know where might go wrong? Thanks! The error is: ''' [*] Load SUCCESS Traceback (most recent call last): File "main.py", line 83, in main() File "main.py", line 79, in main gan.test() File "/home/zoey/nas/zoey/github/UGATIT-pytorch/UGATIT.py", line 387, in test A2B = np.concatenate((A2B, np.concatenate((RGB2BGR(tensor2numpy(denorm(real_A[0]))), UnboundLocalError: local variable 'A2B' referenced before assignment '''

qiuyuchen14 commented 5 years ago

Could you please also help me to understand the images generated during the training? For example in the picture below, I got 7 rows of images, I don't understand why my 3rd, 5th, 6th, 7th rows are empty.

Screenshot from 2019-08-07 17-43-49

Trueyellow commented 5 years ago

As for the first question, you could add

A2B = np.zeros((self.img_size * 7, 0, 3))
B2A = np.zeros((self.img_size * 7, 0, 3)) 

at the begining of test function.

For the second, I think your network is just broke, it is not correctly trained at all.

I suggest a warmup should be added at the beginning of training. For example, I linearly increased the learning rate from 0 to 0.0001 at the first 2000 iterations, which performed well in my task.

zerezhka commented 5 years ago

As for the first question, you could add

A2B = np.zeros((self.img_size * 7, 0, 3))
B2A = np.zeros((self.img_size * 7, 0, 3)) 

at the begining of test function.

As I understand - test function isn't work? Add pr for fix it? or you already fix it, @Trueyellow?

Trueyellow commented 5 years ago

As for the first question, you could add

A2B = np.zeros((self.img_size * 7, 0, 3))
B2A = np.zeros((self.img_size * 7, 0, 3)) 

at the begining of test function.

As I understand - test function isn't work? Add pr for fix it? or you already fix it, @Trueyellow?

Yes, the originial test function doesn't work. In fact, according to my usage, the pytorch version of UGATIT has many differences compared with tensorflow version. If I have time, I would open a PR to fix all those differences(BUGs). If anyone want to training a new model from scratch and reproduce the result like paper, I suggest the tensorflow version.

w32zhong commented 5 years ago

Same question here as what @qiuyuchen14 asked.